mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
added polling for receiving live messages
This commit is contained in:
1 parent
be5c038128
commit
c5b1e3d8c7
2 files changed
+22
-1
No files matched your search
@@ -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.
|
||||
|
||||
@@ -69,7 +69,7 @@ async function getMessageGroups(userIdentifier: string): Promise<UnformattedMess
|
||||
LEFT OUTER JOIN users on users.identifier = npwd_messages_groups.participant_identifier
|
||||
LEFT OUTER JOIN npwd_messages_labels on npwd_messages_labels.group_id = npwd_messages_groups.group_id
|
||||
LEFT OUTER JOIN npwd_phone_contacts on npwd_phone_contacts.number = users.phone_number
|
||||
WHERE npwd_messages_groups.user_identifier = ? AND npwd_messages_groups.participant_identifier != ?
|
||||
WHERE npwd_messages_groups.participant_identifier = ?
|
||||
ORDER BY npwd_messages_groups.createdAt DESC
|
||||
`
|
||||
const [results] = await pool.query(query, [ userIdentifier, userIdentifier]);
|
||||
@@ -180,6 +180,17 @@ async function checkIfMessageGroupExists(groupId: string): Promise<boolean> {
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
async function getParticipantsByGroup(groupId: string): Promise<string[]> {
|
||||
const query = `
|
||||
SELECT participant_identifier as identifier
|
||||
FROM npwd_messages_groups
|
||||
WHERE group_id = ?;
|
||||
`;
|
||||
const [results] = await pool.query(query, [ groupId]);
|
||||
const rows = (<any>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
|
||||
|
||||
Reference in new issue
Block a user