]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-undo.ts
Add ability to list jobs
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-undo.ts
CommitLineData
54141398 1import { Transaction } from 'sequelize'
63c93323
C
2import {
3 ActivityAudience,
4 ActivityCreate,
5 ActivityFollow,
6 ActivityLike,
7 ActivityUndo
8} from '../../../../shared/models/activitypub/activity'
54141398
C
9import { AccountInstance } from '../../../models'
10import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
d8553faa
C
11import { VideoInstance } from '../../../models/video/video-interface'
12import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
5e3bb76c
C
13import {
14 broadcastToFollowers,
15 getAccountsInvolvedInVideo,
16 getAudience,
17 getObjectFollowersAudience,
18 getOriginVideoAudience,
19 unicastTo
20} from './misc'
d8553faa 21import { createActivityData, createDislikeActivityData } from './send-create'
54141398 22import { followActivityData } from './send-follow'
0032ebe9 23import { likeActivityData } from './send-like'
54141398
C
24
25async 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
38async 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
50async 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
63async 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
77async 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
94export {
0032ebe9
C
95 sendUndoFollow,
96 sendUndoLikeToOrigin,
97 sendUndoLikeToVideoFollowers,
98 sendUndoDislikeToOrigin,
99 sendUndoDislikeToVideoFollowers
54141398
C
100}
101
102// ---------------------------------------------------------------------------
103
63c93323
C
104async 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}