mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
Tweaks / Message notifications (#174)
* Remove msg notifications when opening one | Dont alert notifications when inside that conversation * Fix msg events * Fix goToConversation util * Fix nuiEvents for messages
This commit is contained in:
1 parent
b42ee97450
commit
a3d7c19f44
3 files changed
+33
-11
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
@@ -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 });
|
||||
};
|
||||
Reference in new issue
Block a user