ActivityPub-federated video streaming platform using P2P directly in your web browser
Handle channel owner update of remote server
Chocobozzzb5e1cd9a3088
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.tsindex 8681ea02ad..4200ddb4df 100644--- a/server/lib/activitypub/actors/get.ts+++ b/server/lib/activitypub/actors/get.ts@@ -68,9 +68,28 @@ async function getOrCreateAPActor (return actorRefreshed}+function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {+ const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')+ if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)++ if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {+ throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)+ }++ try {+ // Don't recurse another time+ const recurseIfNeeded = false+ return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)+ } catch (err) {+ logger.error('Cannot get or create account attributed to video channel ' + actorUrl)+ throw new Error(err)+ }+}+// ---------------------------------------------------------------------------export {+ getOrCreateAPOwner,getOrCreateAPActor}@@ -88,24 +107,6 @@ async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType)return actor}-function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {- const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')- if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)-- if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {- throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)- }-- try {- // Don't recurse another time- const recurseIfNeeded = false- return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)- } catch (err) {- logger.error('Cannot get or create account attributed to video channel ' + actorUrl)- throw new Error(err)- }-}-async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) {if ((created === true || refreshed === true) && updateCollections === true) {const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }diff --git a/server/lib/activitypub/actors/updater.ts b/server/lib/activitypub/actors/updater.tsindex de5e03eee2..042438d9cc 100644--- a/server/lib/activitypub/actors/updater.ts+++ b/server/lib/activitypub/actors/updater.ts@@ -1,8 +1,10 @@import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'import { logger } from '@server/helpers/logger'+import { AccountModel } from '@server/models/account/account'import { VideoChannelModel } from '@server/models/video/video-channel'import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'import { ActivityPubActor, ActorImageType } from '@shared/models'+import { getOrCreateAPOwner } from './get'import { updateActorImageInstance } from './image'import { fetchActorFollowsCount } from './shared'import { getImageInfoFromObject } from './shared/object-to-model-attributes'@@ -36,7 +38,13 @@ export class APActorUpdater {this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsernamethis.accountOrChannel.description = this.actorObject.summary- if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support+ if (this.accountOrChannel instanceof VideoChannelModel) {+ const owner = await getOrCreateAPOwner(this.actorObject, this.actorObject.url)+ this.accountOrChannel.accountId = owner.Account.id+ this.accountOrChannel.Account = owner.Account as AccountModel++ this.accountOrChannel.support = this.actorObject.support+ }await runInReadCommittedTransaction(async t => {await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.tsindex baded642ac..f463171639 100644--- a/server/lib/activitypub/send/send-create.ts+++ b/server/lib/activitypub/send/send-create.ts@@ -116,7 +116,7 @@ function buildCreateActivity (url: string, byActor: MActorLight, object: any, autype: 'Create' as 'Create',id: url + '/activity',actor: byActor.url,- object: audiencify(object, audience)+ object},audience)diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.tsindex bcf6e15696..3c65e19edf 100644--- a/server/lib/activitypub/send/send-update.ts+++ b/server/lib/activitypub/send/send-update.ts@@ -134,7 +134,7 @@ function buildUpdateActivity (url: string, byActor: MActorLight, object: any, autype: 'Update' as 'Update',id: url,actor: byActor.url,- object: audiencify(object, audience)+ object},audience)