aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-undo.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-23 14:19:55 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit0032ebe94aa83fab761c7de3ceb6210ac4532824 (patch)
tree3ea407d7ea6de4c7f7bc66caba7e23c0cc4036e3 /server/lib/activitypub/send/send-undo.ts
parentd52eb8f656242c7e34afdb2dee681861fb9bce35 (diff)
downloadPeerTube-0032ebe94aa83fab761c7de3ceb6210ac4532824.tar.gz
PeerTube-0032ebe94aa83fab761c7de3ceb6210ac4532824.tar.zst
PeerTube-0032ebe94aa83fab761c7de3ceb6210ac4532824.zip
Federate likes/dislikes
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r--server/lib/activitypub/send/send-undo.ts71
1 files changed, 66 insertions, 5 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index 77bee6639..53fddd0cb 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -1,10 +1,14 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityFollow, ActivityUndo } from '../../../../shared/models/activitypub/activity' 2import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
3import { AccountInstance } from '../../../models' 3import { AccountInstance } from '../../../models'
4import { AccountFollowInstance } from '../../../models/account/account-follow-interface' 4import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
5import { unicastTo } from './misc' 5import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc'
6import { followActivityData } from './send-follow' 6import { followActivityData } from './send-follow'
7import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl } from '../url' 7import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
8import { VideoInstance } from '../../../models/video/video-interface'
9import { likeActivityData } from './send-like'
10import { createActivityData, createDislikeActivityData } from './send-create'
11import { getServerAccount } from '../../../helpers/utils'
8 12
9async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) { 13async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) {
10 const me = accountFollow.AccountFollower 14 const me = accountFollow.AccountFollower
@@ -19,15 +23,72 @@ async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transact
19 return unicastTo(data, me, following.inboxUrl, t) 23 return unicastTo(data, me, following.inboxUrl, t)
20} 24}
21 25
26async 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
36async 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
50async 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
62async 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
78
22// --------------------------------------------------------------------------- 79// ---------------------------------------------------------------------------
23 80
24export { 81export {
25 sendUndoFollow 82 sendUndoFollow,
83 sendUndoLikeToOrigin,
84 sendUndoLikeToVideoFollowers,
85 sendUndoDislikeToOrigin,
86 sendUndoDislikeToVideoFollowers
26} 87}
27 88
28// --------------------------------------------------------------------------- 89// ---------------------------------------------------------------------------
29 90
30async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow) { 91async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow | ActivityLike | ActivityCreate) {
31 const activity: ActivityUndo = { 92 const activity: ActivityUndo = {
32 type: 'Undo', 93 type: 'Undo',
33 id: url, 94 id: url,