Skip to content

Commit

Permalink
tweak(phone/messages): remove dead code flow
Browse files Browse the repository at this point in the history
  • Loading branch information
TasoOneAsia committed Dec 8, 2021
1 parent 893bffa commit ab61bf3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
59 changes: 25 additions & 34 deletions phone/src/apps/messages/hooks/useMessageService.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import { useNuiEvent } from 'fivem-nui-react-lib';
import {
Message,
MessageConversationResponse,
MessageEvents,
} from '@typings/messages';
import { useMessageActions } from './useMessageActions';
import { useCallback } from 'react';
import { MessageEvents } from '@typings/messages';
import { useMessageNotifications } from './useMessageNotifications';
import { useLocation } from 'react-router';
import { usePhoneVisibility } from '@os/phone/hooks/usePhoneVisibility';
import { useContactActions } from '../../contacts/hooks/useContactActions';

export const useMessagesService = () => {
const { updateMessages, updateConversations } = useMessageActions();
// const { updateMessages, updateConversations } = useMessageActions();
const { setNotification } = useMessageNotifications();
const { pathname } = useLocation();
const { visibility } = usePhoneVisibility();
const { getContactByNumber } = useContactActions();
// const { getContactByNumber } = useContactActions();

const handleMessageBroadcast = ({ conversationName, conversationId, message }) => {
if (visibility && pathname.includes('/messages/conversations')) {
Expand All @@ -26,30 +19,28 @@ export const useMessagesService = () => {
setNotification({ conversationName, conversationId, message });
};

// This is only called for the receiver of the message. We'll be using the standardized pattern for the transmitter.
const handleUpdateMessages = useCallback(
(messageDto: Message) => {
updateMessages(messageDto);
},
[updateMessages],
);

const handleAddConversation = useCallback(
(conversation: MessageConversationResponse) => {
const contact = getContactByNumber(conversation.phoneNumber);

updateConversations({
phoneNumber: conversation.phoneNumber,
conversation_id: conversation.conversation_id,
avatar: contact.avatar || null,
unread: 0,
display: contact.display || null,
});
},
[updateConversations, getContactByNumber],
);
// // This is only called for the receiver of the message. We'll be using the standardized pattern for the transmitter.
// const handleUpdateMessages = useCallback(
// (messageDto: Message) => {
// updateMessages(messageDto);
// },
// [updateMessages],
// );
//
// const handleAddConversation = useCallback(
// (conversation: MessageConversationResponse) => {
// const contact = getContactByNumber(conversation.phoneNumber);
//
// updateConversations({
// phoneNumber: conversation.phoneNumber,
// conversation_id: conversation.conversation_id,
// avatar: contact.avatar || null,
// unread: 0,
// display: contact.display || null,
// });
// },
// [updateConversations, getContactByNumber],
// );

useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_BROADCAST, handleMessageBroadcast);
useNuiEvent('MESSAGES', MessageEvents.SEND_MESSAGE_SUCCESS, handleUpdateMessages);
useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_CONVERSATION_SUCCESS, handleAddConversation);
};
9 changes: 0 additions & 9 deletions typings/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,10 @@ export interface MessageConversationResponse {

export enum MessageEvents {
FETCH_MESSAGE_CONVERSATIONS = 'npwd:fetchMessageGroups',
FETCH_MESSAGE_GROUPS_SUCCESS = 'npwd:fetchMessageGroupsSuccess',
FETCH_MESSAGE_GROUPS_FAILED = 'npwd:fetchMessageGroupsFailed',
CREATE_MESSAGE_CONVERSATION = 'npwd:createMessageGroup',
CREATE_MESSAGE_CONVERSATION_SUCCESS = 'npwd:createMessageConversationSuccess',
CREATE_MESSAGE_GROUP_SUCCESS = 'npwd:createMessageGroupSuccess',
CREATE_MESSAGE_GROUP_FAILED = 'npwd:createMessageGroupFailed',
SEND_MESSAGE = 'npwd:sendMessage',
SEND_MESSAGE_SUCCESS = 'npwd:sendMessageSuccess',
SEND_MESSAGE_FAILED = 'npwd:sendMessageFailed',
DELETE_MESSAGE = 'npwd:deleteMessage',
FETCH_MESSAGES = 'npwd:fetchMessages',
FETCH_MESSAGES_SUCCESS = 'npwd:fetchMessagesSuccess',
FETCH_MESSAGES_FAILED = 'npwd:fetchMessagesFailed',
FETCH_INITIAL_MESSAGES = 'npwd:fetchInitialMessages',
ACTION_RESULT = 'npwd:setMessagesAlert',
CREATE_MESSAGE_BROADCAST = 'createMessagesBroadcast',
Expand Down

0 comments on commit ab61bf3

Please sign in to comment.