1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 18:29:27 +02:00

Send follow/accept

This commit is contained in:
Chocobozzz 2017-11-13 18:48:28 +01:00
parent 7a7724e66e
commit ce548a10db
No known key found for this signature in database
GPG key ID: 583A612D890159BE
9 changed files with 160 additions and 19 deletions

View file

@ -56,6 +56,18 @@ function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction)
return broadcastToFollowers(data, account, t)
}
function sendAccept (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
const data = acceptActivityData(fromAccount)
return unicastTo(data, toAccount, t)
}
function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
const data = followActivityData(toAccount.url, fromAccount)
return unicastTo(data, toAccount, t)
}
// ---------------------------------------------------------------------------
export {
@ -65,7 +77,9 @@ export {
sendAddVideo,
sendUpdateVideo,
sendDeleteVideo,
sendDeleteAccount
sendDeleteAccount,
sendAccept,
sendFollow
}
// ---------------------------------------------------------------------------
@ -81,6 +95,15 @@ async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t:
return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload)
}
async function unicastTo (data: any, toAccount: AccountInstance, t: Sequelize.Transaction) {
const jobPayload = {
uris: [ toAccount.url ],
body: data
}
return httpRequestJobScheduler.createJob(t, 'httpRequestUnicastHandler', jobPayload)
}
function buildSignedActivity (byAccount: AccountInstance, data: Object) {
const activity = activityPubContextify(data)
@ -142,3 +165,24 @@ async function addActivityData (url: string, byAccount: AccountInstance, target:
return buildSignedActivity(byAccount, base)
}
async function followActivityData (url: string, byAccount: AccountInstance) {
const base = {
type: 'Follow',
id: byAccount.url,
actor: byAccount.url,
object: url
}
return buildSignedActivity(byAccount, base)
}
async function acceptActivityData (byAccount: AccountInstance) {
const base = {
type: 'Accept',
id: byAccount.url,
actor: byAccount.url
}
return buildSignedActivity(byAccount, base)
}