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