aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-undo.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-14 17:38:41 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 10:53:16 +0100
commit50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch)
treef1732b27edcd05c7877a8358b8312f1e38c287ed /server/lib/activitypub/process/process-undo.ts
parentfadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff)
downloadPeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst
PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip
Begin moving video channel to actor
Diffstat (limited to 'server/lib/activitypub/process/process-undo.ts')
-rw-r--r--server/lib/activitypub/process/process-undo.ts43
1 files changed, 22 insertions, 21 deletions
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts
index efa63122b..4a0181137 100644
--- a/server/lib/activitypub/process/process-undo.ts
+++ b/server/lib/activitypub/process/process-undo.ts
@@ -3,8 +3,9 @@ import { DislikeObject } from '../../../../shared/models/activitypub/objects'
3import { logger, retryTransactionWrapper } from '../../../helpers' 3import { logger, retryTransactionWrapper } from '../../../helpers'
4import { sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
5import { AccountModel } from '../../../models/account/account' 5import { AccountModel } from '../../../models/account/account'
6import { AccountFollowModel } from '../../../models/account/account-follow'
7import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 6import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
7import { ActorModel } from '../../../models/activitypub/actor'
8import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
8import { VideoModel } from '../../../models/video/video' 9import { VideoModel } from '../../../models/video/video'
9import { forwardActivity } from '../send/misc' 10import { forwardActivity } from '../send/misc'
10 11
@@ -32,21 +33,21 @@ export {
32 33
33// --------------------------------------------------------------------------- 34// ---------------------------------------------------------------------------
34 35
35function processUndoLike (actor: string, activity: ActivityUndo) { 36function processUndoLike (actorUrl: string, activity: ActivityUndo) {
36 const options = { 37 const options = {
37 arguments: [ actor, activity ], 38 arguments: [ actorUrl, activity ],
38 errorMessage: 'Cannot undo like with many retries.' 39 errorMessage: 'Cannot undo like with many retries.'
39 } 40 }
40 41
41 return retryTransactionWrapper(undoLike, options) 42 return retryTransactionWrapper(undoLike, options)
42} 43}
43 44
44function undoLike (actor: string, activity: ActivityUndo) { 45function undoLike (actorUrl: string, activity: ActivityUndo) {
45 const likeActivity = activity.object as ActivityLike 46 const likeActivity = activity.object as ActivityLike
46 47
47 return sequelizeTypescript.transaction(async t => { 48 return sequelizeTypescript.transaction(async t => {
48 const byAccount = await AccountModel.loadByUrl(actor, t) 49 const byAccount = await AccountModel.loadByUrl(actorUrl, t)
49 if (!byAccount) throw new Error('Unknown account ' + actor) 50 if (!byAccount) throw new Error('Unknown account ' + actorUrl)
50 51
51 const video = await VideoModel.loadByUrlAndPopulateAccount(likeActivity.object, t) 52 const video = await VideoModel.loadByUrlAndPopulateAccount(likeActivity.object, t)
52 if (!video) throw new Error('Unknown video ' + likeActivity.actor) 53 if (!video) throw new Error('Unknown video ' + likeActivity.actor)
@@ -59,27 +60,27 @@ function undoLike (actor: string, activity: ActivityUndo) {
59 60
60 if (video.isOwned()) { 61 if (video.isOwned()) {
61 // Don't resend the activity to the sender 62 // Don't resend the activity to the sender
62 const exceptions = [ byAccount ] 63 const exceptions = [ byAccount.Actor ]
63 await forwardActivity(activity, t, exceptions) 64 await forwardActivity(activity, t, exceptions)
64 } 65 }
65 }) 66 })
66} 67}
67 68
68function processUndoDislike (actor: string, activity: ActivityUndo) { 69function processUndoDislike (actorUrl: string, activity: ActivityUndo) {
69 const options = { 70 const options = {
70 arguments: [ actor, activity ], 71 arguments: [ actorUrl, activity ],
71 errorMessage: 'Cannot undo dislike with many retries.' 72 errorMessage: 'Cannot undo dislike with many retries.'
72 } 73 }
73 74
74 return retryTransactionWrapper(undoDislike, options) 75 return retryTransactionWrapper(undoDislike, options)
75} 76}
76 77
77function undoDislike (actor: string, activity: ActivityUndo) { 78function undoDislike (actorUrl: string, activity: ActivityUndo) {
78 const dislike = activity.object.object as DislikeObject 79 const dislike = activity.object.object as DislikeObject
79 80
80 return sequelizeTypescript.transaction(async t => { 81 return sequelizeTypescript.transaction(async t => {
81 const byAccount = await AccountModel.loadByUrl(actor, t) 82 const byAccount = await AccountModel.loadByUrl(actorUrl, t)
82 if (!byAccount) throw new Error('Unknown account ' + actor) 83 if (!byAccount) throw new Error('Unknown account ' + actorUrl)
83 84
84 const video = await VideoModel.loadByUrlAndPopulateAccount(dislike.object, t) 85 const video = await VideoModel.loadByUrlAndPopulateAccount(dislike.object, t)
85 if (!video) throw new Error('Unknown video ' + dislike.actor) 86 if (!video) throw new Error('Unknown video ' + dislike.actor)
@@ -92,30 +93,30 @@ function undoDislike (actor: string, activity: ActivityUndo) {
92 93
93 if (video.isOwned()) { 94 if (video.isOwned()) {
94 // Don't resend the activity to the sender 95 // Don't resend the activity to the sender
95 const exceptions = [ byAccount ] 96 const exceptions = [ byAccount.Actor ]
96 await forwardActivity(activity, t, exceptions) 97 await forwardActivity(activity, t, exceptions)
97 } 98 }
98 }) 99 })
99} 100}
100 101
101function processUndoFollow (actor: string, followActivity: ActivityFollow) { 102function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) {
102 const options = { 103 const options = {
103 arguments: [ actor, followActivity ], 104 arguments: [ actorUrl, followActivity ],
104 errorMessage: 'Cannot undo follow with many retries.' 105 errorMessage: 'Cannot undo follow with many retries.'
105 } 106 }
106 107
107 return retryTransactionWrapper(undoFollow, options) 108 return retryTransactionWrapper(undoFollow, options)
108} 109}
109 110
110function undoFollow (actor: string, followActivity: ActivityFollow) { 111function undoFollow (actorUrl: string, followActivity: ActivityFollow) {
111 return sequelizeTypescript.transaction(async t => { 112 return sequelizeTypescript.transaction(async t => {
112 const follower = await AccountModel.loadByUrl(actor, t) 113 const follower = await ActorModel.loadByUrl(actorUrl, t)
113 const following = await AccountModel.loadByUrl(followActivity.object, t) 114 const following = await ActorModel.loadByUrl(followActivity.object, t)
114 const accountFollow = await AccountFollowModel.loadByAccountAndTarget(follower.id, following.id, t) 115 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t)
115 116
116 if (!accountFollow) throw new Error(`'Unknown account follow ${follower.id} -> ${following.id}.`) 117 if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${following.id}.`)
117 118
118 await accountFollow.destroy({ transaction: t }) 119 await actorFollow.destroy({ transaction: t })
119 120
120 return undefined 121 return undefined
121 }) 122 })