-import { resetSequelizeInstance } from '@server/helpers/database-utils'
+import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
import { logger } from '@server/helpers/logger'
-import { sequelizeTypescript } from '@server/initializers/database'
+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 { updateActorImageInstance } from './image'
+import { getOrCreateAPOwner } from './get'
+import { updateActorImages } from './image'
import { fetchActorFollowsCount } from './shared'
-import { getImageInfoFromObject } from './shared/object-to-model-attributes'
+import { getImagesInfoFromObject } from './shared/object-to-model-attributes'
export class APActorUpdater {
}
async update () {
- const avatarInfo = getImageInfoFromObject(this.actorObject, ActorImageType.AVATAR)
- const bannerInfo = getImageInfoFromObject(this.actorObject, ActorImageType.BANNER)
+ const avatarsInfo = getImagesInfoFromObject(this.actorObject, ActorImageType.AVATAR)
+ const bannersInfo = getImagesInfoFromObject(this.actorObject, ActorImageType.BANNER)
try {
- await sequelizeTypescript.transaction(async t => {
- await this.updateActorInstance(this.actor, this.actorObject)
+ await this.updateActorInstance(this.actor, this.actorObject)
- await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
- await updateActorImageInstance(this.actor, ActorImageType.BANNER, bannerInfo, t)
+ this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
+ this.accountOrChannel.description = this.actorObject.summary
- await this.actor.save({ transaction: t })
+ 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.name = this.actorObject.name || this.actorObject.preferredUsername
- this.accountOrChannel.description = this.actorObject.summary
+ this.accountOrChannel.support = this.actorObject.support
+ }
- if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support
+ await runInReadCommittedTransaction(async t => {
+ await updateActorImages(this.actor, ActorImageType.BANNER, bannersInfo, t)
+ await updateActorImages(this.actor, ActorImageType.AVATAR, avatarsInfo, t)
+ })
+ await runInReadCommittedTransaction(async t => {
+ await this.actor.save({ transaction: t })
await this.accountOrChannel.save({ transaction: t })
})