diff --git a/README.md b/README.md index c34ea96..353bccb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -NPWD is our current running project. Our team has been working on the project since Auguest, 2020. This resource isn’t complete yet and currently has no ETA for release. Feel free to test it out in a dev environment by following the installation guide. +NPWD is our current running project. Our team has been working on the project since August, 2020. This resource isn’t complete yet and currently has no ETA for release. Feel free to test it out in a dev environment by following the installation guide. Written completely by the Project Error Dev Team in [React](https://reactjs.org/) with a [TypeScript](https://www.typescriptlang.org/) client/server environment. diff --git a/phone/src/apps/messages/hooks/useMessageNotifications.ts b/phone/src/apps/messages/hooks/useMessageNotifications.ts index 8df34c8..1a41834 100644 --- a/phone/src/apps/messages/hooks/useMessageNotifications.ts +++ b/phone/src/apps/messages/hooks/useMessageNotifications.ts @@ -1,5 +1,6 @@ +import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -import { useHistory } from 'react-router-dom'; +import { matchPath, useHistory } from 'react-router-dom'; import { useApp } from '../../../os/apps/hooks/useApps'; import { useNotifications } from '../../../os/notifications/hooks/useNotifications'; import { goToConversation } from '../utils/goToConversation'; @@ -12,7 +13,20 @@ export const useMessageNotifications = () => { const history = useHistory(); const { removeId, addNotification, addNotificationAlert } = useNotifications(); const { icon, notificationIcon } = useApp('MESSAGES'); - const { getMessageGroupById } = useMessages(); + const { getMessageGroupById, activeMessageGroup } = useMessages(); + + // Remove notifications from groups when opening them + history.listen((location) => { + if ( + activeMessageGroup?.groupId && + matchPath(location.pathname, { + path: `/messages/conversations/${activeMessageGroup.groupId}`, + exact: true, + }) + ) { + removeId(`${NOTIFICATION_ID}:${activeMessageGroup.groupId}`); + } + }); const setNotification = ({ groupId, message }) => { const group = getMessageGroupById(groupId); diff --git a/phone/src/apps/messages/hooks/useMessageService.ts b/phone/src/apps/messages/hooks/useMessageService.ts index 458a21e..7647f7d 100644 --- a/phone/src/apps/messages/hooks/useMessageService.ts +++ b/phone/src/apps/messages/hooks/useMessageService.ts @@ -6,8 +6,11 @@ import { useTranslation } from 'react-i18next'; import { useMessageNotifications } from './useMessageNotifications'; import { useCallback } from 'react'; import Nui from '../../../os/nui-events/utils/Nui'; +import { useLocation } from 'react-router'; +import { MessageEvents } from '../../../../../typings/messages'; export const useMessagesService = () => { + const { pathname } = useLocation(); const [activeMessageGroup, setActiveMessageGroup] = useRecoilState( messageState.activeMessageGroup, ); @@ -31,11 +34,15 @@ export const useMessagesService = () => { const handleMessageBroadcast = useCallback( ({ groupId, message }) => { if (groupId === activeMessageGroup?.groupId) { - Nui.send('phone:fetchMessages', { groupId: activeMessageGroup.groupId }); + Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: activeMessageGroup.groupId }); + if (pathname.includes('messages/conversations')) { + // Dont trigger notification if conversation is open. + return; + } } setNotification({ groupId, message }); }, - [activeMessageGroup, setNotification], + [activeMessageGroup, pathname, setNotification], ); const _setMessageGroups = useCallback( @@ -50,10 +57,10 @@ export const useMessagesService = () => { [activeMessageGroup, setActiveMessageGroup, setMessageGroups], ); - useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', _setMessageGroups); - useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages); - useNuiEvent('MESSAGES', 'phone:createMessageGroupSuccess', setCreateMessageGroupResult); - useNuiEvent('MESSAGES', 'phone:createMessageGroupFailed', setCreateMessageGroupResult); - useNuiEvent('MESSAGES', 'createMessagesBroadcast', handleMessageBroadcast); - useNuiEvent('MESSAGES', 'phone:setMessagesAlert', handleAddAlert); + useNuiEvent('MESSAGES', MessageEvents.FETCH_MESSAGE_GROUPS_SUCCESS, _setMessageGroups); + useNuiEvent('MESSAGES', MessageEvents.FETCH_MESSAGES_SUCCESS, setMessages); + useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_GROUP_SUCCESS, setCreateMessageGroupResult); + useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_GROUP_FAILED, setCreateMessageGroupResult); + useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_BROADCAST, handleMessageBroadcast); + useNuiEvent('MESSAGES', MessageEvents.ACTION_RESULT, handleAddAlert); }; diff --git a/phone/src/apps/messages/utils/goToConversation.ts b/phone/src/apps/messages/utils/goToConversation.ts index 52b5905..b70a796 100644 --- a/phone/src/apps/messages/utils/goToConversation.ts +++ b/phone/src/apps/messages/utils/goToConversation.ts @@ -1,7 +1,8 @@ +import { MessageEvents } from '../../../../../typings/messages'; import Nui from '../../../os/nui-events/utils/Nui'; export const goToConversation = (messageGroup, history) => { if (!messageGroup?.groupId || !history) return; history.push(`/messages/conversations/${messageGroup.groupId}`); - Nui.send('phone:fetchMessages', { groupId: messageGroup.groupId }); + Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: messageGroup.groupId }); }; diff --git a/phone/src/apps/settings/hooks/useSettings.ts b/phone/src/apps/settings/hooks/useSettings.ts index 96217ae..38e5370 100644 --- a/phone/src/apps/settings/hooks/useSettings.ts +++ b/phone/src/apps/settings/hooks/useSettings.ts @@ -81,8 +81,10 @@ const localStorageEffect = (key) => ({ setSelf, onSet }) => { const savedVal = localStorage.getItem(key); if (savedVal) { try { - const validString = !isSchemaValid(savedVal); + const validString = isSchemaValid(savedVal); if (validString) { + setSelf(JSON.parse(savedVal)); + } else { console.error('Settings Schema was invalid, applying default settings'); setSelf(config.defaultSettings); } diff --git a/resources/client/cl_sellout.ts b/resources/client/cl_sellout.ts index 8622562..1699827 100644 --- a/resources/client/cl_sellout.ts +++ b/resources/client/cl_sellout.ts @@ -2,12 +2,11 @@ import { MarketplaceEvents, MarketplaceListing } from '../../typings/marketplace import { IAlertProps } from '../../typings/alerts'; import { sendMarketplaceEvent } from '../utils/messages'; -RegisterNuiCallbackType(MarketplaceEvents.ADD_LISTING); - -onNet(MarketplaceEvents.SEND_LISTING, (listing: MarketplaceListing) => { - sendMarketplaceEvent('setListing', listing); +onNet(MarketplaceEvents.SEND_LISTING, (listings: MarketplaceListing[]) => { + sendMarketplaceEvent('setListings', listings); }); +RegisterNuiCallbackType(MarketplaceEvents.ADD_LISTING); on(`__cfx_nui:${MarketplaceEvents.ADD_LISTING}`, (data: MarketplaceListing, cb: Function) => { emitNet(MarketplaceEvents.ADD_LISTING, data); cb(); diff --git a/resources/client/cl_utils.ts b/resources/client/cl_utils.ts index 304f25f..6db155c 100644 --- a/resources/client/cl_utils.ts +++ b/resources/client/cl_utils.ts @@ -52,3 +52,10 @@ export default class ClientUtils { }); } } + +export const NuiCallback = (event: string, callback: Function) => { + RegisterRawNuiCallback(event, (data: any) => { + const parsed = JSON.parse(data?.body); + callback(parsed); + }); +};