]>
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' | |
5e3bb76c C |
13 | import { |
14 | broadcastToFollowers, | |
15 | getAccountsInvolvedInVideo, | |
16 | getAudience, | |
17 | getObjectFollowersAudience, | |
18 | getOriginVideoAudience, | |
19 | unicastTo | |
20 | } from './misc' | |
d8553faa | 21 | import { createActivityData, createDislikeActivityData } from './send-create' |
54141398 | 22 | import { followActivityData } from './send-follow' |
0032ebe9 | 23 | import { likeActivityData } from './send-like' |
54141398 C |
24 | |
25 | async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) { | |
26 | const me = accountFollow.AccountFollower | |
27 | const following = accountFollow.AccountFollowing | |
28 | ||
29 | const followUrl = getAccountFollowActivityPubUrl(accountFollow) | |
30 | const undoUrl = getUndoActivityPubUrl(followUrl) | |
31 | ||
32 | const object = await followActivityData(followUrl, me, following) | |
33 | const data = await undoActivityData(undoUrl, me, object) | |
34 | ||
35 | return unicastTo(data, me, following.inboxUrl, t) | |
36 | } | |
37 | ||
0032ebe9 C |
38 | async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { |
39 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | |
40 | const undoUrl = getUndoActivityPubUrl(likeUrl) | |
41 | ||
5e3bb76c C |
42 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) |
43 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | |
0032ebe9 | 44 | const object = await likeActivityData(likeUrl, byAccount, video) |
5e3bb76c | 45 | const data = await undoActivityData(undoUrl, byAccount, object, audience) |
0032ebe9 C |
46 | |
47 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | |
48 | } | |
49 | ||
50 | async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
51 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | |
52 | const undoUrl = getUndoActivityPubUrl(likeUrl) | |
53 | ||
63c93323 | 54 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) |
4e50b6a1 | 55 | const audience = getObjectFollowersAudience(toAccountsFollowers) |
0032ebe9 | 56 | const object = await likeActivityData(likeUrl, byAccount, video) |
63c93323 | 57 | const data = await undoActivityData(undoUrl, byAccount, object, audience) |
0032ebe9 C |
58 | |
59 | const followersException = [ byAccount ] | |
63c93323 | 60 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
0032ebe9 C |
61 | } |
62 | ||
63 | async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
64 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | |
65 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | |
66 | ||
5e3bb76c C |
67 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video) |
68 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | |
0032ebe9 | 69 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
5e3bb76c | 70 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity, audience) |
0032ebe9 C |
71 | |
72 | const data = await undoActivityData(undoUrl, byAccount, object) | |
73 | ||
74 | return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) | |
75 | } | |
76 | ||
77 | async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
78 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | |
79 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | |
80 | ||
81 | const dislikeActivity = createDislikeActivityData(byAccount, video) | |
82 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity) | |
83 | ||
84 | const data = await undoActivityData(undoUrl, byAccount, object) | |
85 | ||
63c93323 | 86 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video) |
0032ebe9 C |
87 | |
88 | const followersException = [ byAccount ] | |
63c93323 | 89 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) |
0032ebe9 C |
90 | } |
91 | ||
54141398 C |
92 | // --------------------------------------------------------------------------- |
93 | ||
94 | export { | |
0032ebe9 C |
95 | sendUndoFollow, |
96 | sendUndoLikeToOrigin, | |
97 | sendUndoLikeToVideoFollowers, | |
98 | sendUndoDislikeToOrigin, | |
99 | sendUndoDislikeToVideoFollowers | |
54141398 C |
100 | } |
101 | ||
102 | // --------------------------------------------------------------------------- | |
103 | ||
63c93323 C |
104 | async function undoActivityData ( |
105 | url: string, | |
106 | byAccount: AccountInstance, | |
107 | object: ActivityFollow | ActivityLike | ActivityCreate, | |
108 | audience?: ActivityAudience | |
109 | ) { | |
110 | if (!audience) { | |
111 | audience = await getAudience(byAccount) | |
112 | } | |
113 | ||
54141398 C |
114 | const activity: ActivityUndo = { |
115 | type: 'Undo', | |
116 | id: url, | |
117 | actor: byAccount.url, | |
63c93323 C |
118 | to: audience.to, |
119 | cc: audience.cc, | |
54141398 C |
120 | object |
121 | } | |
122 | ||
123 | return activity | |
124 | } |