diff options
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 8f46a051e..79fc113f0 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -1,11 +1,16 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity' | 2 | import { |
3 | import { getServerAccount } from '../../../helpers/utils' | 3 | ActivityAudience, |
4 | ActivityCreate, | ||
5 | ActivityFollow, | ||
6 | ActivityLike, | ||
7 | ActivityUndo | ||
8 | } from '../../../../shared/models/activitypub/activity' | ||
4 | import { AccountInstance } from '../../../models' | 9 | import { AccountInstance } from '../../../models' |
5 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | 10 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' |
6 | import { VideoInstance } from '../../../models/video/video-interface' | 11 | import { VideoInstance } from '../../../models/video/video-interface' |
7 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | 12 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' |
8 | import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc' | 13 | import { broadcastToFollowers, getAccountsInvolvedInVideo, getAudience, getVideoFollowersAudience, unicastTo } from './misc' |
9 | import { createActivityData, createDislikeActivityData } from './send-create' | 14 | import { createActivityData, createDislikeActivityData } from './send-create' |
10 | import { followActivityData } from './send-follow' | 15 | import { followActivityData } from './send-follow' |
11 | import { likeActivityData } from './send-like' | 16 | import { likeActivityData } from './send-like' |
@@ -37,14 +42,13 @@ async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: | |||
37 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | 42 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) |
38 | const undoUrl = getUndoActivityPubUrl(likeUrl) | 43 | const undoUrl = getUndoActivityPubUrl(likeUrl) |
39 | 44 | ||
45 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) | ||
46 | const audience = getVideoFollowersAudience(toAccountsFollowers) | ||
40 | const object = await likeActivityData(likeUrl, byAccount, video) | 47 | const object = await likeActivityData(likeUrl, byAccount, video) |
41 | const data = await undoActivityData(undoUrl, byAccount, object) | 48 | const data = await undoActivityData(undoUrl, byAccount, object, audience) |
42 | |||
43 | const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video) | ||
44 | const serverAccount = await getServerAccount() | ||
45 | 49 | ||
46 | const followersException = [ byAccount ] | 50 | const followersException = [ byAccount ] |
47 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 51 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
48 | } | 52 | } |
49 | 53 | ||
50 | async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | 54 | async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { |
@@ -68,11 +72,10 @@ async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, vide | |||
68 | 72 | ||
69 | const data = await undoActivityData(undoUrl, byAccount, object) | 73 | const data = await undoActivityData(undoUrl, byAccount, object) |
70 | 74 | ||
71 | const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video) | 75 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) |
72 | const serverAccount = await getServerAccount() | ||
73 | 76 | ||
74 | const followersException = [ byAccount ] | 77 | const followersException = [ byAccount ] |
75 | return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException) | 78 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
76 | } | 79 | } |
77 | 80 | ||
78 | // --------------------------------------------------------------------------- | 81 | // --------------------------------------------------------------------------- |
@@ -87,11 +90,22 @@ export { | |||
87 | 90 | ||
88 | // --------------------------------------------------------------------------- | 91 | // --------------------------------------------------------------------------- |
89 | 92 | ||
90 | async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow | ActivityLike | ActivityCreate) { | 93 | async function undoActivityData ( |
94 | url: string, | ||
95 | byAccount: AccountInstance, | ||
96 | object: ActivityFollow | ActivityLike | ActivityCreate, | ||
97 | audience?: ActivityAudience | ||
98 | ) { | ||
99 | if (!audience) { | ||
100 | audience = await getAudience(byAccount) | ||
101 | } | ||
102 | |||
91 | const activity: ActivityUndo = { | 103 | const activity: ActivityUndo = { |
92 | type: 'Undo', | 104 | type: 'Undo', |
93 | id: url, | 105 | id: url, |
94 | actor: byAccount.url, | 106 | actor: byAccount.url, |
107 | to: audience.to, | ||
108 | cc: audience.cc, | ||
95 | object | 109 | object |
96 | } | 110 | } |
97 | 111 | ||