]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
63c93323 C |
2 | import { |
3 | ActivityAudience, | |
4 | ActivityCreate, | |
5 | ActivityFollow, | |
6 | ActivityLike, | |
7 | ActivityUndo | |
8 | } from '../../../../shared/models/activitypub/activity' | |
54141398 C |
9 | import { AccountInstance } from '../../../models' |
10 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | |
d8553faa C |
11 | import { VideoInstance } from '../../../models/video/video-interface' |
12 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | |
63c93323 | 13 | import { broadcastToFollowers, getAccountsInvolvedInVideo, getAudience, getVideoFollowersAudience, unicastTo } from './misc' |
d8553faa | 14 | import { createActivityData, createDislikeActivityData } from './send-create' |
54141398 | 15 | import { followActivityData } from './send-follow' |
0032ebe9 | 16 | import { likeActivityData } from './send-like' |
54141398 C |
17 | |
18 | async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) { | |
19 | const me = accountFollow.AccountFollower | |
20 | const following = accountFollow.AccountFollowing | |
21 | ||
22 | const followUrl = getAccountFollowActivityPubUrl(accountFollow) | |
23 | const undoUrl = getUndoActivityPubUrl(followUrl) | |
24 | ||
25 | const object = await followActivityData(followUrl, me, following) | |
26 | const data = await undoActivityData(undoUrl, me, object) | |
27 | ||
28 | return unicastTo(data, me, following.inboxUrl, t) | |
29 | } | |
30 | ||
0032ebe9 C |
31 | async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { |
32 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | |
33 | const undoUrl = getUndoActivityPubUrl(likeUrl) | |
34 | ||
35 | const object = await likeActivityData(likeUrl, byAccount, video) | |
36 | const data = await undoActivityData(undoUrl, byAccount, object) | |
37 | ||
38 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | |
39 | } | |
40 | ||
41 | async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
42 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | |
43 | const undoUrl = getUndoActivityPubUrl(likeUrl) | |
44 | ||
63c93323 C |
45 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) |
46 | const audience = getVideoFollowersAudience(toAccountsFollowers) | |
0032ebe9 | 47 | const object = await likeActivityData(likeUrl, byAccount, video) |
63c93323 | 48 | const data = await undoActivityData(undoUrl, byAccount, object, audience) |
0032ebe9 C |
49 | |
50 | const followersException = [ byAccount ] | |
63c93323 | 51 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
0032ebe9 C |
52 | } |
53 | ||
54 | async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
55 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | |
56 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | |
57 | ||
58 | const dislikeActivity = createDislikeActivityData(byAccount, video) | |
59 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity) | |
60 | ||
61 | const data = await undoActivityData(undoUrl, byAccount, object) | |
62 | ||
63 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | |
64 | } | |
65 | ||
66 | async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
67 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | |
68 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | |
69 | ||
70 | const dislikeActivity = createDislikeActivityData(byAccount, video) | |
71 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity) | |
72 | ||
73 | const data = await undoActivityData(undoUrl, byAccount, object) | |
74 | ||
63c93323 | 75 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) |
0032ebe9 C |
76 | |
77 | const followersException = [ byAccount ] | |
63c93323 | 78 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
0032ebe9 C |
79 | } |
80 | ||
54141398 C |
81 | // --------------------------------------------------------------------------- |
82 | ||
83 | export { | |
0032ebe9 C |
84 | sendUndoFollow, |
85 | sendUndoLikeToOrigin, | |
86 | sendUndoLikeToVideoFollowers, | |
87 | sendUndoDislikeToOrigin, | |
88 | sendUndoDislikeToVideoFollowers | |
54141398 C |
89 | } |
90 | ||
91 | // --------------------------------------------------------------------------- | |
92 | ||
63c93323 C |
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 | ||
54141398 C |
103 | const activity: ActivityUndo = { |
104 | type: 'Undo', | |
105 | id: url, | |
106 | actor: byAccount.url, | |
63c93323 C |
107 | to: audience.to, |
108 | cc: audience.cc, | |
54141398 C |
109 | object |
110 | } | |
111 | ||
112 | return activity | |
113 | } |