aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process/process-update.ts')
-rw-r--r--server/lib/activitypub/process/process-update.ts45
1 files changed, 9 insertions, 36 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 05ea7d272..2c094f7ca 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -8,11 +8,10 @@ import { resetSequelizeInstance } from '../../../helpers/utils'
8import { sequelizeTypescript } from '../../../initializers' 8import { sequelizeTypescript } from '../../../initializers'
9import { AccountModel } from '../../../models/account/account' 9import { AccountModel } from '../../../models/account/account'
10import { ActorModel } from '../../../models/activitypub/actor' 10import { ActorModel } from '../../../models/activitypub/actor'
11import { AvatarModel } from '../../../models/avatar/avatar'
12import { TagModel } from '../../../models/video/tag' 11import { TagModel } from '../../../models/video/tag'
13import { VideoModel } from '../../../models/video/video' 12import { VideoModel } from '../../../models/video/video'
14import { VideoFileModel } from '../../../models/video/video-file' 13import { VideoFileModel } from '../../../models/video/video-file'
15import { fetchActorTotalItems, fetchAvatarIfExists, getOrCreateActorAndServerAndModel } from '../actor' 14import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
16import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' 15import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
17 16
18async function processUpdateActivity (activity: ActivityUpdate) { 17async function processUpdateActivity (activity: ActivityUpdate) {
@@ -124,7 +123,6 @@ async function updateRemoteAccount (actor: ActorModel, activity: ActivityUpdate)
124 const accountAttributesToUpdate = activity.object as ActivityPubActor 123 const accountAttributesToUpdate = activity.object as ActivityPubActor
125 124
126 logger.debug('Updating remote account "%s".', accountAttributesToUpdate.uuid) 125 logger.debug('Updating remote account "%s".', accountAttributesToUpdate.uuid)
127 let actorInstance: ActorModel
128 let accountInstance: AccountModel 126 let accountInstance: AccountModel
129 let actorFieldsSave: object 127 let actorFieldsSave: object
130 let accountFieldsSave: object 128 let accountFieldsSave: object
@@ -134,39 +132,14 @@ async function updateRemoteAccount (actor: ActorModel, activity: ActivityUpdate)
134 132
135 try { 133 try {
136 await sequelizeTypescript.transaction(async t => { 134 await sequelizeTypescript.transaction(async t => {
137 actorInstance = await ActorModel.loadByUrl(accountAttributesToUpdate.id, t) 135 actorFieldsSave = actor.toJSON()
138 if (!actorInstance) throw new Error('Actor ' + accountAttributesToUpdate.id + ' not found.') 136 accountInstance = actor.Account
139 137 accountFieldsSave = actor.Account.toJSON()
140 actorFieldsSave = actorInstance.toJSON()
141 accountInstance = actorInstance.Account
142 accountFieldsSave = actorInstance.Account.toJSON()
143
144 const followersCount = await fetchActorTotalItems(accountAttributesToUpdate.followers)
145 const followingCount = await fetchActorTotalItems(accountAttributesToUpdate.following)
146
147 actorInstance.set('type', accountAttributesToUpdate.type)
148 actorInstance.set('uuid', accountAttributesToUpdate.uuid)
149 actorInstance.set('preferredUsername', accountAttributesToUpdate.preferredUsername)
150 actorInstance.set('url', accountAttributesToUpdate.id)
151 actorInstance.set('publicKey', accountAttributesToUpdate.publicKey.publicKeyPem)
152 actorInstance.set('followersCount', followersCount)
153 actorInstance.set('followingCount', followingCount)
154 actorInstance.set('inboxUrl', accountAttributesToUpdate.inbox)
155 actorInstance.set('outboxUrl', accountAttributesToUpdate.outbox)
156 actorInstance.set('sharedInboxUrl', accountAttributesToUpdate.endpoints.sharedInbox)
157 actorInstance.set('followersUrl', accountAttributesToUpdate.followers)
158 actorInstance.set('followingUrl', accountAttributesToUpdate.following)
159 138
160 if (avatarName !== undefined) { 139 await updateActorInstance(actor, accountAttributesToUpdate)
161 if (actorInstance.avatarId) {
162 await actorInstance.Avatar.destroy({ transaction: t })
163 }
164
165 const avatar = await AvatarModel.create({
166 filename: avatarName
167 }, { transaction: t })
168 140
169 actor.set('avatarId', avatar.id) 141 if (avatarName !== undefined) {
142 await updateActorAvatarInstance(actor, avatarName, t)
170 } 143 }
171 144
172 await actor.save({ transaction: t }) 145 await actor.save({ transaction: t })
@@ -177,8 +150,8 @@ async function updateRemoteAccount (actor: ActorModel, activity: ActivityUpdate)
177 150
178 logger.info('Remote account with uuid %s updated', accountAttributesToUpdate.uuid) 151 logger.info('Remote account with uuid %s updated', accountAttributesToUpdate.uuid)
179 } catch (err) { 152 } catch (err) {
180 if (actorInstance !== undefined && actorFieldsSave !== undefined) { 153 if (actor !== undefined && actorFieldsSave !== undefined) {
181 resetSequelizeInstance(actorInstance, actorFieldsSave) 154 resetSequelizeInstance(actor, actorFieldsSave)
182 } 155 }
183 156
184 if (accountInstance !== undefined && accountFieldsSave !== undefined) { 157 if (accountInstance !== undefined && accountFieldsSave !== undefined) {