activitypub: correctly handle new notes that were edited

This commit is contained in:
Johann150 2023-07-16 14:30:09 +02:00
parent cc776a6b9b
commit 9b4e976bda
Signed by: Johann150
GPG Key ID: 9EE6577A2A06F8F1
3 changed files with 4 additions and 3 deletions

View File

@ -20,8 +20,6 @@ export async function update(actor: IRemoteUser, note: IObject, resolver: Resolv
try {
// if creating was successful...
const existsNow = await Notes.findOneByOrFail({ uri });
// set the updatedAt timestamp since the note was changed
await Notes.update(existsNow.id, { updatedAt: new Date() });
return 'ok: unknown note created and marked as updated';
} catch (e) {
return `skip: updated note unknown and creating rejected: ${e.message}`;

View File

@ -278,6 +278,7 @@ export async function createNote(value: string | IObject, resolver: Resolver, si
return await post(actor, {
...processedContent,
createdAt: note.published ? new Date(note.published) : null,
updatedAt: note.updated,
reply,
renote: quote,
localOnly: false,
@ -354,7 +355,7 @@ export async function updateNote(value: IPost, actor: User, resolver: Resolver):
// update note content itself
await Notes.update(exists.id, {
updatedAt: new Date(),
updatedAt: value.updated ?? new Date(),
cw: processedContent.cw,
fileIds: processedContent.files.map(file => file.id),

View File

@ -26,6 +26,7 @@ type MinimumUser = {
type Option = {
createdAt?: Date | null;
updatedAt?: Date | null;
name?: string | null;
text?: string | null;
reply?: Note | null;
@ -159,6 +160,7 @@ async function insertNote(user: { id: User['id']; host: User['host']; }, data: O
const insert = new Note({
id: genId(createdAt),
createdAt,
updatedAt: data.updatedAt ?? null,
fileIds: data.files?.map(file => file.id) ?? [],
replyId: data.reply?.id ?? null,
renoteId: data.renote?.id ?? null,