diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx index b120a45..6d03a33 100644 --- a/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/phone/src/apps/contacts/components/List/ContactList.tsx @@ -43,13 +43,13 @@ export const ContactList = () => { }); }; - const handleMessage = () => { + const handleMessage = (phoneNumber: string) => { LogDebugEvent({ action: 'Routing to Message', level: 1, - data: true, + data: { phoneNumber }, }); - // TODO: Integrate to send to message event when route becomes available + history.push(`/messages/new/${phoneNumber}`); }; const filteredRegEx = new RegExp(filteredContacts, 'gi'); @@ -82,7 +82,7 @@ export const ContactList = () => { - - + ); diff --git a/phone/src/apps/messages/hooks/useAlerts.ts b/phone/src/apps/messages/hooks/useAlerts.ts index efa0672..9e802f0 100644 --- a/phone/src/apps/messages/hooks/useAlerts.ts +++ b/phone/src/apps/messages/hooks/useAlerts.ts @@ -1,21 +1,16 @@ -import { useRecoilState } from 'recoil'; +import { useRecoilValue } from 'recoil'; import { CreateMessageGroupResult } from '../../../common/typings/messages'; import { messageState } from './state'; interface IUseAlerts { createMessageGroupResult: CreateMessageGroupResult | null; - clearCreateMessageGroupResult: () => void; } export default (): IUseAlerts => { - const [ - createMessageGroupResult, - setCreateMessageGroupResult, - ] = useRecoilState( + const createMessageGroupResult = useRecoilValue( messageState.createMessageGroupResult ); - const clearCreateMessageGroupResult = () => setCreateMessageGroupResult(null); - return { createMessageGroupResult, clearCreateMessageGroupResult }; + return { createMessageGroupResult }; }; diff --git a/phone/src/apps/messages/hooks/useMessages.ts b/phone/src/apps/messages/hooks/useMessages.ts index f95a291..c093d4b 100644 --- a/phone/src/apps/messages/hooks/useMessages.ts +++ b/phone/src/apps/messages/hooks/useMessages.ts @@ -1,11 +1,13 @@ import { useRecoilState, useRecoilValue } from 'recoil'; -import { Message, MessageGroup } from '../../../common/typings/messages'; +import { CreateMessageGroupResult, Message, MessageGroup } from '../../../common/typings/messages'; import { messageState } from './state'; interface IUseMessages { messages?: Message[] | null; setMessages: (messages: Message[] | null) => void; messageGroups?: MessageGroup[] | null; + createMessageGroupResult?: CreateMessageGroupResult | null; + clearMessageGroupResult(): void; } export default (): IUseMessages => { @@ -15,5 +17,12 @@ export default (): IUseMessages => { const messageGroups = useRecoilValue( messageState.messageGroups ); - return { messages, setMessages, messageGroups }; + + const [createMessageGroupResult, setCreateMessageGroupResult] = useRecoilState( + messageState.createMessageGroupResult + ); + + const clearMessageGroupResult = () => setCreateMessageGroupResult(null); + + return { messages, setMessages, messageGroups, createMessageGroupResult, clearMessageGroupResult }; }; diff --git a/phone/src/os/debug/InjectDebugData.ts b/phone/src/os/debug/InjectDebugData.ts index d2a342f..87ac94f 100644 --- a/phone/src/os/debug/InjectDebugData.ts +++ b/phone/src/os/debug/InjectDebugData.ts @@ -27,7 +27,7 @@ interface DebugEvent { * } * ]) **/ -const InjectDebugData = (events: DebugEvent[]) => { +const InjectDebugData = (events: DebugEvent[], timer = 1000) => { if (process.env.NODE_ENV === 'development') { for (const event of events) { setTimeout(() => { @@ -40,7 +40,7 @@ const InjectDebugData = (events: DebugEvent[]) => { }, }) ); - }, 1000); + }, timer); } } }; diff --git a/resources/server/sv_messages.ts b/resources/server/sv_messages.ts index 8118f30..496939f 100644 --- a/resources/server/sv_messages.ts +++ b/resources/server/sv_messages.ts @@ -298,6 +298,24 @@ async function getFormattedMessageGroups( }); } +/** + * Create the same unique ID from an identifiers array. + * They will be always be sorted to ensure always the same ID. + * @param identifiers array of player identifiers + */ +function createGroupHashID(identifiers: string[]) { + // 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. + identifiers.sort(); + const mergedIdentifiers = identifiers.join('-'); + // we don't need this to be secure. Its purpose is to create a unique + // string derived from the identifiers. In this way we can check + // that this groupId isn't used before. If it has then it means + // we are trying to create a duplicate message group! + return md5(mergedIdentifiers); +} + /** * Main method to handle creation of new message groups. First * we retrieve identifiers for each submitted phone number and @@ -335,18 +353,9 @@ async function createMessageGroupsFromPhoneNumbers( 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. - identifiers.sort(); - const mergedIdentifiers = identifiers.join('-'); - // we don't need this to be secure. Its purpose is to create a unique - // string derived from the identifiers. In this way we can check - // that this groupId isn't used before. If it has then it means - // we are trying to create a duplicate message group! - const groupId = md5(mergedIdentifiers); + const groupId = createGroupHashID(identifiers); if (await checkIfMessageGroupExists(groupId)) { - return { error: true, duplicate: true }; + return { error: false, duplicate: true, groupId }; } const queryPromises = [ @@ -382,7 +391,7 @@ onNet(events.MESSAGES_FETCH_MESSAGE_GROUPS, async () => { const messageGroups = await getFormattedMessageGroups(identifier); emitNet( events.MESSAGES_FETCH_MESSAGE_GROUPS_SUCCESS, - getSource(), + _source, messageGroups ); } catch (e) { @@ -406,18 +415,18 @@ onNet( if (result.error) { emitNet( events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, - getSource(), + _source, result ); } else { emitNet( events.MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS, - getSource(), + _source, result ); } } catch (e) { - emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, getSource()); + emitNet(events.MESSAGES_CREATE_MESSAGE_GROUP_FAILED, _source); messageLogger.error(`Failed to create message group, ${e.message}`, { source: _source, });