From 678aa493deae131f5dc46b7e8e3c9bbe1c8ac84f Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Fri, 26 Jan 2024 14:21:50 +0800 Subject: [PATCH] fix(edit): add missing `updated` field --- packages/backend/src/core/NoteUpdateService.ts | 7 +++---- packages/backend/src/core/activitypub/ApRendererService.ts | 1 + .../backend/src/core/activitypub/models/ApNoteService.ts | 3 +++ packages/backend/src/core/activitypub/type.ts | 1 + packages/backend/src/server/api/endpoints/notes/update.ts | 7 +++---- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/NoteUpdateService.ts b/packages/backend/src/core/NoteUpdateService.ts index 400bf7f1b..9a24b8ae5 100644 --- a/packages/backend/src/core/NoteUpdateService.ts +++ b/packages/backend/src/core/NoteUpdateService.ts @@ -3,11 +3,10 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Brackets, In } from 'typeorm'; import { Injectable, Inject } from '@nestjs/common'; import * as mfm from 'mfm-js'; import type { MiUser, MiLocalUser, MiRemoteUser } from '@/models/User.js'; -import type { MiNote, IMentionedRemoteUsers } from '@/models/Note.js'; +import type { MiNote } from '@/models/Note.js'; import type { InstancesRepository, NotesRepository, UsersRepository } from '@/models/_.js'; import { RelayService } from '@/core/RelayService.js'; import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; @@ -68,7 +67,7 @@ export class NoteUpdateService { * @param note Note to update * @param ps New note info */ - async update(user: { id: MiUser['id']; uri: MiUser['uri']; host: MiUser['host']; isBot: MiUser['isBot']; }, note: MiNote, ps: Pick, quiet = false, updater?: MiUser) { + async update(user: { id: MiUser['id']; uri: MiUser['uri']; host: MiUser['host']; isBot: MiUser['isBot']; }, note: MiNote, ps: Pick, quiet = false, updater?: MiUser) { const newNote = { ...note, ...ps, // Overwrite updated fields @@ -94,7 +93,7 @@ export class NoteUpdateService { this.searchService.indexNote(newNote); await this.notesRepository.update({ id: note.id }, { - updatedAt: new Date(), + updatedAt: ps.updatedAt, history: [...(note.history || []), { createdAt: (note.updatedAt || this.idService.parse(note.id).date).toISOString(), cw: note.cw, diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 0d5687a11..adc690cd6 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -425,6 +425,7 @@ export class ApRendererService { return { id: `${this.config.url}/notes/${note.id}`, type: 'Note', + updated: note.updatedAt ?? undefined, attributedTo, summary: summary ?? undefined, content: content ?? undefined, diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 2bd744f86..0049b866c 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -363,9 +363,12 @@ export class ApNoteService { text = this.apMfmService.htmlToMfm(note.content, note.tag); } + const updatedAt = note.updated || new Date(); + await this.noteUpdateService.update(actor, originNote, { cw, text, + updatedAt, }, silent); } diff --git a/packages/backend/src/core/activitypub/type.ts b/packages/backend/src/core/activitypub/type.ts index 16812b7a4..a1925251b 100644 --- a/packages/backend/src/core/activitypub/type.ts +++ b/packages/backend/src/core/activitypub/type.ts @@ -127,6 +127,7 @@ export interface IPost extends IObject { _misskey_quote?: string; _misskey_content?: string; quoteUrl?: string; + updated?: Date; } export interface IQuestion extends IObject { diff --git a/packages/backend/src/server/api/endpoints/notes/update.ts b/packages/backend/src/server/api/endpoints/notes/update.ts index 179b69a2f..1e6981294 100644 --- a/packages/backend/src/server/api/endpoints/notes/update.ts +++ b/packages/backend/src/server/api/endpoints/notes/update.ts @@ -5,14 +5,12 @@ import ms from 'ms'; import { Inject, Injectable } from '@nestjs/common'; -import type { UsersRepository, NotesRepository } from '@/models/_.js'; +import type { UsersRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { GetterService } from '@/server/api/GetterService.js'; -import { GlobalEventService } from '@/core/GlobalEventService.js'; import { MAX_NOTE_TEXT_LENGTH } from '@/const.js'; -import { ApiError } from '../../error.js'; -import { IdService } from "@/core/IdService.js"; +import { ApiError } from '@/server/api/error.js'; import { NoteUpdateService } from '@/core/NoteUpdateService.js'; export const meta = { @@ -75,6 +73,7 @@ export default class extends Endpoint { // eslint- await this.noteUpdateService.update(await this.usersRepository.findOneByOrFail({ id: note.userId }), note, { text: ps.text, cw: ps.cw, + updatedAt: new Date(), }, false, me); }); }