forked from mirrors/iceshrimp
[mastodon-client] Prevent duplicate reblogs
This commit is contained in:
parent
47d9278eae
commit
98fe5b3a54
|
@ -29,6 +29,7 @@ import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js"
|
||||||
import { Cache } from "@/misc/cache.js";
|
import { Cache } from "@/misc/cache.js";
|
||||||
import AsyncLock from "async-lock";
|
import AsyncLock from "async-lock";
|
||||||
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
||||||
|
import { IsNull } from "typeorm";
|
||||||
|
|
||||||
export class NoteHelpers {
|
export class NoteHelpers {
|
||||||
public static postIdempotencyCache = new Cache<{ status?: MastodonEntity.Status }>('postIdempotencyCache', 60 * 60);
|
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> {
|
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 = {
|
const data = {
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
files: [],
|
files: [],
|
||||||
|
|
Loading…
Reference in a new issue