import { ResultList } from '../../shared/models'
-import { Activity } from '../../shared/models/activitypub'
+import { Activity, ActivityPubActor } from '../../shared/models/activitypub'
import { ACTIVITY_PUB } from '../initializers'
import { ActorModel } from '../models/activitypub/actor'
import { signObject } from './peertube-crypto'
return signObject(byActor, activity) as Promise<Activity>
}
+function getActorUrl (activityActor: string | ActivityPubActor) {
+ if (typeof activityActor === 'string') return activityActor
+
+ return activityActor.id
+}
+
// ---------------------------------------------------------------------------
export {
+ getActorUrl,
activityPubContextify,
activityPubCollectionPagination,
activityPubCollection,
) ||
(
isActivityPubUrlValid(activity.id) &&
- isActivityPubUrlValid(activity.actor)
+ (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id))
)
}
return (activity['@context'] === undefined || Array.isArray(activity['@context'])) &&
activity.type === type &&
isActivityPubUrlValid(activity.id) &&
- isActivityPubUrlValid(activity.actor) &&
+ (isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id)) &&
(
activity.to === undefined ||
(Array.isArray(activity.to) && activity.to.every(t => isActivityPubUrlValid(t)))
import * as uuidv4 from 'uuid/v4'
import { ActivityPubActor, ActivityPubActorType } from '../../../shared/models/activitypub'
import { ActivityPubAttributedTo } from '../../../shared/models/activitypub/objects'
+import { getActorUrl } from '../../helpers/activitypub'
import { isActorObjectValid } from '../../helpers/custom-validators/activitypub/actor'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { retryTransactionWrapper, updateInstanceWithAnother } from '../../helpers/database-utils'
})
}
-async function getOrCreateActorAndServerAndModel (actorUrl: string, recurseIfNeeded = true) {
+async function getOrCreateActorAndServerAndModel (activityActor: string | ActivityPubActor, recurseIfNeeded = true) {
+ const actorUrl = getActorUrl(activityActor)
+
let actor = await ActorModel.loadByUrl(actorUrl)
// We don't have this actor in our database, fetch it on remote
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'
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)
}
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'
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)
}
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'
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 })
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'
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
}
id: string
to?: string[]
cc?: string[]
- actor: string
+ actor: string | ActivityPubActor
type: ActivityType
signature?: ActivityPubSignature
}