rudeshark.net/packages/backend/src/services/note/polls/update.ts
ThatOneCalculator 6b00abf05c
refactor: 🎨 rome
2023-01-12 20:40:33 -08:00

24 lines
927 B
TypeScript

import renderUpdate from "@/remote/activitypub/renderer/update.js";
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
import renderNote from "@/remote/activitypub/renderer/note.js";
import { Users, Notes } from "@/models/index.js";
import type { Note } from "@/models/entities/note.js";
import { deliverToFollowers } from "@/remote/activitypub/deliver-manager.js";
import { deliverToRelays } from "../../relay.js";
export async function deliverQuestionUpdate(noteId: Note["id"]) {
const note = await Notes.findOneBy({ id: noteId });
if (note == null) throw new Error("note not found");
const user = await Users.findOneBy({ id: note.userId });
if (user == null) throw new Error("note not found");
if (Users.isLocalUser(user)) {
const content = renderActivity(
renderUpdate(await renderNote(note, false), user),
);
deliverToFollowers(user, content);
deliverToRelays(user, content);
}
}