]>
Commit | Line | Data |
---|---|---|
1 | import { Transaction } from 'sequelize' | |
2 | import { | |
3 | ActivityAudience, | |
4 | ActivityCreate, | |
5 | ActivityFollow, | |
6 | ActivityLike, | |
7 | ActivityUndo | |
8 | } from '../../../../shared/models/activitypub/activity' | |
9 | import { AccountInstance } from '../../../models' | |
10 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | |
11 | import { VideoInstance } from '../../../models/video/video-interface' | |
12 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' | |
13 | import { | |
14 | broadcastToFollowers, | |
15 | getAccountsInvolvedInVideo, | |
16 | getAudience, | |
17 | getObjectFollowersAudience, | |
18 | getOriginVideoAudience, | |
19 | unicastTo | |
20 | } from './misc' | |
21 | import { createActivityData, createDislikeActivityData } from './send-create' | |
22 | import { followActivityData } from './send-follow' | |
23 | import { likeActivityData } from './send-like' | |
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 = followActivityData(followUrl, me, following) | |
33 | const data = await undoActivityData(undoUrl, me, object, t) | |
34 | ||
35 | return unicastTo(data, me, following.inboxUrl, t) | |
36 | } | |
37 | ||
38 | async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
39 | const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) | |
40 | const undoUrl = getUndoActivityPubUrl(likeUrl) | |
41 | ||
42 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) | |
43 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | |
44 | const object = await likeActivityData(likeUrl, byAccount, video, t) | |
45 | const data = await undoActivityData(undoUrl, byAccount, object, t, audience) | |
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 | ||
54 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) | |
55 | const audience = getObjectFollowersAudience(toAccountsFollowers) | |
56 | const object = await likeActivityData(likeUrl, byAccount, video, t) | |
57 | const data = await undoActivityData(undoUrl, byAccount, object, t, audience) | |
58 | ||
59 | const followersException = [ byAccount ] | |
60 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) | |
61 | } | |
62 | ||
63 | async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) { | |
64 | const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) | |
65 | const undoUrl = getUndoActivityPubUrl(dislikeUrl) | |
66 | ||
67 | const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) | |
68 | const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) | |
69 | const dislikeActivity = createDislikeActivityData(byAccount, video) | |
70 | const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t, audience) | |
71 | ||
72 | const data = await undoActivityData(undoUrl, byAccount, object, t) | |
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, t) | |
83 | ||
84 | const data = await undoActivityData(undoUrl, byAccount, object, t) | |
85 | ||
86 | const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) | |
87 | ||
88 | const followersException = [ byAccount ] | |
89 | return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) | |
90 | } | |
91 | ||
92 | // --------------------------------------------------------------------------- | |
93 | ||
94 | export { | |
95 | sendUndoFollow, | |
96 | sendUndoLikeToOrigin, | |
97 | sendUndoLikeToVideoFollowers, | |
98 | sendUndoDislikeToOrigin, | |
99 | sendUndoDislikeToVideoFollowers | |
100 | } | |
101 | ||
102 | // --------------------------------------------------------------------------- | |
103 | ||
104 | async function undoActivityData ( | |
105 | url: string, | |
106 | byAccount: AccountInstance, | |
107 | object: ActivityFollow | ActivityLike | ActivityCreate, | |
108 | t: Transaction, | |
109 | audience?: ActivityAudience | |
110 | ) { | |
111 | if (!audience) { | |
112 | audience = await getAudience(byAccount, t) | |
113 | } | |
114 | ||
115 | const activity: ActivityUndo = { | |
116 | type: 'Undo', | |
117 | id: url, | |
118 | actor: byAccount.url, | |
119 | to: audience.to, | |
120 | cc: audience.cc, | |
121 | object | |
122 | } | |
123 | ||
124 | return activity | |
125 | } |