From 50d6de9c286abcb34ff4234d56d9cbb803db7665 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Dec 2017 17:38:41 +0100 Subject: Begin moving video channel to actor --- server/lib/activitypub/send/index.ts | 1 - server/lib/activitypub/send/misc.ts | 80 ++++++++------------ server/lib/activitypub/send/send-accept.ts | 22 +++--- server/lib/activitypub/send/send-add.ts | 45 ----------- server/lib/activitypub/send/send-announce.ts | 84 +++++++-------------- server/lib/activitypub/send/send-create.ts | 107 ++++++++++++++------------- server/lib/activitypub/send/send-delete.ts | 38 +++------- server/lib/activitypub/send/send-follow.ts | 20 ++--- server/lib/activitypub/send/send-like.ts | 34 ++++----- server/lib/activitypub/send/send-undo.ts | 84 ++++++++++----------- server/lib/activitypub/send/send-update.ts | 52 ++++++------- 11 files changed, 226 insertions(+), 341 deletions(-) delete mode 100644 server/lib/activitypub/send/send-add.ts (limited to 'server/lib/activitypub/send') diff --git a/server/lib/activitypub/send/index.ts b/server/lib/activitypub/send/index.ts index ee8f3ad7e..79ba6c7fe 100644 --- a/server/lib/activitypub/send/index.ts +++ b/server/lib/activitypub/send/index.ts @@ -1,5 +1,4 @@ export * from './send-accept' -export * from './send-add' export * from './send-announce' export * from './send-create' export * from './send-delete' diff --git a/server/lib/activitypub/send/misc.ts b/server/lib/activitypub/send/misc.ts index ffc221477..14101e630 100644 --- a/server/lib/activitypub/send/misc.ts +++ b/server/lib/activitypub/send/misc.ts @@ -2,18 +2,16 @@ import { Transaction } from 'sequelize' import { Activity } from '../../../../shared/models/activitypub' import { logger } from '../../../helpers' import { ACTIVITY_PUB } from '../../../initializers' -import { AccountModel } from '../../../models/account/account' -import { AccountFollowModel } from '../../../models/account/account-follow' +import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { VideoModel } from '../../../models/video/video' -import { VideoChannelModel } from '../../../models/video/video-channel' -import { VideoChannelShareModel } from '../../../models/video/video-channel-share' import { VideoShareModel } from '../../../models/video/video-share' import { activitypubHttpJobScheduler, ActivityPubHttpPayload } from '../../jobs/activitypub-http-job-scheduler' async function forwardActivity ( activity: Activity, t: Transaction, - followersException: AccountModel[] = [] + followersException: ActorModel[] = [] ) { const to = activity.to || [] const cc = activity.cc || [] @@ -25,11 +23,11 @@ async function forwardActivity ( } } - const toAccountFollowers = await AccountModel.listByFollowersUrls(followersUrls, t) - const uris = await computeFollowerUris(toAccountFollowers, followersException, t) + const toActorFollowers = await ActorModel.listByFollowersUrls(followersUrls, t) + const uris = await computeFollowerUris(toActorFollowers, followersException, t) if (uris.length === 0) { - logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', ')) + logger.info('0 followers for %s, no forwarding.', toActorFollowers.map(a => a.id).join(', ')) return undefined } @@ -45,14 +43,14 @@ async function forwardActivity ( async function broadcastToFollowers ( data: any, - byAccount: AccountModel, - toAccountFollowers: AccountModel[], + byActor: ActorModel, + toActorFollowers: ActorModel[], t: Transaction, - followersException: AccountModel[] = [] + followersException: ActorModel[] = [] ) { - const uris = await computeFollowerUris(toAccountFollowers, followersException, t) + const uris = await computeFollowerUris(toActorFollowers, followersException, t) if (uris.length === 0) { - logger.info('0 followers for %s, no broadcasting.', toAccountFollowers.map(a => a.id).join(', ')) + logger.info('0 followers for %s, no broadcasting.', toActorFollowers.map(a => a.id).join(', ')) return undefined } @@ -60,62 +58,48 @@ async function broadcastToFollowers ( const jobPayload: ActivityPubHttpPayload = { uris, - signatureAccountId: byAccount.id, + signatureActorId: byActor.id, body: data } return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload) } -async function unicastTo (data: any, byAccount: AccountModel, toAccountUrl: string, t: Transaction) { - logger.debug('Creating unicast job.', { uri: toAccountUrl }) +async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string, t: Transaction) { + logger.debug('Creating unicast job.', { uri: toActorUrl }) const jobPayload: ActivityPubHttpPayload = { - uris: [ toAccountUrl ], - signatureAccountId: byAccount.id, + uris: [ toActorUrl ], + signatureActorId: byActor.id, body: data } return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload) } -function getOriginVideoAudience (video: VideoModel, accountsInvolvedInVideo: AccountModel[]) { +function getOriginVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) { return { - to: [ video.VideoChannel.Account.url ], - cc: accountsInvolvedInVideo.map(a => a.followersUrl) + to: [ video.VideoChannel.Account.Actor.url ], + cc: actorsInvolvedInVideo.map(a => a.followersUrl) } } -function getOriginVideoChannelAudience (videoChannel: VideoChannelModel, accountsInvolved: AccountModel[]) { +function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { return { - to: [ videoChannel.Account.url ], - cc: accountsInvolved.map(a => a.followersUrl) - } -} - -function getObjectFollowersAudience (accountsInvolvedInObject: AccountModel[]) { - return { - to: accountsInvolvedInObject.map(a => a.followersUrl), + to: actorsInvolvedInObject.map(a => a.followersUrl), cc: [] } } -async function getAccountsInvolvedInVideo (video: VideoModel, t: Transaction) { - const accountsToForwardView = await VideoShareModel.loadAccountsByShare(video.id, t) - accountsToForwardView.push(video.VideoChannel.Account) - - return accountsToForwardView -} - -async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { - const accountsToForwardView = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) - accountsToForwardView.push(videoChannel.Account) +async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { + const actorsToForwardView = await VideoShareModel.loadActorsByShare(video.id, t) + actorsToForwardView.push(video.VideoChannel.Account.Actor) - return accountsToForwardView + return actorsToForwardView } -async function getAudience (accountSender: AccountModel, t: Transaction, isPublic = true) { - const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t) +async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) { + const followerInboxUrls = await actorSender.getFollowerSharedInboxUrls(t) // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47 let to = [] @@ -132,10 +116,10 @@ async function getAudience (accountSender: AccountModel, t: Transaction, isPubli return { to, cc } } -async function computeFollowerUris (toAccountFollower: AccountModel[], followersException: AccountModel[], t: Transaction) { - const toAccountFollowerIds = toAccountFollower.map(a => a.id) +async function computeFollowerUris (toActorFollower: ActorModel[], followersException: ActorModel[], t: Transaction) { + const toActorFollowerIds = toActorFollower.map(a => a.id) - const result = await AccountFollowModel.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t) + const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl) return result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1) } @@ -144,12 +128,10 @@ async function computeFollowerUris (toAccountFollower: AccountModel[], followers export { broadcastToFollowers, - getOriginVideoChannelAudience, unicastTo, getAudience, getOriginVideoAudience, - getAccountsInvolvedInVideo, - getAccountsInvolvedInVideoChannel, + getActorsInvolvedInVideo, getObjectFollowersAudience, forwardActivity } diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts index f160af3c9..7579884a7 100644 --- a/server/lib/activitypub/send/send-accept.ts +++ b/server/lib/activitypub/send/send-accept.ts @@ -1,15 +1,15 @@ import { Transaction } from 'sequelize' import { ActivityAccept } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' -import { AccountFollowModel } from '../../../models/account/account-follow' -import { getAccountFollowAcceptActivityPubUrl } from '../url' +import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' +import { getActorFollowAcceptActivityPubUrl } from '../url' import { unicastTo } from './misc' -async function sendAccept (accountFollow: AccountFollowModel, t: Transaction) { - const follower = accountFollow.AccountFollower - const me = accountFollow.AccountFollowing +async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) { + const follower = actorFollow.ActorFollower + const me = actorFollow.ActorFollowing - const url = getAccountFollowAcceptActivityPubUrl(accountFollow) + const url = getActorFollowAcceptActivityPubUrl(actorFollow) const data = acceptActivityData(url, me) return unicastTo(data, me, follower.inboxUrl, t) @@ -23,12 +23,10 @@ export { // --------------------------------------------------------------------------- -function acceptActivityData (url: string, byAccount: AccountModel) { - const activity: ActivityAccept = { +function acceptActivityData (url: string, byActor: ActorModel): ActivityAccept { + return { type: 'Accept', id: url, - actor: byAccount.url + actor: byActor.url } - - return activity } diff --git a/server/lib/activitypub/send/send-add.ts b/server/lib/activitypub/send/send-add.ts deleted file mode 100644 index fd614db75..000000000 --- a/server/lib/activitypub/send/send-add.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { Transaction } from 'sequelize' -import { ActivityAdd } from '../../../../shared/models/activitypub' -import { VideoPrivacy } from '../../../../shared/models/videos' -import { AccountModel } from '../../../models/account/account' -import { VideoModel } from '../../../models/video/video' -import { broadcastToFollowers, getAudience } from './misc' - -async function sendAddVideo (video: VideoModel, t: Transaction) { - const byAccount = video.VideoChannel.Account - - const videoObject = video.toActivityPubObject() - const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t) - - return broadcastToFollowers(data, byAccount, [ byAccount ], t) -} - -async function addActivityData ( - url: string, - byAccount: AccountModel, - video: VideoModel, - target: string, - object: any, - t: Transaction -): Promise { - const videoPublic = video.privacy === VideoPrivacy.PUBLIC - - const { to, cc } = await getAudience(byAccount, t, videoPublic) - - return { - type: 'Add', - id: url, - actor: byAccount.url, - to, - cc, - object, - target - } -} - -// --------------------------------------------------------------------------- - -export { - addActivityData, - sendAddVideo -} diff --git a/server/lib/activitypub/send/send-announce.ts b/server/lib/activitypub/send/send-announce.ts index e685323e8..578fbc630 100644 --- a/server/lib/activitypub/send/send-announce.ts +++ b/server/lib/activitypub/send/send-announce.ts @@ -1,88 +1,59 @@ import { Transaction } from 'sequelize' -import { ActivityAdd } from '../../../../shared/index' import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' +import { VideoPrivacy } from '../../../../shared/models/videos' +import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' -import { VideoChannelModel } from '../../../models/video/video-channel' import { getAnnounceActivityPubUrl } from '../url' import { broadcastToFollowers, - getAccountsInvolvedInVideo, - getAccountsInvolvedInVideoChannel, + getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getOriginVideoAudience, - getOriginVideoChannelAudience, unicastTo } from './misc' -import { addActivityData } from './send-add' import { createActivityData } from './send-create' -async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getAnnounceActivityPubUrl(video.url, byAccount) +async function buildVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getAnnounceActivityPubUrl(video.url, byActor) + const videoObject = video.toActivityPubObject() - const videoChannel = video.VideoChannel - const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t) + const announcedAudience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) + const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t, announcedAudience) - const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) + const accountsToForwardView = await getActorsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(accountsToForwardView) - return announceActivityData(url, byAccount, announcedActivity, t, audience) + return announceActivityData(url, byActor, announcedActivity, t, audience) } -async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const data = await buildVideoAnnounceToFollowers(byAccount, video, t) +async function sendVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const data = await buildVideoAnnounceToFollowers(byActor, video, t) - return broadcastToFollowers(data, byAccount, [ byAccount ], t) + return broadcastToFollowers(data, byActor, [ byActor ], t) } -async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getAnnounceActivityPubUrl(video.url, byAccount) +async function sendVideoAnnounceToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getAnnounceActivityPubUrl(video.url, byActor) - const videoChannel = video.VideoChannel - const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t) + const videoObject = video.toActivityPubObject() + const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const data = await createActivityData(url, byAccount, announcedActivity, t, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const data = await createActivityData(url, byActor, announcedActivity, t, audience) - return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) -} - -async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { - const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) - const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) - - const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t) - const audience = getObjectFollowersAudience(accountsToForwardView) - return announceActivityData(url, byAccount, announcedActivity, t, audience) -} - -async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { - const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t) - - return broadcastToFollowers(data, byAccount, [ byAccount ], t) -} - -async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) { - const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount) - const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t) - - const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel, t) - const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo) - const data = await createActivityData(url, byAccount, announcedActivity, t, audience) - - return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } async function announceActivityData ( url: string, - byAccount: AccountModel, - object: ActivityCreate | ActivityAdd, + byActor: ActorModel, + object: ActivityCreate, t: Transaction, audience?: ActivityAudience ): Promise { if (!audience) { - audience = await getAudience(byAccount, t) + audience = await getAudience(byActor, t) } return { @@ -90,7 +61,7 @@ async function announceActivityData ( to: audience.to, cc: audience.cc, id: url, - actor: byAccount.url, + actor: byActor.url, object } } @@ -99,10 +70,7 @@ async function announceActivityData ( export { sendVideoAnnounceToFollowers, - sendVideoChannelAnnounceToFollowers, sendVideoAnnounceToOrigin, - sendVideoChannelAnnounceToOrigin, announceActivityData, - buildVideoAnnounceToFollowers, - buildVideoChannelAnnounceToFollowers + buildVideoAnnounceToFollowers } diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 9fbaa8196..d26c24838 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -1,111 +1,112 @@ import { Transaction } from 'sequelize' import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub' -import { getServerAccount } from '../../../helpers' -import { AccountModel } from '../../../models/account/account' +import { VideoPrivacy } from '../../../../shared/models/videos' +import { getServerActor } from '../../../helpers' +import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' import { VideoAbuseModel } from '../../../models/video/video-abuse' -import { VideoChannelModel } from '../../../models/video/video-channel' import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url' import { broadcastToFollowers, - getAccountsInvolvedInVideo, + getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getOriginVideoAudience, unicastTo } from './misc' -async function sendCreateVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { - const byAccount = videoChannel.Account +async function sendCreateVideo (video: VideoModel, t: Transaction) { + const byActor = video.VideoChannel.Account.Actor - const videoChannelObject = videoChannel.toActivityPubObject() - const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject, t) + const videoObject = video.toActivityPubObject() + const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) + const data = await createActivityData(video.url, byActor, videoObject, t, audience) - return broadcastToFollowers(data, byAccount, [ byAccount ], t) + return broadcastToFollowers(data, byActor, [ byActor ], t) } -async function sendVideoAbuse (byAccount: AccountModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { +async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel, t: Transaction) { const url = getVideoAbuseActivityPubUrl(videoAbuse) - const audience = { to: [ video.VideoChannel.Account.url ], cc: [] } - const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), t, audience) + const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] } + const data = await createActivityData(url, byActor, videoAbuse.toActivityPubObject(), t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendCreateViewToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getVideoViewActivityPubUrl(byAccount, video) - const viewActivity = createViewActivityData(byAccount, video) +async function sendCreateViewToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoViewActivityPubUrl(byActor, video) + const viewActivity = createViewActivityData(byActor, video) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const data = await createActivityData(url, byAccount, viewActivity, t, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const data = await createActivityData(url, byActor, viewActivity, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendCreateViewToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getVideoViewActivityPubUrl(byAccount, video) - const viewActivity = createViewActivityData(byAccount, video) +async function sendCreateViewToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoViewActivityPubUrl(byActor, video) + const viewActivity = createViewActivityData(byActor, video) - const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) - const audience = getObjectFollowersAudience(accountsToForwardView) - const data = await createActivityData(url, byAccount, viewActivity, t, audience) + const actorsToForwardView = await getActorsInvolvedInVideo(video, t) + const audience = getObjectFollowersAudience(actorsToForwardView) + const data = await createActivityData(url, byActor, viewActivity, t, audience) - // Use the server account to send the view, because it could be an unregistered account - const serverAccount = await getServerAccount() - const followersException = [ byAccount ] - return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) + // Use the server actor to send the view + const serverActor = await getServerActor() + const followersException = [ byActor ] + return broadcastToFollowers(data, serverActor, actorsToForwardView, t, followersException) } -async function sendCreateDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getVideoDislikeActivityPubUrl(byAccount, video) - const dislikeActivity = createDislikeActivityData(byAccount, video) +async function sendCreateDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoDislikeActivityPubUrl(byActor, video) + const dislikeActivity = createDislikeActivityData(byActor, video) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const data = await createActivityData(url, byAccount, dislikeActivity, t, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const data = await createActivityData(url, byActor, dislikeActivity, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendCreateDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getVideoDislikeActivityPubUrl(byAccount, video) - const dislikeActivity = createDislikeActivityData(byAccount, video) +async function sendCreateDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoDislikeActivityPubUrl(byActor, video) + const dislikeActivity = createDislikeActivityData(byActor, video) - const accountsToForwardView = await getAccountsInvolvedInVideo(video, t) - const audience = getObjectFollowersAudience(accountsToForwardView) - const data = await createActivityData(url, byAccount, dislikeActivity, t, audience) + const actorsToForwardView = await getActorsInvolvedInVideo(video, t) + const audience = getObjectFollowersAudience(actorsToForwardView) + const data = await createActivityData(url, byActor, dislikeActivity, t, audience) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, actorsToForwardView, t, followersException) } async function createActivityData ( url: string, - byAccount: AccountModel, + byActor: ActorModel, object: any, t: Transaction, audience?: ActivityAudience ): Promise { if (!audience) { - audience = await getAudience(byAccount, t) + audience = await getAudience(byActor, t) } return { type: 'Create', id: url, - actor: byAccount.url, + actor: byActor.url, to: audience.to, cc: audience.cc, object } } -function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) { +function createDislikeActivityData (byActor: ActorModel, video: VideoModel) { return { type: 'Dislike', - actor: byAccount.url, + actor: byActor.url, object: video.url } } @@ -113,7 +114,7 @@ function createDislikeActivityData (byAccount: AccountModel, video: VideoModel) // --------------------------------------------------------------------------- export { - sendCreateVideoChannel, + sendCreateVideo, sendVideoAbuse, createActivityData, sendCreateViewToOrigin, @@ -125,10 +126,10 @@ export { // --------------------------------------------------------------------------- -function createViewActivityData (byAccount: AccountModel, video: VideoModel) { +function createViewActivityData (byActor: ActorModel, video: VideoModel) { return { type: 'View', - actor: byAccount.url, + actor: byActor.url, object: video.url } } diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index 0a45ea10f..4bc5db77e 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts @@ -1,54 +1,40 @@ import { Transaction } from 'sequelize' import { ActivityDelete } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' +import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' -import { VideoChannelModel } from '../../../models/video/video-channel' -import { VideoChannelShareModel } from '../../../models/video/video-channel-share' import { VideoShareModel } from '../../../models/video/video-share' import { broadcastToFollowers } from './misc' -async function sendDeleteVideoChannel (videoChannel: VideoChannelModel, t: Transaction) { - const byAccount = videoChannel.Account - - const data = deleteActivityData(videoChannel.url, byAccount) - - const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) - accountsInvolved.push(byAccount) - - return broadcastToFollowers(data, byAccount, accountsInvolved, t) -} - async function sendDeleteVideo (video: VideoModel, t: Transaction) { - const byAccount = video.VideoChannel.Account + const byActor = video.VideoChannel.Account.Actor - const data = deleteActivityData(video.url, byAccount) + const data = deleteActivityData(video.url, byActor) - const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) - accountsInvolved.push(byAccount) + const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) + actorsInvolved.push(byActor) - return broadcastToFollowers(data, byAccount, accountsInvolved, t) + return broadcastToFollowers(data, byActor, actorsInvolved, t) } -async function sendDeleteAccount (account: AccountModel, t: Transaction) { - const data = deleteActivityData(account.url, account) +async function sendDeleteActor (byActor: ActorModel, t: Transaction) { + const data = deleteActivityData(byActor.url, byActor) - return broadcastToFollowers(data, account, [ account ], t) + return broadcastToFollowers(data, byActor, [ byActor ], t) } // --------------------------------------------------------------------------- export { - sendDeleteVideoChannel, sendDeleteVideo, - sendDeleteAccount + sendDeleteActor } // --------------------------------------------------------------------------- -function deleteActivityData (url: string, byAccount: AccountModel): ActivityDelete { +function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete { return { type: 'Delete', id: url, - actor: byAccount.url + actor: byActor.url } } diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts index 51735ddfd..eac60e94f 100644 --- a/server/lib/activitypub/send/send-follow.ts +++ b/server/lib/activitypub/send/send-follow.ts @@ -1,26 +1,26 @@ import { Transaction } from 'sequelize' import { ActivityFollow } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' -import { AccountFollowModel } from '../../../models/account/account-follow' -import { getAccountFollowActivityPubUrl } from '../url' +import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' +import { getActorFollowActivityPubUrl } from '../url' import { unicastTo } from './misc' -function sendFollow (accountFollow: AccountFollowModel, t: Transaction) { - const me = accountFollow.AccountFollower - const following = accountFollow.AccountFollowing +function sendFollow (actorFollow: ActorFollowModel, t: Transaction) { + const me = actorFollow.ActorFollower + const following = actorFollow.ActorFollowing - const url = getAccountFollowActivityPubUrl(accountFollow) + const url = getActorFollowActivityPubUrl(actorFollow) const data = followActivityData(url, me, following) return unicastTo(data, me, following.inboxUrl, t) } -function followActivityData (url: string, byAccount: AccountModel, targetAccount: AccountModel): ActivityFollow { +function followActivityData (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow { return { type: 'Follow', id: url, - actor: byAccount.url, - object: targetAccount.url + actor: byActor.url, + object: targetActor.url } } diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index 1a35d0db0..7e0c73796 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts @@ -1,53 +1,53 @@ import { Transaction } from 'sequelize' import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' +import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' import { getVideoLikeActivityPubUrl } from '../url' import { broadcastToFollowers, - getAccountsInvolvedInVideo, + getActorsInvolvedInVideo, getAudience, - getOriginVideoAudience, getObjectFollowersAudience, + getOriginVideoAudience, unicastTo } from './misc' -async function sendLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getVideoLikeActivityPubUrl(byAccount, video) +async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoLikeActivityPubUrl(byActor, video) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) + const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const data = await likeActivityData(url, byAccount, video, t, audience) + const data = await likeActivityData(url, byActor, video, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const url = getVideoLikeActivityPubUrl(byAccount, video) +async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const url = getVideoLikeActivityPubUrl(byActor, video) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) + const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) const audience = getObjectFollowersAudience(accountsInvolvedInVideo) - const data = await likeActivityData(url, byAccount, video, t, audience) + const data = await likeActivityData(url, byActor, video, t, audience) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, accountsInvolvedInVideo, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) } async function likeActivityData ( url: string, - byAccount: AccountModel, + byActor: ActorModel, video: VideoModel, t: Transaction, audience?: ActivityAudience ): Promise { if (!audience) { - audience = await getAudience(byAccount, t) + audience = await getAudience(byActor, t) } return { type: 'Like', id: url, - actor: byAccount.url, + actor: byActor.url, to: audience.to, cc: audience.cc, object: video.url diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 699f920f0..92271b700 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts @@ -6,13 +6,13 @@ import { ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' -import { AccountFollowModel } from '../../../models/account/account-follow' +import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { VideoModel } from '../../../models/video/video' -import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' +import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' import { broadcastToFollowers, - getAccountsInvolvedInVideo, + getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getOriginVideoAudience, @@ -22,11 +22,11 @@ import { createActivityData, createDislikeActivityData } from './send-create' import { followActivityData } from './send-follow' import { likeActivityData } from './send-like' -async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction) { - const me = accountFollow.AccountFollower - const following = accountFollow.AccountFollowing +async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { + const me = actorFollow.ActorFollower + const following = actorFollow.ActorFollowing - const followUrl = getAccountFollowActivityPubUrl(accountFollow) + const followUrl = getActorFollowActivityPubUrl(actorFollow) const undoUrl = getUndoActivityPubUrl(followUrl) const object = followActivityData(followUrl, me, following) @@ -35,58 +35,58 @@ async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction return unicastTo(data, me, following.inboxUrl, t) } -async function sendUndoLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) +async function sendUndoLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const likeUrl = getVideoLikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(likeUrl) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const object = await likeActivityData(likeUrl, byAccount, video, t) - const data = await undoActivityData(undoUrl, byAccount, object, t, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const object = await likeActivityData(likeUrl, byActor, video, t) + const data = await undoActivityData(undoUrl, byActor, object, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendUndoLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) +async function sendUndoLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const likeUrl = getVideoLikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(likeUrl) - const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) - const audience = getObjectFollowersAudience(toAccountsFollowers) - const object = await likeActivityData(likeUrl, byAccount, video, t) - const data = await undoActivityData(undoUrl, byAccount, object, t, audience) + const toActorsFollowers = await getActorsInvolvedInVideo(video, t) + const audience = getObjectFollowersAudience(toActorsFollowers) + const object = await likeActivityData(likeUrl, byActor, video, t) + const data = await undoActivityData(undoUrl, byActor, object, t, audience) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) } -async function sendUndoDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) +async function sendUndoDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(dislikeUrl) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const dislikeActivity = createDislikeActivityData(byAccount, video) - const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const dislikeActivity = createDislikeActivityData(byActor, video) + const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) - const data = await undoActivityData(undoUrl, byAccount, object, t, audience) + const data = await undoActivityData(undoUrl, byActor, object, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendUndoDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) +async function sendUndoDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(dislikeUrl) - const dislikeActivity = createDislikeActivityData(byAccount, video) - const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) + const dislikeActivity = createDislikeActivityData(byActor, video) + const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) - const data = await undoActivityData(undoUrl, byAccount, object, t) + const data = await undoActivityData(undoUrl, byActor, object, t) - const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) + const toActorsFollowers = await getActorsInvolvedInVideo(video, t) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) } // --------------------------------------------------------------------------- @@ -103,19 +103,19 @@ export { async function undoActivityData ( url: string, - byAccount: AccountModel, + byActor: ActorModel, object: ActivityFollow | ActivityLike | ActivityCreate, t: Transaction, audience?: ActivityAudience ): Promise { if (!audience) { - audience = await getAudience(byAccount, t) + audience = await getAudience(byActor, t) } return { type: 'Undo', id: url, - actor: byAccount.url, + actor: byActor.url, to: audience.to, cc: audience.cc, object diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 9baf13a87..48bbbcac1 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts @@ -1,56 +1,52 @@ import { Transaction } from 'sequelize' -import { ActivityUpdate } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' +import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' +import { VideoPrivacy } from '../../../../shared/models/videos' +import { ActorModel } from '../../../models/activitypub/actor' import { VideoModel } from '../../../models/video/video' -import { VideoChannelModel } from '../../../models/video/video-channel' -import { VideoChannelShareModel } from '../../../models/video/video-channel-share' import { VideoShareModel } from '../../../models/video/video-share' import { getUpdateActivityPubUrl } from '../url' import { broadcastToFollowers, getAudience } from './misc' -async function sendUpdateVideoChannel (videoChannel: VideoChannelModel, 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, t) - - const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t) - accountsInvolved.push(byAccount) - - return broadcastToFollowers(data, byAccount, accountsInvolved, t) -} - async function sendUpdateVideo (video: VideoModel, t: Transaction) { - const byAccount = video.VideoChannel.Account + const byActor = video.VideoChannel.Account.Actor const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString()) const videoObject = video.toActivityPubObject() - const data = await updateActivityData(url, byAccount, videoObject, t) + const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC) + + const data = await updateActivityData(url, byActor, videoObject, t, audience) - const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t) - accountsInvolved.push(byAccount) + const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) + actorsInvolved.push(byActor) - return broadcastToFollowers(data, byAccount, accountsInvolved, t) + return broadcastToFollowers(data, byActor, actorsInvolved, t) } // --------------------------------------------------------------------------- export { - sendUpdateVideoChannel, sendUpdateVideo } // --------------------------------------------------------------------------- -async function updateActivityData (url: string, byAccount: AccountModel, object: any, t: Transaction): Promise { - const { to, cc } = await getAudience(byAccount, t) +async function updateActivityData ( + url: string, + byActor: ActorModel, + object: any, + t: Transaction, + audience?: ActivityAudience +): Promise { + if (!audience) { + audience = await getAudience(byActor, t) + } + return { type: 'Update', id: url, - actor: byAccount.url, - to, - cc, + actor: byActor.url, + to: audience.to, + cc: audience.cc, object } } -- cgit v1.2.3