From 3800eb8980eee8e446038355b8faf29554699825 Mon Sep 17 00:00:00 2001 From: April John Date: Fri, 5 May 2023 15:16:10 +0200 Subject: [PATCH] Feat: new internal post visibility "hidden" --- .../migration/1682891891317-AddHiddenPosts.js | 13 +++++++++++++ packages/backend/src/models/entities/note.ts | 1 + .../backend/src/queue/processors/db/import-posts.ts | 4 ++-- .../backend/src/remote/activitypub/models/note.ts | 4 ++-- .../server/api/endpoints/notes/global-timeline.ts | 1 + .../server/api/endpoints/notes/hybrid-timeline.ts | 2 ++ .../server/api/endpoints/notes/local-timeline.ts | 1 + .../api/endpoints/notes/recommended-timeline.ts | 1 + .../src/server/api/endpoints/notes/timeline.ts | 2 ++ .../backend/src/services/note/reaction/create.ts | 2 +- packages/backend/src/types.ts | 1 + 11 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 packages/backend/migration/1682891891317-AddHiddenPosts.js diff --git a/packages/backend/migration/1682891891317-AddHiddenPosts.js b/packages/backend/migration/1682891891317-AddHiddenPosts.js new file mode 100644 index 0000000000..9fbb553b3b --- /dev/null +++ b/packages/backend/migration/1682891891317-AddHiddenPosts.js @@ -0,0 +1,13 @@ +export class AddHiddenPosts1682891891317 { + name = "AddHiddenPosts1682891891317"; + + async up(queryRunner) { + await queryRunner.query( + `ALTER TYPE note_visibility_enum ADD VALUE IF NOT EXISTS 'hidden'`, + ); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TYPE note_visibility_enum REMOVE VALUE IF EXISTS 'hidden'`); + } +} diff --git a/packages/backend/src/models/entities/note.ts b/packages/backend/src/models/entities/note.ts index 10449bb6d6..f4e76c1dba 100644 --- a/packages/backend/src/models/entities/note.ts +++ b/packages/backend/src/models/entities/note.ts @@ -111,6 +111,7 @@ export class Note { /** * public ... 公開 * home ... ホームタイムライン(ユーザーページのタイムライン含む)のみに流す + * hidden ... only visible on profile (doesnt federate, like local only, but can be fetched via AP like home) <- for now only used for post imports * followers ... フォロワーのみ * specified ... visibleUserIds で指定したユーザーのみ */ diff --git a/packages/backend/src/queue/processors/db/import-posts.ts b/packages/backend/src/queue/processors/db/import-posts.ts index 20ef3a518d..a0a916b41e 100644 --- a/packages/backend/src/queue/processors/db/import-posts.ts +++ b/packages/backend/src/queue/processors/db/import-posts.ts @@ -65,7 +65,7 @@ export async function importPosts( renote: null, cw: cw, localOnly, - visibility: "public", + visibility: "hidden", visibleUsers: [], channel: null, apMentions: new Array(0), @@ -109,7 +109,7 @@ export async function importPosts( renote: null, cw: post.sensitive, localOnly: false, - visibility: "public", + visibility: "hidden", visibleUsers: [], channel: null, apMentions: new Array(0), diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 7b41de6700..719feb56f6 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -686,7 +686,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { multiple: poll?.multiple, votes: poll?.votes, expiresAt: poll?.expiresAt, - noteVisibility: note.visibility, + noteVisibility: note.visibility === "hidden" ? "home" : note.visibility, userId: actor.id, userHost: actor.host, }); @@ -704,7 +704,7 @@ export async function updateNote(value: string | IObject, resolver?: Resolver) { multiple: poll?.multiple, votes: poll?.votes, expiresAt: poll?.expiresAt, - noteVisibility: note.visibility, + noteVisibility: note.visibility === "hidden" ? "home" : note.visibility, }, ); updating = true; diff --git a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts index 93fbda8c76..78a1932830 100644 --- a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts @@ -98,6 +98,7 @@ export default define(meta, paramDef, async (ps, user) => { if (ps.withFiles) { query.andWhere("note.fileIds != '{}'"); } + query.andWhere("note.visibility != 'hidden'"); //#endregion process.nextTick(() => { diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index 06f9edf453..508b268cc0 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -156,6 +156,8 @@ export default define(meta, paramDef, async (ps, user) => { if (ps.withFiles) { query.andWhere("note.fileIds != '{}'"); } + + query.andWhere("note.visibility != 'hidden'"); //#endregion process.nextTick(() => { diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts index ec3d4bde09..797c6d77cb 100644 --- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts @@ -128,6 +128,7 @@ export default define(meta, paramDef, async (ps, user) => { ); } } + query.andWhere("note.visibility != 'hidden'"); //#endregion process.nextTick(() => { diff --git a/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts b/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts index 27b72f4a3f..321ab4ad7d 100644 --- a/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/recommended-timeline.ts @@ -131,6 +131,7 @@ export default define(meta, paramDef, async (ps, user) => { ); } } + query.andWhere("note.visibility != 'hidden'"); //#endregion process.nextTick(() => { diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index 436b50e9f4..62996efdde 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -152,6 +152,8 @@ export default define(meta, paramDef, async (ps, user) => { if (ps.withFiles) { query.andWhere("note.fileIds != '{}'"); } + + query.andWhere("note.visibility != 'hidden'"); //#endregion process.nextTick(() => { diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index 277393eb41..4b9b20ec30 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -144,7 +144,7 @@ export default async ( }); //#region deliver - if (Users.isLocalUser(user) && !note.localOnly) { + if (Users.isLocalUser(user) && !note.localOnly && note.visibility !== "hidden") { const content = renderActivity(await renderLike(record, note)); const dm = new DeliverManager(user, content); if (note.userHost !== null) { diff --git a/packages/backend/src/types.ts b/packages/backend/src/types.ts index 9e53440a17..2ba6da2f7d 100644 --- a/packages/backend/src/types.ts +++ b/packages/backend/src/types.ts @@ -18,6 +18,7 @@ export const noteVisibilities = [ "home", "followers", "specified", + "hidden", ] as const; export const mutedNoteReasons = ["word", "manual", "spam", "other"] as const;