Handle channel owner update of remote server

pull/4636/head
Chocobozzz 2021-12-09 11:48:29 +01:00
parent e81193b04b
commit b5e1cd9a30
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 32 additions and 23 deletions

View File

@ -68,26 +68,6 @@ async function getOrCreateAPActor (
return actorRefreshed
}
// ---------------------------------------------------------------------------
export {
getOrCreateAPActor
}
// ---------------------------------------------------------------------------
async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType) {
let actor = await loadActorByUrl(actorUrl, fetchType)
// Orphan actor (not associated to an account of channel) so recreate it
if (actor && (!actor.Account && !actor.VideoChannel)) {
await actor.destroy()
actor = null
}
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)
@ -106,6 +86,27 @@ function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
}
}
// ---------------------------------------------------------------------------
export {
getOrCreateAPOwner,
getOrCreateAPActor
}
// ---------------------------------------------------------------------------
async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType) {
let actor = await loadActorByUrl(actorUrl, fetchType)
// Orphan actor (not associated to an account of channel) so recreate it
if (actor && (!actor.Account && !actor.VideoChannel)) {
await actor.destroy()
actor = null
}
return actor
}
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' }

View File

@ -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.preferredUsername
this.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)

View File

@ -116,7 +116,7 @@ function buildCreateActivity (url: string, byActor: MActorLight, object: any, au
type: 'Create' as 'Create',
id: url + '/activity',
actor: byActor.url,
object: audiencify(object, audience)
object
},
audience
)

View File

@ -134,7 +134,7 @@ function buildUpdateActivity (url: string, byActor: MActorLight, object: any, au
type: 'Update' as 'Update',
id: url,
actor: byActor.url,
object: audiencify(object, audience)
object
},
audience
)