From 3e1b112f92922bb73ede14a511789743445fe981 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 10 Jul 2023 18:50:07 +0200 Subject: [PATCH 1/4] Revert "Revert "[mastodon-client] send actual default post privacy instead of fallback value"" This reverts commit a441cc6067c487c563bf673be261a179d96e0533. --- .../api/endpoints/i/registry/get-unsecure.ts | 2 +- .../server/api/mastodon/endpoints/account.ts | 2 +- packages/megalodon/src/misskey.ts | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/i/registry/get-unsecure.ts b/packages/backend/src/server/api/endpoints/i/registry/get-unsecure.ts index f98c6c929f..a9bcf69351 100644 --- a/packages/backend/src/server/api/endpoints/i/registry/get-unsecure.ts +++ b/packages/backend/src/server/api/endpoints/i/registry/get-unsecure.ts @@ -33,7 +33,7 @@ export const paramDef = { } as const; export default define(meta, paramDef, async (ps, user) => { - if (ps.key !== "reactions") return; + if (ps.key !== "reactions" && ps.key !== "defaultNoteVisibility") return; const query = RegistryItems.createQueryBuilder("item") .where("item.domain IS NULL") .andWhere("item.userId = :userId", { userId: user.id }) diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts index 3fb1c9cbe4..5d0abdedd6 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/account.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts @@ -48,7 +48,7 @@ export function apiAccountMastodon(router: Router): void { acct.source = { note: acct.note, fields: acct.fields, - privacy: "public", + privacy: await client.getDefaultPostPrivacy(), sensitive: false, language: "", }; diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index de62b98509..b4a9c6adb9 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1539,6 +1539,23 @@ export default class Misskey implements MegalodonInterface { .then(res => res.data[0] ?? '⭐'); } + private async getDefaultPostPrivacy(): Promise { + // NOTE: get-unsecure is calckey's extension. + // Misskey doesn't have this endpoint and regular `/i/registry/get` won't work + // unless you have a 'nativeToken', which is reserved for the frontend webapp. + + return this.client + .post('/api/i/registry/get-unsecure', { + key: 'defaultNoteVisibility', + scope: ['client', 'base'], + }) + .then(res => { + if (!res.data || (res.data != 'public' && res.data != 'home' && res.data != 'followers' && res.data != 'specified')) + return 'public'; + return this.converter.visibility(res.data); + }); + } + public async unfavouriteStatus(id: string): Promise> { // NOTE: Misskey allows only one reaction per status, so we don't need to care what that emoji was. return this.deleteEmojiReaction(id, ''); From dc0194a842462bfe73dcb95b1fd3a947b8e657b1 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 10 Jul 2023 18:50:12 +0200 Subject: [PATCH 2/4] Revert "Revert "[mastodon-client] send proper user preferences"" This reverts commit dfd9bd5dd106f27fc6dde09d80d40c07116ae517. --- packages/megalodon/src/misskey.ts | 24 +++++--------------- packages/megalodon/src/misskey/api_client.ts | 4 ++-- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index b4a9c6adb9..026b8e9b7a 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1079,23 +1079,11 @@ export default class Misskey implements MegalodonInterface { // accounts/preferences // ====================================== public async getPreferences(): Promise> { - return this.client.post('/api/i').then(res => { - /* - return this.client.post('/api/i/registry/get-all', { - scope: ['client', 'base'], - }).then(ga => { - return Object.assign(res, { - data: this.converter.userPreferences(res.data, ga.data) - }) - }) - */ - - // TODO: - // FIXME: get this from api - return Object.assign(res, { - data: this.converter.userPreferences(res.data, {defaultNoteVisibility: "followers", tutorial: -1}) - }) - }) + return this.client.post('/api/i').then(async res => { + return Object.assign(res, { + data: this.converter.userPreferences(res.data, await this.getDefaultPostPrivacy()) + }) + }) } // ====================================== @@ -1539,7 +1527,7 @@ export default class Misskey implements MegalodonInterface { .then(res => res.data[0] ?? '⭐'); } - private async getDefaultPostPrivacy(): Promise { + private async getDefaultPostPrivacy(): Promise<'public' | 'unlisted' | 'private' | 'direct'> { // NOTE: get-unsecure is calckey's extension. // Misskey doesn't have this endpoint and regular `/i/registry/get` won't work // unless you have a 'nativeToken', which is reserved for the frontend webapp. diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index aabb1f3ee5..f80d5a4421 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -175,13 +175,13 @@ namespace MisskeyAPI { } } - userPreferences = (u: MisskeyAPI.Entity.UserDetailMe, g: MisskeyAPI.Entity.GetAll): MegalodonEntity.Preferences => { + userPreferences = (u: MisskeyAPI.Entity.UserDetailMe, v: 'public' | 'unlisted' | 'private' | 'direct'): MegalodonEntity.Preferences => { return { "reading:expand:media": "default", "reading:expand:spoilers": false, "posting:default:language": u.lang, "posting:default:sensitive": u.alwaysMarkNsfw, - "posting:default:visibility": this.visibility(g.defaultNoteVisibility) + "posting:default:visibility": v } } From 5c3a3ac02b53e8d12480b18726ce0d544a1ae1f3 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 10 Jul 2023 18:05:34 +0200 Subject: [PATCH 3/4] [mastodon-client] userDetail: fallback to username if displayname is null --- packages/megalodon/src/misskey/api_client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index f80d5a4421..1c198ecc95 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -156,7 +156,7 @@ namespace MisskeyAPI { id: u.id, username: u.username, acct: acct, - display_name: u.name, + display_name: u.name || u.username, locked: u.isLocked, created_at: u.createdAt, followers_count: u.followersCount, From 5bb7707649e691a5f38890499e1dfc7cdc14a5a8 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 10 Jul 2023 18:45:01 +0200 Subject: [PATCH 4/4] [mastodon-client] fix getDefaultPostPrivacy --- packages/megalodon/src/misskey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index 026b8e9b7a..ca418439e9 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1541,7 +1541,7 @@ export default class Misskey implements MegalodonInterface { if (!res.data || (res.data != 'public' && res.data != 'home' && res.data != 'followers' && res.data != 'specified')) return 'public'; return this.converter.visibility(res.data); - }); + }).catch(_ => 'public') } public async unfavouriteStatus(id: string): Promise> {