Handle channel owner update of remote server
This commit is contained in:
parent
e81193b04b
commit
b5e1cd9a30
4 changed files with 32 additions and 23 deletions
|
@ -68,26 +68,6 @@ async function getOrCreateAPActor (
|
||||||
return actorRefreshed
|
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) {
|
function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
|
||||||
const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
|
const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
|
||||||
if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
|
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) {
|
async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) {
|
||||||
if ((created === true || refreshed === true) && updateCollections === true) {
|
if ((created === true || refreshed === true) && updateCollections === true) {
|
||||||
const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }
|
const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
|
import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
|
||||||
import { logger } from '@server/helpers/logger'
|
import { logger } from '@server/helpers/logger'
|
||||||
|
import { AccountModel } from '@server/models/account/account'
|
||||||
import { VideoChannelModel } from '@server/models/video/video-channel'
|
import { VideoChannelModel } from '@server/models/video/video-channel'
|
||||||
import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'
|
import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'
|
||||||
import { ActivityPubActor, ActorImageType } from '@shared/models'
|
import { ActivityPubActor, ActorImageType } from '@shared/models'
|
||||||
|
import { getOrCreateAPOwner } from './get'
|
||||||
import { updateActorImageInstance } from './image'
|
import { updateActorImageInstance } from './image'
|
||||||
import { fetchActorFollowsCount } from './shared'
|
import { fetchActorFollowsCount } from './shared'
|
||||||
import { getImageInfoFromObject } from './shared/object-to-model-attributes'
|
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.name = this.actorObject.name || this.actorObject.preferredUsername
|
||||||
this.accountOrChannel.description = this.actorObject.summary
|
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 runInReadCommittedTransaction(async t => {
|
||||||
await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
|
await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
|
||||||
|
|
|
@ -116,7 +116,7 @@ function buildCreateActivity (url: string, byActor: MActorLight, object: any, au
|
||||||
type: 'Create' as 'Create',
|
type: 'Create' as 'Create',
|
||||||
id: url + '/activity',
|
id: url + '/activity',
|
||||||
actor: byActor.url,
|
actor: byActor.url,
|
||||||
object: audiencify(object, audience)
|
object
|
||||||
},
|
},
|
||||||
audience
|
audience
|
||||||
)
|
)
|
||||||
|
|
|
@ -134,7 +134,7 @@ function buildUpdateActivity (url: string, byActor: MActorLight, object: any, au
|
||||||
type: 'Update' as 'Update',
|
type: 'Update' as 'Update',
|
||||||
id: url,
|
id: url,
|
||||||
actor: byActor.url,
|
actor: byActor.url,
|
||||||
object: audiencify(object, audience)
|
object
|
||||||
},
|
},
|
||||||
audience
|
audience
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue