aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/activitypub
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/activitypub')
-rw-r--r--server/models/activitypub/actor-follow.ts3
-rw-r--r--server/models/activitypub/actor.ts51
2 files changed, 48 insertions, 6 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts
index ced481547..416496607 100644
--- a/server/models/activitypub/actor-follow.ts
+++ b/server/models/activitypub/actor-follow.ts
@@ -375,7 +375,8 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
375 score: { 375 score: {
376 [Sequelize.Op.lte]: 0 376 [Sequelize.Op.lte]: 0
377 } 377 }
378 } 378 },
379 logger: false
379 } 380 }
380 381
381 return ActorFollowModel.findAll(query) 382 return ActorFollowModel.findAll(query)
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 408d4df23..269149a31 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -167,17 +167,17 @@ export class ActorModel extends Model<ActorModel> {
167 }, 167 },
168 onDelete: 'cascade' 168 onDelete: 'cascade'
169 }) 169 })
170 AccountFollowing: ActorFollowModel[] 170 ActorFollowing: ActorFollowModel[]
171 171
172 @HasMany(() => ActorFollowModel, { 172 @HasMany(() => ActorFollowModel, {
173 foreignKey: { 173 foreignKey: {
174 name: 'targetActorId', 174 name: 'targetActorId',
175 allowNull: false 175 allowNull: false
176 }, 176 },
177 as: 'followers', 177 as: 'ActorFollowers',
178 onDelete: 'cascade' 178 onDelete: 'cascade'
179 }) 179 })
180 AccountFollowers: ActorFollowModel[] 180 ActorFollowers: ActorFollowModel[]
181 181
182 @ForeignKey(() => ServerModel) 182 @ForeignKey(() => ServerModel)
183 @Column 183 @Column
@@ -277,6 +277,45 @@ export class ActorModel extends Model<ActorModel> {
277 }) 277 })
278 } 278 }
279 279
280 static async getActorsFollowerSharedInboxUrls (actors: ActorModel[], t: Sequelize.Transaction) {
281 const query = {
282 // attribute: [],
283 where: {
284 id: {
285 [Sequelize.Op.in]: actors.map(a => a.id)
286 }
287 },
288 include: [
289 {
290 // attributes: [ ],
291 model: ActorFollowModel.unscoped(),
292 required: true,
293 as: 'ActorFollowers',
294 where: {
295 state: 'accepted'
296 },
297 include: [
298 {
299 attributes: [ 'sharedInboxUrl' ],
300 model: ActorModel.unscoped(),
301 as: 'ActorFollower',
302 required: true
303 }
304 ]
305 }
306 ],
307 transaction: t
308 }
309
310 const hash: { [ id: number ]: string[] } = {}
311 const res = await ActorModel.findAll(query)
312 for (const actor of res) {
313 hash[actor.id] = actor.ActorFollowers.map(follow => follow.ActorFollower.sharedInboxUrl)
314 }
315
316 return hash
317 }
318
280 toFormattedJSON () { 319 toFormattedJSON () {
281 let avatar: Avatar = null 320 let avatar: Avatar = null
282 if (this.Avatar) { 321 if (this.Avatar) {
@@ -347,10 +386,12 @@ export class ActorModel extends Model<ActorModel> {
347 attributes: [ 'sharedInboxUrl' ], 386 attributes: [ 'sharedInboxUrl' ],
348 include: [ 387 include: [
349 { 388 {
350 model: ActorFollowModel, 389 attribute: [],
390 model: ActorFollowModel.unscoped(),
351 required: true, 391 required: true,
352 as: 'followers', 392 as: 'ActorFollowers',
353 where: { 393 where: {
394 state: 'accepted',
354 targetActorId: this.id 395 targetActorId: this.id
355 } 396 }
356 } 397 }