From 1d653fdb0b09e48a5f35def9c22db56cdfe4725a Mon Sep 17 00:00:00 2001 From: Johann150 Date: Mon, 31 Oct 2022 12:08:55 +0100 Subject: [PATCH] server: able to store remote thread IDs --- .../1667212446191-remote-thread-ids.js | 17 +++++++++++++++++ .../src/remote/activitypub/renderer/note.ts | 2 +- packages/backend/src/services/note/create.ts | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/backend/migration/1667212446191-remote-thread-ids.js diff --git a/packages/backend/migration/1667212446191-remote-thread-ids.js b/packages/backend/migration/1667212446191-remote-thread-ids.js new file mode 100644 index 000000000..d0dccbb54 --- /dev/null +++ b/packages/backend/migration/1667212446191-remote-thread-ids.js @@ -0,0 +1,17 @@ +import config from '../built/config/index.js'; + +export class remoteThreadIds1667212446191 { + name = 'remoteThreadIds1667212446191'; + + async up(queryRunner) { + await Promise.all([ + queryRunner.query(`UPDATE "note" SET "threadId" = '${config.url}/notes/' + "threadId"`), + queryRunner.query(`UPDATE "note_thread_muting" SET "threadId" = '${config.url}/notes/' + "threadId"`), + ]); + } + + async down() { + // cannot be undone: + // after this migration other instances threadIds may be stored in the database + } +} diff --git a/packages/backend/src/remote/activitypub/renderer/note.ts b/packages/backend/src/remote/activitypub/renderer/note.ts index 31421a12f..572608cc6 100644 --- a/packages/backend/src/remote/activitypub/renderer/note.ts +++ b/packages/backend/src/remote/activitypub/renderer/note.ts @@ -131,7 +131,7 @@ export default async function renderNote(note: Note, dive = true, isTalk = false return { id: `${config.url}/notes/${note.id}`, - context: `${config.url}/notes/${note.threadId}`, + context: note.threadId, type: 'Note', attributedTo, summary, diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 41ef2a053..9cb8e3094 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -509,7 +509,7 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O replyId: data.reply ? data.reply.id : null, renoteId: data.renote ? data.renote.id : null, channelId: data.channel ? data.channel.id : null, - threadId: data.reply?.threadId ?? id, + threadId: data.reply?.threadId ?? `${config.url}/notes/${id}`, name: data.name, text: data.text, hasPoll: data.poll != null,