aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/lib/activitypub/actors/get.ts37
-rw-r--r--server/lib/activitypub/actors/updater.ts10
-rw-r--r--server/lib/activitypub/send/send-create.ts2
-rw-r--r--server/lib/activitypub/send/send-update.ts2
4 files changed, 30 insertions, 21 deletions
diff --git a/server/lib/activitypub/actors/get.ts b/server/lib/activitypub/actors/get.ts
index 8681ea02a..4200ddb4d 100644
--- a/server/lib/activitypub/actors/get.ts
+++ b/server/lib/activitypub/actors/get.ts
@@ -68,9 +68,28 @@ async function getOrCreateAPActor (
68 return actorRefreshed 68 return actorRefreshed
69} 69}
70 70
71function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
72 const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
73 if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
74
75 if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {
76 throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)
77 }
78
79 try {
80 // Don't recurse another time
81 const recurseIfNeeded = false
82 return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)
83 } catch (err) {
84 logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
85 throw new Error(err)
86 }
87}
88
71// --------------------------------------------------------------------------- 89// ---------------------------------------------------------------------------
72 90
73export { 91export {
92 getOrCreateAPOwner,
74 getOrCreateAPActor 93 getOrCreateAPActor
75} 94}
76 95
@@ -88,24 +107,6 @@ async function loadActorFromDB (actorUrl: string, fetchType: ActorLoadByUrlType)
88 return actor 107 return actor
89} 108}
90 109
91function getOrCreateAPOwner (actorObject: ActivityPubActor, actorUrl: string) {
92 const accountAttributedTo = actorObject.attributedTo.find(a => a.type === 'Person')
93 if (!accountAttributedTo) throw new Error('Cannot find account attributed to video channel ' + actorUrl)
94
95 if (checkUrlsSameHost(accountAttributedTo.id, actorUrl) !== true) {
96 throw new Error(`Account attributed to ${accountAttributedTo.id} does not have the same host than actor url ${actorUrl}`)
97 }
98
99 try {
100 // Don't recurse another time
101 const recurseIfNeeded = false
102 return getOrCreateAPActor(accountAttributedTo.id, 'all', recurseIfNeeded)
103 } catch (err) {
104 logger.error('Cannot get or create account attributed to video channel ' + actorUrl)
105 throw new Error(err)
106 }
107}
108
109async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) { 110async function scheduleOutboxFetchIfNeeded (actor: MActor, created: boolean, refreshed: boolean, updateCollections: boolean) {
110 if ((created === true || refreshed === true) && updateCollections === true) { 111 if ((created === true || refreshed === true) && updateCollections === true) {
111 const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' } 112 const payload = { uri: actor.outboxUrl, type: 'activity' as 'activity' }
diff --git a/server/lib/activitypub/actors/updater.ts b/server/lib/activitypub/actors/updater.ts
index de5e03eee..042438d9c 100644
--- a/server/lib/activitypub/actors/updater.ts
+++ b/server/lib/activitypub/actors/updater.ts
@@ -1,8 +1,10 @@
1import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils' 1import { resetSequelizeInstance, runInReadCommittedTransaction } from '@server/helpers/database-utils'
2import { logger } from '@server/helpers/logger' 2import { logger } from '@server/helpers/logger'
3import { AccountModel } from '@server/models/account/account'
3import { VideoChannelModel } from '@server/models/video/video-channel' 4import { VideoChannelModel } from '@server/models/video/video-channel'
4import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models' 5import { MAccount, MActor, MActorFull, MChannel } from '@server/types/models'
5import { ActivityPubActor, ActorImageType } from '@shared/models' 6import { ActivityPubActor, ActorImageType } from '@shared/models'
7import { getOrCreateAPOwner } from './get'
6import { updateActorImageInstance } from './image' 8import { updateActorImageInstance } from './image'
7import { fetchActorFollowsCount } from './shared' 9import { fetchActorFollowsCount } from './shared'
8import { getImageInfoFromObject } from './shared/object-to-model-attributes' 10import { getImageInfoFromObject } from './shared/object-to-model-attributes'
@@ -36,7 +38,13 @@ export class APActorUpdater {
36 this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername 38 this.accountOrChannel.name = this.actorObject.name || this.actorObject.preferredUsername
37 this.accountOrChannel.description = this.actorObject.summary 39 this.accountOrChannel.description = this.actorObject.summary
38 40
39 if (this.accountOrChannel instanceof VideoChannelModel) this.accountOrChannel.support = this.actorObject.support 41 if (this.accountOrChannel instanceof VideoChannelModel) {
42 const owner = await getOrCreateAPOwner(this.actorObject, this.actorObject.url)
43 this.accountOrChannel.accountId = owner.Account.id
44 this.accountOrChannel.Account = owner.Account as AccountModel
45
46 this.accountOrChannel.support = this.actorObject.support
47 }
40 48
41 await runInReadCommittedTransaction(async t => { 49 await runInReadCommittedTransaction(async t => {
42 await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t) 50 await updateActorImageInstance(this.actor, ActorImageType.AVATAR, avatarInfo, t)
diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts
index baded642a..f46317163 100644
--- a/server/lib/activitypub/send/send-create.ts
+++ b/server/lib/activitypub/send/send-create.ts
@@ -116,7 +116,7 @@ function buildCreateActivity (url: string, byActor: MActorLight, object: any, au
116 type: 'Create' as 'Create', 116 type: 'Create' as 'Create',
117 id: url + '/activity', 117 id: url + '/activity',
118 actor: byActor.url, 118 actor: byActor.url,
119 object: audiencify(object, audience) 119 object
120 }, 120 },
121 audience 121 audience
122 ) 122 )
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts
index bcf6e1569..3c65e19ed 100644
--- a/server/lib/activitypub/send/send-update.ts
+++ b/server/lib/activitypub/send/send-update.ts
@@ -134,7 +134,7 @@ function buildUpdateActivity (url: string, byActor: MActorLight, object: any, au
134 type: 'Update' as 'Update', 134 type: 'Update' as 'Update',
135 id: url, 135 id: url,
136 actor: byActor.url, 136 actor: byActor.url,
137 object: audiencify(object, audience) 137 object
138 }, 138 },
139 audience 139 audience
140 ) 140 )