aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
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
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')
-rw-r--r--server/lib/activitypub/actor.ts13
-rw-r--r--server/lib/activitypub/process/process-update.ts52
-rw-r--r--server/lib/activitypub/send/send-update.ts23
-rw-r--r--server/lib/activitypub/videos.ts6
4 files changed, 62 insertions, 32 deletions
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index c3255d8ca..897acee85 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -225,12 +225,10 @@ function saveActorAndServerAndModelIfNotExist (
225 }) 225 })
226 226
227 if (actorCreated.type === 'Person' || actorCreated.type === 'Application') { 227 if (actorCreated.type === 'Person' || actorCreated.type === 'Application') {
228 const account = await saveAccount(actorCreated, result, t) 228 actorCreated.Account = await saveAccount(actorCreated, result, t)
229 actorCreated.Account = account
230 actorCreated.Account.Actor = actorCreated 229 actorCreated.Account.Actor = actorCreated
231 } else if (actorCreated.type === 'Group') { // Video channel 230 } else if (actorCreated.type === 'Group') { // Video channel
232 const videoChannel = await saveVideoChannel(actorCreated, result, ownerActor, t) 231 actorCreated.VideoChannel = await saveVideoChannel(actorCreated, result, ownerActor, t)
233 actorCreated.VideoChannel = videoChannel
234 actorCreated.VideoChannel.Actor = actorCreated 232 actorCreated.VideoChannel.Actor = actorCreated
235 } 233 }
236 234
@@ -242,6 +240,7 @@ type FetchRemoteActorResult = {
242 actor: ActorModel 240 actor: ActorModel
243 name: string 241 name: string
244 summary: string 242 summary: string
243 support?: string
245 avatarName?: string 244 avatarName?: string
246 attributedTo: ActivityPubAttributedTo[] 245 attributedTo: ActivityPubAttributedTo[]
247} 246}
@@ -290,6 +289,7 @@ async function fetchRemoteActor (actorUrl: string): Promise<FetchRemoteActorResu
290 name, 289 name,
291 avatarName, 290 avatarName,
292 summary: actorJSON.summary, 291 summary: actorJSON.summary,
292 support: actorJSON.support,
293 attributedTo: actorJSON.attributedTo 293 attributedTo: actorJSON.attributedTo
294 } 294 }
295} 295}
@@ -298,6 +298,7 @@ async function saveAccount (actor: ActorModel, result: FetchRemoteActorResult, t
298 const [ accountCreated ] = await AccountModel.findOrCreate({ 298 const [ accountCreated ] = await AccountModel.findOrCreate({
299 defaults: { 299 defaults: {
300 name: result.name, 300 name: result.name,
301 description: result.summary,
301 actorId: actor.id 302 actorId: actor.id
302 }, 303 },
303 where: { 304 where: {
@@ -314,6 +315,7 @@ async function saveVideoChannel (actor: ActorModel, result: FetchRemoteActorResu
314 defaults: { 315 defaults: {
315 name: result.name, 316 name: result.name,
316 description: result.summary, 317 description: result.summary,
318 support: result.support,
317 actorId: actor.id, 319 actorId: actor.id,
318 accountId: ownerActor.Account.id 320 accountId: ownerActor.Account.id
319 }, 321 },
@@ -352,11 +354,14 @@ async function refreshActorIfNeeded (actor: ActorModel) {
352 await actor.save({ transaction: t }) 354 await actor.save({ transaction: t })
353 355
354 actor.Account.set('name', result.name) 356 actor.Account.set('name', result.name)
357 actor.Account.set('description', result.summary)
355 await actor.Account.save({ transaction: t }) 358 await actor.Account.save({ transaction: t })
356 } else if (actor.VideoChannel) { 359 } else if (actor.VideoChannel) {
357 await actor.save({ transaction: t }) 360 await actor.save({ transaction: t })
358 361
359 actor.VideoChannel.set('name', result.name) 362 actor.VideoChannel.set('name', result.name)
363 actor.VideoChannel.set('description', result.summary)
364 actor.VideoChannel.set('support', result.support)
360 await actor.VideoChannel.save({ transaction: t }) 365 await actor.VideoChannel.save({ transaction: t })
361 } 366 }
362 367
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
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index e8f11edd0..622648308 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -1,9 +1,10 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub'
3import { VideoPrivacy } from '../../../../shared/models/videos' 3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { UserModel } from '../../../models/account/user' 4import { AccountModel } from '../../../models/account/account'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
7import { VideoChannelModel } from '../../../models/video/video-channel'
7import { VideoShareModel } from '../../../models/video/video-share' 8import { VideoShareModel } from '../../../models/video/video-share'
8import { getUpdateActivityPubUrl } from '../url' 9import { getUpdateActivityPubUrl } from '../url'
9import { audiencify, broadcastToFollowers, getAudience } from './misc' 10import { audiencify, broadcastToFollowers, getAudience } from './misc'
@@ -23,15 +24,23 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction) {
23 return broadcastToFollowers(data, byActor, actorsInvolved, t) 24 return broadcastToFollowers(data, byActor, actorsInvolved, t)
24} 25}
25 26
26async function sendUpdateUser (user: UserModel, t: Transaction) { 27async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) {
27 const byActor = user.Account.Actor 28 const byActor = accountOrChannel.Actor
28 29
29 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) 30 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
30 const accountObject = user.Account.toActivityPubObject() 31 const accountOrChannelObject = accountOrChannel.toActivityPubObject()
31 const audience = await getAudience(byActor, t) 32 const audience = await getAudience(byActor, t)
32 const data = await updateActivityData(url, byActor, accountObject, t, audience) 33 const data = await updateActivityData(url, byActor, accountOrChannelObject, t, audience)
34
35 let actorsInvolved: ActorModel[]
36 if (accountOrChannel instanceof AccountModel) {
37 // Actors that shared my videos are involved too
38 actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
39 } else {
40 // Actors that shared videos of my channel are involved too
41 actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t)
42 }
33 43
34 const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
35 actorsInvolved.push(byActor) 44 actorsInvolved.push(byActor)
36 45
37 return broadcastToFollowers(data, byActor, actorsInvolved, t) 46 return broadcastToFollowers(data, byActor, actorsInvolved, t)
@@ -40,7 +49,7 @@ async function sendUpdateUser (user: UserModel, t: Transaction) {
40// --------------------------------------------------------------------------- 49// ---------------------------------------------------------------------------
41 50
42export { 51export {
43 sendUpdateUser, 52 sendUpdateActor,
44 sendUpdateVideo 53 sendUpdateVideo
45} 54}
46 55
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index 40e9318e3..e65362190 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -83,6 +83,11 @@ async function videoActivityObjectToDBAttributes (videoChannel: VideoChannelMode
83 description = videoObject.content 83 description = videoObject.content
84 } 84 }
85 85
86 let support = null
87 if (videoObject.support) {
88 support = videoObject.support
89 }
90
86 return { 91 return {
87 name: videoObject.name, 92 name: videoObject.name,
88 uuid: videoObject.uuid, 93 uuid: videoObject.uuid,
@@ -91,6 +96,7 @@ async function videoActivityObjectToDBAttributes (videoChannel: VideoChannelMode
91 licence, 96 licence,
92 language, 97 language,
93 description, 98 description,
99 support,
94 nsfw: videoObject.sensitive, 100 nsfw: videoObject.sensitive,
95 commentsEnabled: videoObject.commentsEnabled, 101 commentsEnabled: videoObject.commentsEnabled,
96 channelId: videoChannel.id, 102 channelId: videoChannel.id,