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.ts62
1 files changed, 8 insertions, 54 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index d2b63c901..aa80d5d09 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -1,19 +1,16 @@
1import { isRedundancyAccepted } from '@server/lib/redundancy' 1import { isRedundancyAccepted } from '@server/lib/redundancy'
2import { ActorImageType } from '@shared/models'
3import { ActivityUpdate, CacheFileObject, VideoObject } from '../../../../shared/models/activitypub' 2import { ActivityUpdate, CacheFileObject, VideoObject } from '../../../../shared/models/activitypub'
4import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor' 3import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
5import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' 4import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
6import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file' 5import { isCacheFileObjectValid } from '../../../helpers/custom-validators/activitypub/cache-file'
7import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos' 6import { sanitizeAndCheckVideoTorrentObject } from '../../../helpers/custom-validators/activitypub/videos'
8import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils' 7import { retryTransactionWrapper } from '../../../helpers/database-utils'
9import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
10import { sequelizeTypescript } from '../../../initializers/database' 9import { sequelizeTypescript } from '../../../initializers/database'
11import { AccountModel } from '../../../models/account/account'
12import { ActorModel } from '../../../models/actor/actor' 10import { ActorModel } from '../../../models/actor/actor'
13import { VideoChannelModel } from '../../../models/video/video-channel'
14import { APProcessorOptions } from '../../../types/activitypub-processor.model' 11import { APProcessorOptions } from '../../../types/activitypub-processor.model'
15import { MActorSignature } from '../../../types/models' 12import { MActorFull, MActorSignature } from '../../../types/models'
16import { getImageInfoIfExists, updateActorImageInstance, updateActorInstance } from '../actor' 13import { APActorUpdater } from '../actors/updater'
17import { createOrUpdateCacheFile } from '../cache-file' 14import { createOrUpdateCacheFile } from '../cache-file'
18import { createOrUpdateVideoPlaylist } from '../playlists' 15import { createOrUpdateVideoPlaylist } from '../playlists'
19import { forwardVideoRelatedActivity } from '../send/utils' 16import { forwardVideoRelatedActivity } from '../send/utils'
@@ -99,56 +96,13 @@ async function processUpdateCacheFile (byActor: MActorSignature, activity: Activ
99 } 96 }
100} 97}
101 98
102async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) { 99async function processUpdateActor (actor: MActorFull, activity: ActivityUpdate) {
103 const actorAttributesToUpdate = activity.object as ActivityPubActor 100 const actorObject = activity.object as ActivityPubActor
104 101
105 logger.debug('Updating remote account "%s".', actorAttributesToUpdate.url) 102 logger.debug('Updating remote account "%s".', actorObject.url)
106 let accountOrChannelInstance: AccountModel | VideoChannelModel
107 let actorFieldsSave: object
108 let accountOrChannelFieldsSave: object
109 103
110 // Fetch icon? 104 const updater = new APActorUpdater(actorObject, actor)
111 const avatarInfo = getImageInfoIfExists(actorAttributesToUpdate, ActorImageType.AVATAR) 105 return updater.update()
112 const bannerInfo = getImageInfoIfExists(actorAttributesToUpdate, ActorImageType.BANNER)
113
114 try {
115 await sequelizeTypescript.transaction(async t => {
116 actorFieldsSave = actor.toJSON()
117
118 if (actorAttributesToUpdate.type === 'Group') accountOrChannelInstance = actor.VideoChannel
119 else accountOrChannelInstance = actor.Account
120
121 accountOrChannelFieldsSave = accountOrChannelInstance.toJSON()
122
123 await updateActorInstance(actor, actorAttributesToUpdate)
124
125 await updateActorImageInstance(actor, ActorImageType.AVATAR, avatarInfo, t)
126 await updateActorImageInstance(actor, ActorImageType.BANNER, bannerInfo, t)
127
128 await actor.save({ transaction: t })
129
130 accountOrChannelInstance.name = actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername
131 accountOrChannelInstance.description = actorAttributesToUpdate.summary
132
133 if (accountOrChannelInstance instanceof VideoChannelModel) accountOrChannelInstance.support = actorAttributesToUpdate.support
134
135 await accountOrChannelInstance.save({ transaction: t })
136 })
137
138 logger.info('Remote account %s updated', actorAttributesToUpdate.url)
139 } catch (err) {
140 if (actor !== undefined && actorFieldsSave !== undefined) {
141 resetSequelizeInstance(actor, actorFieldsSave)
142 }
143
144 if (accountOrChannelInstance !== undefined && accountOrChannelFieldsSave !== undefined) {
145 resetSequelizeInstance(accountOrChannelInstance, accountOrChannelFieldsSave)
146 }
147
148 // This is just a debug because we will retry the insert
149 logger.debug('Cannot update the remote account.', { err })
150 throw err
151 }
152} 106}
153 107
154async function processUpdatePlaylist (byActor: MActorSignature, activity: ActivityUpdate) { 108async function processUpdatePlaylist (byActor: MActorSignature, activity: ActivityUpdate) {