]>
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 | ||
25ed141c C |
32 | const object = followActivityData(followUrl, me, following) |
33 | const data = await undoActivityData(undoUrl, me, object, t) | |
54141398 C |
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 | ||
25ed141c | 42 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
5e3bb76c | 43 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) |
25ed141c C |
44 | const object = await likeActivityData(likeUrl, byAccount, video, t) |
45 | const data = await undoActivityData(undoUrl, byAccount, object, t, 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 | ||
25ed141c | 54 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) |
4e50b6a1 | 55 | const audience = getObjectFollowersAudience(toAccountsFollowers) |
25ed141c C |
56 | const object = await likeActivityData(likeUrl, byAccount, video, t) |
57 | const data = await undoActivityData(undoUrl, byAccount, object, t, 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 | ||
25ed141c | 67 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) |
5e3bb76c | 68 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) |
0032ebe9 | 69 | const dislikeActivity = createDislikeActivityData(byAccount, video) |
fef2c716 | 70 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) |
0032ebe9 | 71 | |
fef2c716 | 72 | const data = await undoActivityData(undoUrl, byAccount, object, t, audience) |
0032ebe9 C |
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) | |
25ed141c | 82 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) |
0032ebe9 | 83 | |
25ed141c | 84 | const data = await undoActivityData(undoUrl, byAccount, object, t) |
0032ebe9 | 85 | |
25ed141c | 86 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) |
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, | |
25ed141c | 108 | t: Transaction, |
63c93323 C |
109 | audience?: ActivityAudience |
110 | ) { | |
111 | if (!audience) { | |
25ed141c | 112 | audience = await getAudience(byAccount, t) |
63c93323 C |
113 | } |
114 | ||
54141398 C |
115 | const activity: ActivityUndo = { |
116 | type: 'Undo', | |
117 | id: url, | |
118 | actor: byAccount.url, | |
63c93323 C |
119 | to: audience.to, |
120 | cc: audience.cc, | |
54141398 C |
121 | object |
122 | } | |
123 | ||
124 | return activity | |
125 | } |