diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:10:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-11 15:25:51 +0200 |
commit | 0f320037e689b2778959c12ddd4ce790f6e4ae4f (patch) | |
tree | 425acaa4345442388901c833275bb76b42a8a268 /server/lib/activitypub/process/process-undo.ts | |
parent | 9675333decd0b89b73a4fc67b39272f7296bfe3f (diff) | |
download | PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.tar.gz PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.tar.zst PeerTube-0f320037e689b2778959c12ddd4ce790f6e4ae4f.zip |
Add ability to update a video channel
Diffstat (limited to 'server/lib/activitypub/process/process-undo.ts')
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 565e70289..9b024d15f 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' | 1 | import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { getActorUrl } from '../../../helpers/activitypub' | 3 | import { getActorUrl } from '../../../helpers/activitypub' |
4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' | 4 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
@@ -10,6 +10,7 @@ import { ActorModel } from '../../../models/activitypub/actor' | |||
10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 10 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
11 | import { forwardActivity } from '../send/misc' | 11 | import { forwardActivity } from '../send/misc' |
12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' | 12 | import { getOrCreateAccountAndVideoAndChannel } from '../videos' |
13 | import { VideoShareModel } from '../../../models/video/video-share' | ||
13 | 14 | ||
14 | async function processUndoActivity (activity: ActivityUndo) { | 15 | async function processUndoActivity (activity: ActivityUndo) { |
15 | const activityToUndo = activity.object | 16 | const activityToUndo = activity.object |
@@ -22,6 +23,8 @@ async function processUndoActivity (activity: ActivityUndo) { | |||
22 | return processUndoDislike(actorUrl, activity) | 23 | return processUndoDislike(actorUrl, activity) |
23 | } else if (activityToUndo.type === 'Follow') { | 24 | } else if (activityToUndo.type === 'Follow') { |
24 | return processUndoFollow(actorUrl, activityToUndo) | 25 | return processUndoFollow(actorUrl, activityToUndo) |
26 | } else if (activityToUndo.type === 'Announce') { | ||
27 | return processUndoAnnounce(actorUrl, activityToUndo) | ||
25 | } | 28 | } |
26 | 29 | ||
27 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) | 30 | logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) |
@@ -123,3 +126,23 @@ function undoFollow (actorUrl: string, followActivity: ActivityFollow) { | |||
123 | return undefined | 126 | return undefined |
124 | }) | 127 | }) |
125 | } | 128 | } |
129 | |||
130 | function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | ||
131 | const options = { | ||
132 | arguments: [ actorUrl, announceActivity ], | ||
133 | errorMessage: 'Cannot undo announce with many retries.' | ||
134 | } | ||
135 | |||
136 | return retryTransactionWrapper(undoAnnounce, options) | ||
137 | } | ||
138 | |||
139 | function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { | ||
140 | return sequelizeTypescript.transaction(async t => { | ||
141 | const share = await VideoShareModel.loadByUrl(announceActivity.id, t) | ||
142 | if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`) | ||
143 | |||
144 | await share.destroy({ transaction: t }) | ||
145 | |||
146 | return undefined | ||
147 | }) | ||
148 | } | ||