mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Improve activity pub actors implementation
This commit is contained in:
parent
9e841674da
commit
6be84cbcea
9 changed files with 32 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
import { ActivityAccept } from '../../../../shared/models/activitypub'
|
||||
import { getActorUrl } from '../../../helpers/activitypub'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { addFetchOutboxJob } from '../fetch'
|
||||
|
@ -6,7 +7,8 @@ import { addFetchOutboxJob } from '../fetch'
|
|||
async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) {
|
||||
if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
|
||||
|
||||
const targetActor = await ActorModel.loadByUrl(activity.actor)
|
||||
const actorUrl = getActorUrl(activity.actor)
|
||||
const targetActor = await ActorModel.loadByUrl(actorUrl)
|
||||
|
||||
return processAccept(inboxActor, targetActor)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { ActivityReject } from '../../../../shared/models/activitypub/activity'
|
||||
import { getActorUrl } from '../../../helpers/activitypub'
|
||||
import { sequelizeTypescript } from '../../../initializers'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
|
@ -6,7 +7,8 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
|||
async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) {
|
||||
if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.')
|
||||
|
||||
const targetActor = await ActorModel.loadByUrl(activity.actor)
|
||||
const actorUrl = getActorUrl(activity.actor)
|
||||
const targetActor = await ActorModel.loadByUrl(actorUrl)
|
||||
|
||||
return processReject(inboxActor, targetActor)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub'
|
||||
import { DislikeObject } from '../../../../shared/models/activitypub/objects'
|
||||
import { getActorUrl } from '../../../helpers/activitypub'
|
||||
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { sequelizeTypescript } from '../../../initializers'
|
||||
|
@ -13,12 +14,14 @@ import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
|||
async function processUndoActivity (activity: ActivityUndo) {
|
||||
const activityToUndo = activity.object
|
||||
|
||||
const actorUrl = getActorUrl(activity.actor)
|
||||
|
||||
if (activityToUndo.type === 'Like') {
|
||||
return processUndoLike(activity.actor, activity)
|
||||
return processUndoLike(actorUrl, activity)
|
||||
} else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') {
|
||||
return processUndoDislike(activity.actor, activity)
|
||||
return processUndoDislike(actorUrl, activity)
|
||||
} else if (activityToUndo.type === 'Follow') {
|
||||
return processUndoFollow(activity.actor, activityToUndo)
|
||||
return processUndoFollow(actorUrl, activityToUndo)
|
||||
}
|
||||
|
||||
logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id })
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Activity, ActivityType } from '../../../../shared/models/activitypub'
|
||||
import { getActorUrl } from '../../../helpers/activitypub'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { processAcceptActivity } from './process-accept'
|
||||
|
@ -25,9 +26,11 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor?
|
|||
|
||||
async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) {
|
||||
for (const activity of activities) {
|
||||
const actorUrl = getActorUrl(activity.actor)
|
||||
|
||||
// When we fetch remote data, we don't have signature
|
||||
if (signatureActor && activity.actor !== signatureActor.url) {
|
||||
logger.warn('Signature mismatch between %s and %s.', activity.actor, signatureActor.url)
|
||||
if (signatureActor && actorUrl !== signatureActor.url) {
|
||||
logger.warn('Signature mismatch between %s and %s.', actorUrl, signatureActor.url)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue