aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-15 14:46:26 +0100
committerChocobozzz <me@florianbigard.com>2018-02-15 15:29:07 +0100
commit2422c46b27790d94fd29a7092170cee5a1b56008 (patch)
treed5c1942ce20cadb27a551d87c789edfe92f5b105 /server/lib/activitypub/process
parent34cbef8c6cc912143a421413bdd832c4adcc556a (diff)
downloadPeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.tar.gz
PeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.tar.zst
PeerTube-2422c46b27790d94fd29a7092170cee5a1b56008.zip
Implement support field in video and video channel
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r--server/lib/activitypub/process/process-update.ts52
1 files changed, 31 insertions, 21 deletions
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index c7ad412bc..566e5938b 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -9,20 +9,24 @@ import { 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 { TagModel } from '../../../models/video/tag' 11import { TagModel } from '../../../models/video/tag'
12import { VideoChannelModel } from '../../../models/video/video-channel'
12import { VideoFileModel } from '../../../models/video/video-file' 13import { VideoFileModel } from '../../../models/video/video-file'
13import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor' 14import { fetchAvatarIfExists, getOrCreateActorAndServerAndModel, updateActorAvatarInstance, updateActorInstance } from '../actor'
14import { 15import {
15 generateThumbnailFromUrl, getOrCreateAccountAndVideoAndChannel, videoActivityObjectToDBAttributes, 16 generateThumbnailFromUrl,
17 getOrCreateAccountAndVideoAndChannel,
18 videoActivityObjectToDBAttributes,
16 videoFileActivityUrlToDBAttributes 19 videoFileActivityUrlToDBAttributes
17} from '../videos' 20} from '../videos'
18 21
19async function processUpdateActivity (activity: ActivityUpdate) { 22async function processUpdateActivity (activity: ActivityUpdate) {
20 const actor = await getOrCreateActorAndServerAndModel(activity.actor) 23 const actor = await getOrCreateActorAndServerAndModel(activity.actor)
24 const objectType = activity.object.type
21 25
22 if (activity.object.type === 'Video') { 26 if (objectType === 'Video') {
23 return processUpdateVideo(actor, activity) 27 return processUpdateVideo(actor, activity)
24 } else if (activity.object.type === 'Person') { 28 } else if (objectType === 'Person' || objectType === 'Application' || objectType === 'Group') {
25 return processUpdateAccount(actor, activity) 29 return processUpdateActor(actor, activity)
26 } 30 }
27 31
28 return 32 return
@@ -75,6 +79,7 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
75 videoInstance.set('licence', videoData.licence) 79 videoInstance.set('licence', videoData.licence)
76 videoInstance.set('language', videoData.language) 80 videoInstance.set('language', videoData.language)
77 videoInstance.set('description', videoData.description) 81 videoInstance.set('description', videoData.description)
82 videoInstance.set('support', videoData.support)
78 videoInstance.set('nsfw', videoData.nsfw) 83 videoInstance.set('nsfw', videoData.nsfw)
79 videoInstance.set('commentsEnabled', videoData.commentsEnabled) 84 videoInstance.set('commentsEnabled', videoData.commentsEnabled)
80 videoInstance.set('duration', videoData.duration) 85 videoInstance.set('duration', videoData.duration)
@@ -117,33 +122,36 @@ async function updateRemoteVideo (actor: ActorModel, activity: ActivityUpdate) {
117 } 122 }
118} 123}
119 124
120function processUpdateAccount (actor: ActorModel, activity: ActivityUpdate) { 125function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) {
121 const options = { 126 const options = {
122 arguments: [ actor, activity ], 127 arguments: [ actor, activity ],
123 errorMessage: 'Cannot update the remote account with many retries' 128 errorMessage: 'Cannot update the remote actor with many retries'
124 } 129 }
125 130
126 return retryTransactionWrapper(updateRemoteAccount, options) 131 return retryTransactionWrapper(updateRemoteActor, options)
127} 132}
128 133
129async function updateRemoteAccount (actor: ActorModel, activity: ActivityUpdate) { 134async function updateRemoteActor (actor: ActorModel, activity: ActivityUpdate) {
130 const accountAttributesToUpdate = activity.object as ActivityPubActor 135 const actorAttributesToUpdate = activity.object as ActivityPubActor
131 136
132 logger.debug('Updating remote account "%s".', accountAttributesToUpdate.uuid) 137 logger.debug('Updating remote account "%s".', actorAttributesToUpdate.uuid)
133 let accountInstance: AccountModel 138 let accountOrChannelInstance: AccountModel | VideoChannelModel
134 let actorFieldsSave: object 139 let actorFieldsSave: object
135 let accountFieldsSave: object 140 let accountOrChannelFieldsSave: object
136 141
137 // Fetch icon? 142 // Fetch icon?
138 const avatarName = await fetchAvatarIfExists(accountAttributesToUpdate) 143 const avatarName = await fetchAvatarIfExists(actorAttributesToUpdate)
139 144
140 try { 145 try {
141 await sequelizeTypescript.transaction(async t => { 146 await sequelizeTypescript.transaction(async t => {
142 actorFieldsSave = actor.toJSON() 147 actorFieldsSave = actor.toJSON()
143 accountInstance = actor.Account
144 accountFieldsSave = actor.Account.toJSON()
145 148
146 await updateActorInstance(actor, accountAttributesToUpdate) 149 if (actorAttributesToUpdate.type === 'Group') accountOrChannelInstance = actor.VideoChannel
150 else accountOrChannelInstance = actor.Account
151
152 accountOrChannelFieldsSave = accountOrChannelInstance.toJSON()
153
154 await updateActorInstance(actor, actorAttributesToUpdate)
147 155
148 if (avatarName !== undefined) { 156 if (avatarName !== undefined) {
149 await updateActorAvatarInstance(actor, avatarName, t) 157 await updateActorAvatarInstance(actor, avatarName, t)
@@ -151,18 +159,20 @@ async function updateRemoteAccount (actor: ActorModel, activity: ActivityUpdate)
151 159
152 await actor.save({ transaction: t }) 160 await actor.save({ transaction: t })
153 161
154 actor.Account.set('name', accountAttributesToUpdate.name || accountAttributesToUpdate.preferredUsername) 162 accountOrChannelInstance.set('name', actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername)
155 await actor.Account.save({ transaction: t }) 163 accountOrChannelInstance.set('description', actorAttributesToUpdate.summary)
164 accountOrChannelInstance.set('support', actorAttributesToUpdate.support)
165 await accountOrChannelInstance.save({ transaction: t })
156 }) 166 })
157 167
158 logger.info('Remote account with uuid %s updated', accountAttributesToUpdate.uuid) 168 logger.info('Remote account with uuid %s updated', actorAttributesToUpdate.uuid)
159 } catch (err) { 169 } catch (err) {
160 if (actor !== undefined && actorFieldsSave !== undefined) { 170 if (actor !== undefined && actorFieldsSave !== undefined) {
161 resetSequelizeInstance(actor, actorFieldsSave) 171 resetSequelizeInstance(actor, actorFieldsSave)
162 } 172 }
163 173
164 if (accountInstance !== undefined && accountFieldsSave !== undefined) { 174 if (accountOrChannelInstance !== undefined && accountOrChannelFieldsSave !== undefined) {
165 resetSequelizeInstance(accountInstance, accountFieldsSave) 175 resetSequelizeInstance(accountOrChannelInstance, accountOrChannelFieldsSave)
166 } 176 }
167 177
168 // This is just a debug because we will retry the insert 178 // This is just a debug because we will retry the insert