mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 15:48:23 -05:00
Notifications (#2117)
* Initial * Progress * Fix * Progress * Notifications list page * BADGE_MANAGER_ADDED * Mark as seen initial * Split tables * Progress * Fix styles * Push notifs initial * Progress * Rename * Routines * Progress * Add e2e tests * Done? * Try updating actions * Consistency * Dep fix * A couple fixes
This commit is contained in:
39
app/features/chat/ChatSystemMessage.server.ts
Normal file
39
app/features/chat/ChatSystemMessage.server.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { nanoid } from "nanoid";
|
||||
import { SKALOP_TOKEN_HEADER_NAME } from "~/constants";
|
||||
import invariant from "~/utils/invariant";
|
||||
import type { ChatMessage } from "./chat-types";
|
||||
|
||||
type PartialChatMessage = Pick<
|
||||
ChatMessage,
|
||||
"type" | "context" | "room" | "revalidateOnly"
|
||||
>;
|
||||
interface ChatSystemMessageService {
|
||||
send: (msg: PartialChatMessage | PartialChatMessage[]) => undefined;
|
||||
}
|
||||
|
||||
invariant(
|
||||
process.env.SKALOP_SYSTEM_MESSAGE_URL,
|
||||
"Missing env var: SKALOP_SYSTEM_MESSAGE_URL",
|
||||
);
|
||||
invariant(process.env.SKALOP_TOKEN, "Missing env var: SKALOP_TOKEN");
|
||||
|
||||
export const send: ChatSystemMessageService["send"] = (partialMsg) => {
|
||||
const msgArr = Array.isArray(partialMsg) ? partialMsg : [partialMsg];
|
||||
|
||||
const fullMessages: ChatMessage[] = msgArr.map((partialMsg) => {
|
||||
return {
|
||||
id: nanoid(),
|
||||
timestamp: Date.now(),
|
||||
room: partialMsg.room,
|
||||
context: partialMsg.context,
|
||||
type: partialMsg.type,
|
||||
revalidateOnly: partialMsg.revalidateOnly,
|
||||
};
|
||||
});
|
||||
|
||||
return void fetch(process.env.SKALOP_SYSTEM_MESSAGE_URL!, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(fullMessages),
|
||||
headers: [[SKALOP_TOKEN_HEADER_NAME, process.env.SKALOP_TOKEN!]],
|
||||
}).catch(console.error);
|
||||
};
|
||||
Reference in New Issue
Block a user