diff options
Diffstat (limited to 'server/lib/activitypub/process/process-undo.ts')
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 43 |
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' | |||
3 | import { logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { logger, retryTransactionWrapper } from '../../../helpers' |
4 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { AccountModel } from '../../../models/account/account' | 5 | import { AccountModel } from '../../../models/account/account' |
6 | import { AccountFollowModel } from '../../../models/account/account-follow' | ||
7 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
7 | import { ActorModel } from '../../../models/activitypub/actor' | ||
8 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | ||
8 | import { VideoModel } from '../../../models/video/video' | 9 | import { VideoModel } from '../../../models/video/video' |
9 | import { forwardActivity } from '../send/misc' | 10 | import { forwardActivity } from '../send/misc' |
10 | 11 | ||
@@ -32,21 +33,21 @@ export { | |||
32 | 33 | ||
33 | // --------------------------------------------------------------------------- | 34 | // --------------------------------------------------------------------------- |
34 | 35 | ||
35 | function processUndoLike (actor: string, activity: ActivityUndo) { | 36 | function 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 | ||
44 | function undoLike (actor: string, activity: ActivityUndo) { | 45 | function 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 | ||
68 | function processUndoDislike (actor: string, activity: ActivityUndo) { | 69 | function 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 | ||
77 | function undoDislike (actor: string, activity: ActivityUndo) { | 78 | function 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 | ||
101 | function processUndoFollow (actor: string, followActivity: ActivityFollow) { | 102 | function 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 | ||
110 | function undoFollow (actor: string, followActivity: ActivityFollow) { | 111 | function 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 | }) |