diff --git a/phone/src/apps/messages/components/modal/MessageModal.tsx b/phone/src/apps/messages/components/modal/MessageModal.tsx index b574773..8d402e0 100644 --- a/phone/src/apps/messages/components/modal/MessageModal.tsx +++ b/phone/src/apps/messages/components/modal/MessageModal.tsx @@ -7,10 +7,12 @@ import useMessages from "../../hooks/useMessages"; import useModals from "../../hooks/useModals"; import Conversation, { CONVERSATION_ELEMENT_ID } from "./Conversation"; import MessageSkeletonList from "./MessageSkeletonList"; +import Nui from "../../../../os/nui-events/utils/Nui"; const LARGE_HEADER_CHARS = 30; const MAX_HEADER_CHARS = 80; const MINIMUM_LOAD_TIME = 750; +const MESSAGES_REFRESH_RATE = 5000; export const MessageModal = () => { const classes = useStyles(); @@ -42,6 +44,14 @@ export const MessageModal = () => { } }, [minimumLoadPassed, messages?.length]); + useEffect(() => { + const interval = window.setInterval(() => { + if (!activeMessageGroup) return; + Nui.send("phone:fetchMessages", { groupId: activeMessageGroup.groupId }); + }, MESSAGES_REFRESH_RATE); + return () => window.clearInterval(interval); + }); + // we add a minimum (but short) load time here so that // there isn't a quick flash of loading and immediately // another flash to the tweets screen. diff --git a/resources/server/sv_messages.ts b/resources/server/sv_messages.ts index 8522e4d..5693e5d 100644 --- a/resources/server/sv_messages.ts +++ b/resources/server/sv_messages.ts @@ -69,7 +69,7 @@ async function getMessageGroups(userIdentifier: string): Promise { return count > 0; } +async function getParticipantsByGroup(groupId: string): Promise { + const query = ` + SELECT participant_identifier as identifier + FROM npwd_messages_groups + WHERE group_id = ?; + `; + const [results] = await pool.query(query, [ groupId]); + const rows = (results); + return rows.map((row: any) => row.identifier); +} + /** * Consolidate raw message groups into a mapping that groups participants * by the message group. The goal of this is to reduce the rows of message