diff options
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 53 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 12 |
2 files changed, 33 insertions, 32 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index f21d2b8a2..27643704e 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { values, difference } from 'lodash' | 2 | import { difference, values } from 'lodash' |
3 | import { | 3 | import { |
4 | AfterCreate, | 4 | AfterCreate, |
5 | AfterDestroy, | 5 | AfterDestroy, |
@@ -23,7 +23,7 @@ import { logger } from '../../helpers/logger' | |||
23 | import { getServerActor } from '../../helpers/utils' | 23 | import { getServerActor } from '../../helpers/utils' |
24 | import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants' | 24 | import { ACTOR_FOLLOW_SCORE, FOLLOW_STATES, SERVER_ACTOR_NAME } from '../../initializers/constants' |
25 | import { ServerModel } from '../server/server' | 25 | import { ServerModel } from '../server/server' |
26 | import { createSafeIn, getSort, getFollowsSort } from '../utils' | 26 | import { createSafeIn, getFollowsSort, getSort } from '../utils' |
27 | import { ActorModel, unusedActorAttributesForAPI } from './actor' | 27 | import { ActorModel, unusedActorAttributesForAPI } from './actor' |
28 | import { VideoChannelModel } from '../video/video-channel' | 28 | import { VideoChannelModel } from '../video/video-channel' |
29 | import { AccountModel } from '../account/account' | 29 | import { AccountModel } from '../account/account' |
@@ -36,7 +36,6 @@ import { | |||
36 | MActorFollowSubscriptions | 36 | MActorFollowSubscriptions |
37 | } from '@server/typings/models' | 37 | } from '@server/typings/models' |
38 | import { ActivityPubActorType } from '@shared/models' | 38 | import { ActivityPubActorType } from '@shared/models' |
39 | import { afterCommitIfTransaction } from '@server/helpers/database-utils' | ||
40 | 39 | ||
41 | @Table({ | 40 | @Table({ |
42 | tableName: 'actorFollow', | 41 | tableName: 'actorFollow', |
@@ -226,7 +225,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
226 | 225 | ||
227 | return ActorFollowModel.findOne(query) | 226 | return ActorFollowModel.findOne(query) |
228 | .then(result => { | 227 | .then(result => { |
229 | if (result && result.ActorFollowing.VideoChannel) { | 228 | if (result?.ActorFollowing.VideoChannel) { |
230 | result.ActorFollowing.VideoChannel.Actor = result.ActorFollowing | 229 | result.ActorFollowing.VideoChannel.Actor = result.ActorFollowing |
231 | } | 230 | } |
232 | 231 | ||
@@ -239,24 +238,24 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
239 | .map(t => { | 238 | .map(t => { |
240 | if (t.host) { | 239 | if (t.host) { |
241 | return { | 240 | return { |
242 | [ Op.and ]: [ | 241 | [Op.and]: [ |
243 | { | 242 | { |
244 | '$preferredUsername$': t.name | 243 | $preferredUsername$: t.name |
245 | }, | 244 | }, |
246 | { | 245 | { |
247 | '$host$': t.host | 246 | $host$: t.host |
248 | } | 247 | } |
249 | ] | 248 | ] |
250 | } | 249 | } |
251 | } | 250 | } |
252 | 251 | ||
253 | return { | 252 | return { |
254 | [ Op.and ]: [ | 253 | [Op.and]: [ |
255 | { | 254 | { |
256 | '$preferredUsername$': t.name | 255 | $preferredUsername$: t.name |
257 | }, | 256 | }, |
258 | { | 257 | { |
259 | '$serverId$': null | 258 | $serverId$: null |
260 | } | 259 | } |
261 | ] | 260 | ] |
262 | } | 261 | } |
@@ -265,9 +264,9 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
265 | const query = { | 264 | const query = { |
266 | attributes: [], | 265 | attributes: [], |
267 | where: { | 266 | where: { |
268 | [ Op.and ]: [ | 267 | [Op.and]: [ |
269 | { | 268 | { |
270 | [ Op.or ]: whereTab | 269 | [Op.or]: whereTab |
271 | }, | 270 | }, |
272 | { | 271 | { |
273 | actorId | 272 | actorId |
@@ -295,12 +294,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
295 | } | 294 | } |
296 | 295 | ||
297 | static listFollowingForApi (options: { | 296 | static listFollowingForApi (options: { |
298 | id: number, | 297 | id: number |
299 | start: number, | 298 | start: number |
300 | count: number, | 299 | count: number |
301 | sort: string, | 300 | sort: string |
302 | state?: FollowState, | 301 | state?: FollowState |
303 | actorType?: ActivityPubActorType, | 302 | actorType?: ActivityPubActorType |
304 | search?: string | 303 | search?: string |
305 | }) { | 304 | }) { |
306 | const { id, start, count, sort, search, state, actorType } = options | 305 | const { id, start, count, sort, search, state, actorType } = options |
@@ -312,7 +311,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
312 | if (search) { | 311 | if (search) { |
313 | Object.assign(followingServerWhere, { | 312 | Object.assign(followingServerWhere, { |
314 | host: { | 313 | host: { |
315 | [ Op.iLike ]: '%' + search + '%' | 314 | [Op.iLike]: '%' + search + '%' |
316 | } | 315 | } |
317 | }) | 316 | }) |
318 | } | 317 | } |
@@ -362,12 +361,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
362 | } | 361 | } |
363 | 362 | ||
364 | static listFollowersForApi (options: { | 363 | static listFollowersForApi (options: { |
365 | actorId: number, | 364 | actorId: number |
366 | start: number, | 365 | start: number |
367 | count: number, | 366 | count: number |
368 | sort: string, | 367 | sort: string |
369 | state?: FollowState, | 368 | state?: FollowState |
370 | actorType?: ActivityPubActorType, | 369 | actorType?: ActivityPubActorType |
371 | search?: string | 370 | search?: string |
372 | }) { | 371 | }) { |
373 | const { actorId, start, count, sort, search, state, actorType } = options | 372 | const { actorId, start, count, sort, search, state, actorType } = options |
@@ -379,7 +378,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
379 | if (search) { | 378 | if (search) { |
380 | Object.assign(followerServerWhere, { | 379 | Object.assign(followerServerWhere, { |
381 | host: { | 380 | host: { |
382 | [ Op.iLike ]: '%' + search + '%' | 381 | [Op.iLike]: '%' + search + '%' |
383 | } | 382 | } |
384 | }) | 383 | }) |
385 | } | 384 | } |
@@ -631,7 +630,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
631 | 630 | ||
632 | const tasks: Bluebird<any>[] = [] | 631 | const tasks: Bluebird<any>[] = [] |
633 | 632 | ||
634 | for (let selection of selections) { | 633 | for (const selection of selections) { |
635 | let query = 'SELECT ' + selection + ' FROM "actor" ' + | 634 | let query = 'SELECT ' + selection + ' FROM "actor" ' + |
636 | 'INNER JOIN "actorFollow" ON "actorFollow"."' + firstJoin + '" = "actor"."id" ' + | 635 | 'INNER JOIN "actorFollow" ON "actorFollow"."' + firstJoin + '" = "actor"."id" ' + |
637 | 'INNER JOIN "actor" AS "Follows" ON "actorFollow"."' + secondJoin + '" = "Follows"."id" ' + | 636 | 'INNER JOIN "actor" AS "Follows" ON "actorFollow"."' + secondJoin + '" = "Follows"."id" ' + |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index d651a281a..00e8dc954 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -16,7 +16,7 @@ import { | |||
16 | Table, | 16 | Table, |
17 | UpdatedAt | 17 | UpdatedAt |
18 | } from 'sequelize-typescript' | 18 | } from 'sequelize-typescript' |
19 | import { ActivityPubActorType } from '../../../shared/models/activitypub' | 19 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' |
20 | import { Avatar } from '../../../shared/models/avatars/avatar.model' | 20 | import { Avatar } from '../../../shared/models/avatars/avatar.model' |
21 | import { activityPubContextify } from '../../helpers/activitypub' | 21 | import { activityPubContextify } from '../../helpers/activitypub' |
22 | import { | 22 | import { |
@@ -335,7 +335,7 @@ export class ActorModel extends Model<ActorModel> { | |||
335 | const query = { | 335 | const query = { |
336 | where: { | 336 | where: { |
337 | followersUrl: { | 337 | followersUrl: { |
338 | [ Op.in ]: followersUrls | 338 | [Op.in]: followersUrls |
339 | } | 339 | } |
340 | }, | 340 | }, |
341 | transaction | 341 | transaction |
@@ -362,7 +362,7 @@ export class ActorModel extends Model<ActorModel> { | |||
362 | .findOne(query) | 362 | .findOne(query) |
363 | .then(actor => { | 363 | .then(actor => { |
364 | if (preferredUsername === SERVER_ACTOR_NAME) { | 364 | if (preferredUsername === SERVER_ACTOR_NAME) { |
365 | ActorModel.localNameCache[ preferredUsername ] = actor | 365 | ActorModel.localNameCache[preferredUsername] = actor |
366 | } | 366 | } |
367 | 367 | ||
368 | return actor | 368 | return actor |
@@ -388,7 +388,7 @@ export class ActorModel extends Model<ActorModel> { | |||
388 | .findOne(query) | 388 | .findOne(query) |
389 | .then(actor => { | 389 | .then(actor => { |
390 | if (preferredUsername === SERVER_ACTOR_NAME) { | 390 | if (preferredUsername === SERVER_ACTOR_NAME) { |
391 | ActorModel.localUrlCache[ preferredUsername ] = actor | 391 | ActorModel.localUrlCache[preferredUsername] = actor |
392 | } | 392 | } |
393 | 393 | ||
394 | return actor | 394 | return actor |
@@ -500,9 +500,11 @@ export class ActorModel extends Model<ActorModel> { | |||
500 | } | 500 | } |
501 | 501 | ||
502 | toActivityPubObject (this: MActorAP, name: string) { | 502 | toActivityPubObject (this: MActorAP, name: string) { |
503 | let icon = undefined | 503 | let icon: ActivityIconObject |
504 | |||
504 | if (this.avatarId) { | 505 | if (this.avatarId) { |
505 | const extension = extname(this.Avatar.filename) | 506 | const extension = extname(this.Avatar.filename) |
507 | |||
506 | icon = { | 508 | icon = { |
507 | type: 'Image', | 509 | type: 'Image', |
508 | mediaType: extension === '.png' ? 'image/png' : 'image/jpeg', | 510 | mediaType: extension === '.png' ? 'image/png' : 'image/jpeg', |