]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/process/process-undo.ts
5d09423e1046202a51e87268cc2c1de8f584a7b3
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-undo.ts
1 import { ActivityUndo } from '../../../../shared/models/activitypub/activity'
2 import { logger } from '../../../helpers/logger'
3 import { database as db } from '../../../initializers'
4
5 async function processUndoActivity (activity: ActivityUndo) {
6 const activityToUndo = activity.object
7
8 if (activityToUndo.type === 'Follow') {
9 const follower = await db.Account.loadByUrl(activity.actor)
10 const following = await db.Account.loadByUrl(activityToUndo.object)
11 const accountFollow = await db.AccountFollow.loadByAccountAndTarget(follower.id, following.id)
12
13 if (!accountFollow) throw new Error(`'Unknown account follow (${follower.id} -> ${following.id}.`)
14
15 await accountFollow.destroy()
16
17 return undefined
18 }
19
20 logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id })
21
22 return undefined
23 }
24
25 // ---------------------------------------------------------------------------
26
27 export {
28 processUndoActivity
29 }
30
31 // ---------------------------------------------------------------------------