From 9022ab9f2a5872c02f6d20f1d96ebc1bee6dd43f Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 10 Oct 2022 17:36:13 +0200 Subject: [PATCH 01/29] backend: ignore detail parameter on meta endpoint Also allow meta endpoint to be fetched via GET. Changelog: Removed --- .../backend/src/server/api/endpoints/meta.ts | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 0d11c5a92..cbf74ef04 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -10,6 +10,9 @@ export const meta = { requireCredential: false, + allowGet: true, + cacheSec: 60, + res: { type: 'object', optional: false, nullable: false, @@ -253,7 +256,12 @@ export const meta = { export const paramDef = { type: 'object', properties: { - detail: { type: 'boolean', default: true }, + detail: { + deprecated: true, + description: 'This parameter is ignored. You will always get all details (as if it was `true`).', + type: 'boolean', + default: true, + }, }, required: [], } as const; @@ -276,7 +284,7 @@ export default define(meta, paramDef, async (ps, me) => { }, }); - const response: any = { + return { maintainerName: instance.maintainerName, maintainerEmail: instance.maintainerEmail, @@ -317,21 +325,16 @@ export default define(meta, paramDef, async (ps, me) => { translatorAvailable: instance.deeplAuthKey != null, - ...(ps.detail ? { - pinnedPages: instance.pinnedPages, - pinnedClipId: instance.pinnedClipId, - cacheRemoteFiles: instance.cacheRemoteFiles, - requireSetup: (await Users.countBy({ - host: IsNull(), - })) === 0, - } : {}), - }; + pinnedPages: instance.pinnedPages, + pinnedClipId: instance.pinnedClipId, + cacheRemoteFiles: instance.cacheRemoteFiles, + requireSetup: (await Users.countBy({ + host: IsNull(), + })) === 0, - if (ps.detail) { - const proxyAccount = instance.proxyAccountId ? await Users.pack(instance.proxyAccountId).catch(() => null) : null; + proxyAccountName: instance.proxyAccountId ? (await Users.pack(instance.proxyAccountId).catch(() => null))?.username : null, - response.proxyAccountName = proxyAccount ? proxyAccount.username : null; - response.features = { + features: { registration: !instance.disableRegistration, localTimeLine: !instance.disableLocalTimeline, globalTimeLine: !instance.disableGlobalTimeline, @@ -345,8 +348,6 @@ export default define(meta, paramDef, async (ps, me) => { discord: instance.enableDiscordIntegration, serviceWorker: instance.enableServiceWorker, miauth: true, - }; - } - - return response; + }, + }; }); From 4f9504d135546e8c1dc11f5c56966866c48dd7f2 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 10 Oct 2022 17:36:50 +0200 Subject: [PATCH 02/29] client: fetch meta via GET --- packages/client/src/instance.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/client/src/instance.ts b/packages/client/src/instance.ts index b4bc07578..71a293005 100644 --- a/packages/client/src/instance.ts +++ b/packages/client/src/instance.ts @@ -1,6 +1,6 @@ import { computed, reactive } from 'vue'; import * as foundkey from 'foundkey-js'; -import { api } from '@/os'; +import { apiGet } from '@/os'; // TODO: 他のタブと永続化されたstateを同期 @@ -13,13 +13,7 @@ export const instance: foundkey.entities.InstanceMetadata = reactive(instanceDat }); export async function fetchInstance(): Promise { - const meta = await api('meta', { - detail: false, - }); - - for (const [k, v] of Object.entries(meta)) { - instance[k] = v; - } + Object.assign(instance, await apiGet('meta')); localStorage.setItem('instance', JSON.stringify(instance)); } From 8920eeb86af5c29e576b6a10784696edb02731f7 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 11 Oct 2022 00:27:43 +0200 Subject: [PATCH 03/29] ActivityPub: allow all known shared inboxes to be addressed This is oriented on this paragraph from the AP spec: > Additionally, if an object is addressed to the Public special collection, > a server MAY deliver that object to all known sharedInbox endpoints > on the network. --- .../src/remote/activitypub/deliver-manager.ts | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/remote/activitypub/deliver-manager.ts b/packages/backend/src/remote/activitypub/deliver-manager.ts index e0af5b8f9..5fd0d5f60 100644 --- a/packages/backend/src/remote/activitypub/deliver-manager.ts +++ b/packages/backend/src/remote/activitypub/deliver-manager.ts @@ -8,6 +8,10 @@ interface IRecipe { type: string; } +interface IEveryoneRecipe extends IRecipe { + type: 'Everyone'; +} + interface IFollowersRecipe extends IRecipe { type: 'Followers'; } @@ -17,6 +21,9 @@ interface IDirectRecipe extends IRecipe { to: IRemoteUser; } +const isEveryone = (recipe: any): recipe is IEveryoneRecipe => + recipe.type === 'Everyone'; + const isFollowers = (recipe: any): recipe is IFollowersRecipe => recipe.type === 'Followers'; @@ -63,6 +70,13 @@ export default class DeliverManager { this.addRecipe(recipe); } + /** + * Add recipe to send this activity to all known sharedInboxes + */ + public addEveryone() { + this.addRecipe({ type: 'Everyone' } as IEveryoneRecipe); + } + /** * Add recipe * @param recipe Recipe @@ -82,9 +96,26 @@ export default class DeliverManager { /* build inbox list - Process follower recipes first to avoid duplication when processing - direct recipes later. + Processing order matters to avoid duplication. */ + + if (this.recipes.some(r => isEveryone(r))) { + // deliver to all of known network + const sharedInboxes = await Users.createQueryBuilder('users') + .select('users.sharedInbox', 'sharedInbox') + // can't deliver to unknown shared inbox + .where('users.sharedInbox IS NOT NULL') + // don't deliver to ourselves + .andWhere('users.host IS NOT NULL') + // so we don't have to make our inboxes Set work as hard + .groupBy('users.sharedInbox') + .getRawMany(); + + for (const inbox of sharedInboxes) { + inboxes.add(inbox.sharedInbox); + } + } + if (this.recipes.some(r => isFollowers(r))) { // followers deliver // TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう From c65559872b7509e07efea9ebcc9e94dfb61cb08e Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 11 Oct 2022 01:51:17 -0400 Subject: [PATCH 04/29] backend: add missing return type annotation in array.ts --- packages/backend/src/prelude/array.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/prelude/array.ts b/packages/backend/src/prelude/array.ts index 0b2830cb7..4e2088e72 100644 --- a/packages/backend/src/prelude/array.ts +++ b/packages/backend/src/prelude/array.ts @@ -84,7 +84,7 @@ export function groupOn(f: (x: T) => S, xs: T[]): T[][] { return groupBy((a, b) => f(a) === f(b), xs); } -export function groupByX(collections: T[], keySelector: (x: T) => string) { +export function groupByX(collections: T[], keySelector: (x: T) => string): Record { return collections.reduce((obj: Record, item: T) => { const key = keySelector(item); if (!Object.prototype.hasOwnProperty.call(obj, key)) { From 683b0cfa8270cb972bc0fede7c4106b49e921a63 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Tue, 11 Oct 2022 01:53:34 -0400 Subject: [PATCH 05/29] backend: remove unused prelude modules Much of these modules are no longer used in the backend. They seem to be from before the code was organized in packages. --- packages/backend/src/prelude/math.ts | 3 --- packages/backend/src/prelude/maybe.ts | 20 -------------------- packages/backend/src/prelude/string.ts | 15 --------------- packages/backend/test/prelude/maybe.ts | 18 ------------------ 4 files changed, 56 deletions(-) delete mode 100644 packages/backend/src/prelude/math.ts delete mode 100644 packages/backend/src/prelude/maybe.ts delete mode 100644 packages/backend/src/prelude/string.ts delete mode 100644 packages/backend/test/prelude/maybe.ts diff --git a/packages/backend/src/prelude/math.ts b/packages/backend/src/prelude/math.ts deleted file mode 100644 index 07b94bec3..000000000 --- a/packages/backend/src/prelude/math.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function gcd(a: number, b: number): number { - return b === 0 ? a : gcd(b, a % b); -} diff --git a/packages/backend/src/prelude/maybe.ts b/packages/backend/src/prelude/maybe.ts deleted file mode 100644 index df7c4ed52..000000000 --- a/packages/backend/src/prelude/maybe.ts +++ /dev/null @@ -1,20 +0,0 @@ -export interface IMaybe { - isJust(): this is IJust; -} - -export interface IJust extends IMaybe { - get(): T; -} - -export function just(value: T): IJust { - return { - isJust: () => true, - get: () => value, - }; -} - -export function nothing(): IMaybe { - return { - isJust: () => false, - }; -} diff --git a/packages/backend/src/prelude/string.ts b/packages/backend/src/prelude/string.ts deleted file mode 100644 index b907e0a2e..000000000 --- a/packages/backend/src/prelude/string.ts +++ /dev/null @@ -1,15 +0,0 @@ -export function concat(xs: string[]): string { - return xs.join(''); -} - -export function capitalize(s: string): string { - return toUpperCase(s.charAt(0)) + toLowerCase(s.slice(1)); -} - -export function toUpperCase(s: string): string { - return s.toUpperCase(); -} - -export function toLowerCase(s: string): string { - return s.toLowerCase(); -} diff --git a/packages/backend/test/prelude/maybe.ts b/packages/backend/test/prelude/maybe.ts deleted file mode 100644 index 0f4b00065..000000000 --- a/packages/backend/test/prelude/maybe.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as assert from 'assert'; -import { just, nothing } from '../../src/prelude/maybe.js'; - -describe('just', () => { - it('has a value', () => { - assert.deepStrictEqual(just(3).isJust(), true); - }); - - it('has the inverse called get', () => { - assert.deepStrictEqual(just(3).get(), 3); - }); -}); - -describe('nothing', () => { - it('has no value', () => { - assert.deepStrictEqual(nothing().isJust(), false); - }); -}); From 2c411d59f4f54c70990bbba7711b30ed612e6574 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 11 Oct 2022 10:46:25 +0200 Subject: [PATCH 06/29] client: use cached instance information --- packages/client/src/components/featured-photos.vue | 12 ++---------- packages/client/src/pages/_error_.vue | 11 ++++------- packages/client/src/pages/welcome.entrance.a.vue | 12 ++++-------- packages/client/src/pages/welcome.vue | 11 ++--------- packages/client/src/ui/visitor/b.vue | 5 ----- 5 files changed, 12 insertions(+), 39 deletions(-) diff --git a/packages/client/src/components/featured-photos.vue b/packages/client/src/components/featured-photos.vue index ac96c1a4d..d75da9684 100644 --- a/packages/client/src/components/featured-photos.vue +++ b/packages/client/src/components/featured-photos.vue @@ -1,17 +1,9 @@