mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Refractor activity pub lib/helpers
This commit is contained in:
parent
eb8b27c93e
commit
5414139835
47 changed files with 844 additions and 498 deletions
31
server/lib/activitypub/process/process-undo.ts
Normal file
31
server/lib/activitypub/process/process-undo.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
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)
|
||||
|
||||
if (!accountFollow) throw new Error(`'Unknown account follow (${follower.id} -> ${following.id}.`)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
Loading…
Add table
Add a link
Reference in a new issue