diff --git a/phone/src/apps/messages/components/AlertBar.tsx b/phone/src/apps/messages/components/AlertBar.tsx index 8bdadc4..b7bab8f 100644 --- a/phone/src/apps/messages/components/AlertBar.tsx +++ b/phone/src/apps/messages/components/AlertBar.tsx @@ -35,7 +35,7 @@ export default function AlertBar() { useEffect(() => { if (!createMessageGroupResult) return; - const { error, phoneNumber, duplicate } = createMessageGroupResult; + const { error, phoneNumber, duplicate, mine } = createMessageGroupResult; if (error && phoneNumber) { const error = `${t("APPS_MESSAGES_INVALID_PHONE_NUMBER")}${phoneNumber}`; setOpen(true); @@ -45,6 +45,10 @@ export default function AlertBar() { setOpen(true); setSeverity("error"); setMessage(t("APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE")); + } else if (error && mine) { + setOpen(true); + setSeverity("error"); + setMessage(t("APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE")); } else if (error) { setOpen(true); setSeverity("error"); diff --git a/phone/src/apps/messages/components/modal/MessageModal.tsx b/phone/src/apps/messages/components/modal/MessageModal.tsx index 8d402e0..2de6560 100644 --- a/phone/src/apps/messages/components/modal/MessageModal.tsx +++ b/phone/src/apps/messages/components/modal/MessageModal.tsx @@ -27,11 +27,24 @@ export const MessageModal = () => { }; useEffect(() => { + if (!activeMessageGroup?.groupId) return; + const timeout = window.setTimeout(() => { setMimimumLoadPassed(true); }, MINIMUM_LOAD_TIME); - return () => window.clearTimeout(timeout); - }); + + const interval = window.setInterval(() => { + if (!activeMessageGroup) return; + Nui.send("phone:fetchMessages", { + groupId: activeMessageGroup.groupId, + }); + }, MESSAGES_REFRESH_RATE); + + return () => { + window.clearInterval(interval); + window.clearTimeout(timeout); + }; + }, [activeMessageGroup?.groupId]); useEffect(() => { // when we get a new message group we should scroll to the @@ -44,14 +57,6 @@ 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/phone/src/common/interfaces/messages.ts b/phone/src/common/interfaces/messages.ts index a307562..aaa7db3 100644 --- a/phone/src/common/interfaces/messages.ts +++ b/phone/src/common/interfaces/messages.ts @@ -23,4 +23,5 @@ export interface CreateMessageGroupResult { phoneNumber?: string; duplicate?: boolean; groupId?: string; + mine?: boolean; } diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index d1a8358..e68f834 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -60,6 +60,7 @@ "APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT": "Submit", "APPS_MESSAGES_INVALID_PHONE_NUMBER": "Invalid phone number: ", "APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE": "This message group already exists", - "APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED": "Failed to create message group" + "APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED": "Failed to create message group", + "APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE": "You cannot add yourself!" } } diff --git a/resources/server/sv_messages.ts b/resources/server/sv_messages.ts index 5693e5d..a53f168 100644 --- a/resources/server/sv_messages.ts +++ b/resources/server/sv_messages.ts @@ -180,17 +180,6 @@ async function checkIfMessageGroupExists(groupId: 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 @@ -267,6 +256,11 @@ async function createMessageGroupsFromPhoneNumbers( } } + // don't allow explicitly adding yourself + if (identifiers.some(identifier => identifier === userIdentifier)) { + return { error: true, mine: true }; + } + // make sure we are always in a consistent order. It is very important // that this not change! Changing this order can result in the ability // of duplicate message groups being created.