hippofish/packages/backend/src/services/add-note-to-antenna.ts

28 lines
776 B
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import type { Antenna } from "@/models/entities/antenna.js";
import type { Note } from "@/models/entities/note.js";
import { genId } from "@/misc/gen-id.js";
import { redisClient } from "@/db/redis.js";
import { publishAntennaStream } from "@/services/stream.js";
2023-01-13 05:40:33 +01:00
import type { User } from "@/models/entities/user.js";
export async function addNoteToAntenna(
antenna: Antenna,
note: Note,
noteUser: { id: User["id"] },
) {
// 通知しない設定になっているか、自分自身の投稿なら既読にする
2023-01-13 05:40:33 +01:00
const read = !antenna.notify || antenna.userId === noteUser.id;
redisClient.xadd(
`antennaTimeline:${antenna.id}`,
"MAXLEN",
"~",
"200",
`${genId(note.createdAt)}-*`,
"note",
note.id,
);
2023-01-13 05:40:33 +01:00
publishAntennaStream(antenna.id, "note", note);
}