From 66fb2aa39b6f8e4677f80128c27fbafd3a8fe2e7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 21 Nov 2019 12:16:27 +0100 Subject: Don't always replace actor avatar --- server/lib/activitypub/actor.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'server/lib/activitypub/actor.ts') diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts index 74241aba9..14dd1b9b9 100644 --- a/server/lib/activitypub/actor.ts +++ b/server/lib/activitypub/actor.ts @@ -173,25 +173,28 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ type AvatarInfo = { name: string, onDisk: boolean, fileUrl: string } async function updateActorAvatarInstance (actor: MActorDefault, info: AvatarInfo, t: Transaction) { - if (info.name !== undefined) { - if (actor.avatarId) { - try { - await actor.Avatar.destroy({ transaction: t }) - } catch (err) { - logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) - } - } + if (!info.name) return actor - const avatar = await AvatarModel.create({ - filename: info.name, - onDisk: info.onDisk, - fileUrl: info.fileUrl - }, { transaction: t }) + if (actor.Avatar) { + // Don't update the avatar if the filename did not change + if (actor.Avatar.filename === info.name) return actor - actor.avatarId = avatar.id - actor.Avatar = avatar + try { + await actor.Avatar.destroy({ transaction: t }) + } catch (err) { + logger.error('Cannot remove old avatar of actor %s.', actor.url, { err }) + } } + const avatar = await AvatarModel.create({ + filename: info.name, + onDisk: info.onDisk, + fileUrl: info.fileUrl + }, { transaction: t }) + + actor.avatarId = avatar.id + actor.Avatar = avatar + return actor } -- cgit v1.2.3