[mastodon-client] Prevent duplicate reblogs

This commit is contained in:
Laura Hausmann 2023-10-07 17:34:22 +02:00
parent 47d9278eae
commit 98fe5b3a54
Signed by: zotan
GPG key ID: D044E84C5BE01605

View file

@ -29,6 +29,7 @@ import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js"
import { Cache } from "@/misc/cache.js";
import AsyncLock from "async-lock";
import { IdentifiableError } from "@/misc/identifiable-error.js";
import { IsNull } from "typeorm";
export class NoteHelpers {
public static postIdempotencyCache = new Cache<{ status?: MastodonEntity.Status }>('postIdempotencyCache', 60 * 60);
@ -59,6 +60,12 @@ export class NoteHelpers {
}
public static async reblogNote(note: Note, user: ILocalUser): Promise<Note> {
const existingRenote = await Notes.findOneBy({
userId: user.id,
renoteId: note.id,
text: IsNull(),
});
if (existingRenote) return existingRenote;
const data = {
createdAt: new Date(),
files: [],