PeerTube/server/lib/activitypub/process/process-undo.ts

32 lines
1.0 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { ActivityUndo } from '../../../../shared/models/activitypub/activity'
import { logger } from '../../../helpers/logger'
import { database as db } from '../../../initializers'
async function processUndoActivity (activity: ActivityUndo) {
const activityToUndo = activity.object
if (activityToUndo.type === 'Follow') {
const follower = await db.Account.loadByUrl(activity.actor)
const following = await db.Account.loadByUrl(activityToUndo.object)
const accountFollow = await db.AccountFollow.loadByAccountAndTarget(follower.id, following.id)
2017-11-20 04:19:23 -06:00
if (!accountFollow) throw new Error(`'Unknown account follow ${follower.id} -> ${following.id}.`)
2017-11-20 02:43:39 -06:00
await accountFollow.destroy()
return undefined
}
logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id })
return undefined
}
// ---------------------------------------------------------------------------
export {
processUndoActivity
}
// ---------------------------------------------------------------------------