From 47581df0737ebcc058a5863143c752f9112a4424 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 23 Oct 2019 11:33:53 +0200 Subject: Fix federation with some actors That don't have a shared inbox, or a URL --- server/models/activitypub/actor-follow.ts | 8 ++++---- server/models/activitypub/actor.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'server/models/activitypub') diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 8498692f0..fb3c4ef9d 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts @@ -574,8 +574,8 @@ export class ActorFollowModel extends Model { } const selections: string[] = [] - if (distinct === true) selections.push('DISTINCT("Follows"."' + columnUrl + '") AS "url"') - else selections.push('"Follows"."' + columnUrl + '" AS "url"') + if (distinct === true) selections.push('DISTINCT("Follows"."' + columnUrl + '") AS "selectionUrl"') + else selections.push('"Follows"."' + columnUrl + '" AS "selectionUrl"') selections.push('COUNT(*) AS "total"') @@ -585,7 +585,7 @@ export class ActorFollowModel extends Model { let query = 'SELECT ' + selection + ' FROM "actor" ' + 'INNER JOIN "actorFollow" ON "actorFollow"."' + firstJoin + '" = "actor"."id" ' + 'INNER JOIN "actor" AS "Follows" ON "actorFollow"."' + secondJoin + '" = "Follows"."id" ' + - 'WHERE "actor"."id" = ANY ($actorIds) AND "actorFollow"."state" = \'accepted\' ' + 'WHERE "actor"."id" = ANY ($actorIds) AND "actorFollow"."state" = \'accepted\' AND "selectionUrl" IS NOT NULL ' if (count !== undefined) query += 'LIMIT ' + count if (start !== undefined) query += ' OFFSET ' + start @@ -599,7 +599,7 @@ export class ActorFollowModel extends Model { } const [ followers, [ dataTotal ] ] = await Promise.all(tasks) - const urls: string[] = followers.map(f => f.url) + const urls: string[] = followers.map(f => f.selectionUrl) return { data: urls, diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 535ebd792..42a24b583 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -44,7 +44,8 @@ import { MActorFull, MActorHost, MActorServer, - MActorSummaryFormattable + MActorSummaryFormattable, + MActorWithInboxes } from '../../typings/models' import * as Bluebird from 'bluebird' @@ -179,8 +180,8 @@ export class ActorModel extends Model { @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) outboxUrl: string - @AllowNull(false) - @Is('ActorSharedInboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'shared inbox url')) + @AllowNull(true) + @Is('ActorSharedInboxUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'shared inbox url', true)) @Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max)) sharedInboxUrl: string @@ -402,6 +403,10 @@ export class ActorModel extends Model { }) } + getSharedInbox (this: MActorWithInboxes) { + return this.sharedInboxUrl || this.inboxUrl + } + toFormattedSummaryJSON (this: MActorSummaryFormattable) { let avatar: Avatar = null if (this.Avatar) { -- cgit v1.2.3