diff options
Diffstat (limited to 'server/models/activitypub')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 7 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 47 |
2 files changed, 42 insertions, 12 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index ce6a4e267..4c5f37620 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -248,13 +248,6 @@ export class ActorFollowModel extends Model { | |||
248 | } | 248 | } |
249 | 249 | ||
250 | return ActorFollowModel.findOne(query) | 250 | return ActorFollowModel.findOne(query) |
251 | .then(result => { | ||
252 | if (result?.ActorFollowing.VideoChannel) { | ||
253 | result.ActorFollowing.VideoChannel.Actor = result.ActorFollowing | ||
254 | } | ||
255 | |||
256 | return result | ||
257 | }) | ||
258 | } | 251 | } |
259 | 252 | ||
260 | static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Promise<MActorFollowFollowingHost[]> { | 253 | static listSubscribedIn (actorId: number, targets: { name: string, host?: string }[]): Promise<MActorFollowFollowingHost[]> { |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 09d96b24d..6595f11e2 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -29,11 +29,19 @@ import { | |||
29 | isActorPublicKeyValid | 29 | isActorPublicKeyValid |
30 | } from '../../helpers/custom-validators/activitypub/actor' | 30 | } from '../../helpers/custom-validators/activitypub/actor' |
31 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 31 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
32 | import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' | 32 | import { |
33 | ACTIVITY_PUB, | ||
34 | ACTIVITY_PUB_ACTOR_TYPES, | ||
35 | CONSTRAINTS_FIELDS, | ||
36 | MIMETYPES, | ||
37 | SERVER_ACTOR_NAME, | ||
38 | WEBSERVER | ||
39 | } from '../../initializers/constants' | ||
33 | import { | 40 | import { |
34 | MActor, | 41 | MActor, |
35 | MActorAccountChannelId, | 42 | MActorAccountChannelId, |
36 | MActorAP, | 43 | MActorAPAccount, |
44 | MActorAPChannel, | ||
37 | MActorFormattable, | 45 | MActorFormattable, |
38 | MActorFull, | 46 | MActorFull, |
39 | MActorHost, | 47 | MActorHost, |
@@ -104,6 +112,11 @@ export const unusedActorAttributesForAPI = [ | |||
104 | model: ActorImageModel, | 112 | model: ActorImageModel, |
105 | as: 'Avatar', | 113 | as: 'Avatar', |
106 | required: false | 114 | required: false |
115 | }, | ||
116 | { | ||
117 | model: ActorImageModel, | ||
118 | as: 'Banner', | ||
119 | required: false | ||
107 | } | 120 | } |
108 | ] | 121 | ] |
109 | } | 122 | } |
@@ -531,29 +544,46 @@ export class ActorModel extends Model { | |||
531 | toFormattedJSON (this: MActorFormattable) { | 544 | toFormattedJSON (this: MActorFormattable) { |
532 | const base = this.toFormattedSummaryJSON() | 545 | const base = this.toFormattedSummaryJSON() |
533 | 546 | ||
547 | let banner: ActorImage = null | ||
548 | if (this.bannerId) { | ||
549 | banner = this.Banner.toFormattedJSON() | ||
550 | } | ||
551 | |||
534 | return Object.assign(base, { | 552 | return Object.assign(base, { |
535 | id: this.id, | 553 | id: this.id, |
536 | hostRedundancyAllowed: this.getRedundancyAllowed(), | 554 | hostRedundancyAllowed: this.getRedundancyAllowed(), |
537 | followingCount: this.followingCount, | 555 | followingCount: this.followingCount, |
538 | followersCount: this.followersCount, | 556 | followersCount: this.followersCount, |
557 | banner, | ||
539 | createdAt: this.createdAt, | 558 | createdAt: this.createdAt, |
540 | updatedAt: this.updatedAt | 559 | updatedAt: this.updatedAt |
541 | }) | 560 | }) |
542 | } | 561 | } |
543 | 562 | ||
544 | toActivityPubObject (this: MActorAP, name: string) { | 563 | toActivityPubObject (this: MActorAPChannel | MActorAPAccount, name: string) { |
545 | let icon: ActivityIconObject | 564 | let icon: ActivityIconObject |
565 | let image: ActivityIconObject | ||
546 | 566 | ||
547 | if (this.avatarId) { | 567 | if (this.avatarId) { |
548 | const extension = extname(this.Avatar.filename) | 568 | const extension = extname(this.Avatar.filename) |
549 | 569 | ||
550 | icon = { | 570 | icon = { |
551 | type: 'Image', | 571 | type: 'Image', |
552 | mediaType: extension === '.png' ? 'image/png' : 'image/jpeg', | 572 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], |
553 | url: this.getAvatarUrl() | 573 | url: this.getAvatarUrl() |
554 | } | 574 | } |
555 | } | 575 | } |
556 | 576 | ||
577 | if (this.bannerId) { | ||
578 | const extension = extname((this as MActorAPChannel).Banner.filename) | ||
579 | |||
580 | image = { | ||
581 | type: 'Image', | ||
582 | mediaType: MIMETYPES.IMAGE.EXT_MIMETYPE[extension], | ||
583 | url: this.getBannerUrl() | ||
584 | } | ||
585 | } | ||
586 | |||
557 | const json = { | 587 | const json = { |
558 | type: this.type, | 588 | type: this.type, |
559 | id: this.url, | 589 | id: this.url, |
@@ -573,7 +603,8 @@ export class ActorModel extends Model { | |||
573 | owner: this.url, | 603 | owner: this.url, |
574 | publicKeyPem: this.publicKey | 604 | publicKeyPem: this.publicKey |
575 | }, | 605 | }, |
576 | icon | 606 | icon, |
607 | image | ||
577 | } | 608 | } |
578 | 609 | ||
579 | return activityPubContextify(json) | 610 | return activityPubContextify(json) |
@@ -643,6 +674,12 @@ export class ActorModel extends Model { | |||
643 | return WEBSERVER.URL + this.Avatar.getStaticPath() | 674 | return WEBSERVER.URL + this.Avatar.getStaticPath() |
644 | } | 675 | } |
645 | 676 | ||
677 | getBannerUrl () { | ||
678 | if (!this.bannerId) return undefined | ||
679 | |||
680 | return WEBSERVER.URL + this.Banner.getStaticPath() | ||
681 | } | ||
682 | |||
646 | isOutdated () { | 683 | isOutdated () { |
647 | if (this.isOwned()) return false | 684 | if (this.isOwned()) return false |
648 | 685 | ||