2023-01-13 05:40:33 +01:00
|
|
|
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";
|
2019-03-07 13:19:32 +01:00
|
|
|
|
2023-01-13 05:40:33 +01:00
|
|
|
export async function deliverQuestionUpdate(noteId: Note["id"]) {
|
2022-03-26 07:34:00 +01:00
|
|
|
const note = await Notes.findOneBy({ id: noteId });
|
2023-01-13 05:40:33 +01:00
|
|
|
if (note == null) throw new Error("note not found");
|
2019-03-07 13:19:32 +01:00
|
|
|
|
2022-03-26 07:34:00 +01:00
|
|
|
const user = await Users.findOneBy({ id: note.userId });
|
2023-01-13 05:40:33 +01:00
|
|
|
if (user == null) throw new Error("note not found");
|
2019-03-07 13:19:32 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
if (Users.isLocalUser(user)) {
|
2023-01-13 05:40:33 +01:00
|
|
|
const content = renderActivity(
|
|
|
|
renderUpdate(await renderNote(note, false), user),
|
|
|
|
);
|
2019-11-09 10:51:54 +01:00
|
|
|
deliverToFollowers(user, content);
|
2020-05-10 11:42:31 +02:00
|
|
|
deliverToRelays(user, content);
|
2019-03-07 13:19:32 +01:00
|
|
|
}
|
|
|
|
}
|