undo announce

This commit is contained in:
Namekuji 2023-08-27 01:40:29 -04:00
parent c9aa7646d2
commit 2a3e45456e
No known key found for this signature in database
GPG key ID: 1D62332C07FBA532

View file

@ -3,6 +3,13 @@ import type { CacheableRemoteUser } from "@/models/entities/user.js";
import type { IAnnounce } from "../../type.js";
import { getApId } from "../../type.js";
import deleteNote from "@/services/note/delete.js";
import {
type ScyllaNote,
scyllaClient,
prepared,
parseScyllaNote,
} from "@/db/scylla.js";
import type { Note } from "@/models/entities/note.js";
export const undoAnnounce = async (
actor: CacheableRemoteUser,
@ -10,10 +17,26 @@ export const undoAnnounce = async (
): Promise<string> => {
const uri = getApId(activity);
const note = await Notes.findOneBy({
let note: Note | ScyllaNote | null = null;
if (scyllaClient) {
const result = await scyllaClient.execute(
prepared.note.select.byUri,
[uri],
{ prepare: true },
);
if (result.rowLength > 0) {
const candidate = parseScyllaNote(result.first());
if (candidate.userId === actor.id) {
note = candidate;
}
}
} else {
note = await Notes.findOneBy({
uri,
userId: actor.id,
});
}
if (!note) return "skip: no such Announce";