mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Refractor activity pub lib/helpers
This commit is contained in:
parent
eb8b27c93e
commit
5414139835
47 changed files with 844 additions and 498 deletions
55
server/lib/activitypub/send/send-update.ts
Normal file
55
server/lib/activitypub/send/send-update.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import { Transaction } from 'sequelize'
|
||||
import { ActivityUpdate } from '../../../../shared/models/activitypub/activity'
|
||||
import { getUpdateActivityPubUrl } from '../../../helpers/activitypub'
|
||||
import { database as db } from '../../../initializers'
|
||||
import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
|
||||
import { broadcastToFollowers, getAudience } from './misc'
|
||||
|
||||
async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
||||
const byAccount = videoChannel.Account
|
||||
|
||||
const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
|
||||
const videoChannelObject = videoChannel.toActivityPubObject()
|
||||
const data = await updateActivityData(url, byAccount, videoChannelObject)
|
||||
|
||||
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
||||
accountsInvolved.push(byAccount)
|
||||
|
||||
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||
}
|
||||
|
||||
async function sendUpdateVideo (video: VideoInstance, t: Transaction) {
|
||||
const byAccount = video.VideoChannel.Account
|
||||
|
||||
const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
|
||||
const videoObject = video.toActivityPubObject()
|
||||
const data = await updateActivityData(url, byAccount, videoObject)
|
||||
|
||||
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
||||
accountsInvolved.push(byAccount)
|
||||
|
||||
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
sendUpdateVideoChannel,
|
||||
sendUpdateVideo
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
|
||||
const { to, cc } = await getAudience(byAccount)
|
||||
const activity: ActivityUpdate = {
|
||||
type: 'Update',
|
||||
id: url,
|
||||
actor: byAccount.url,
|
||||
to,
|
||||
cc,
|
||||
object
|
||||
}
|
||||
|
||||
return activity
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue