diff --git a/lib/shared/chat-utils.js b/lib/shared/chat-utils.js new file mode 100644 index 000000000..2cf008635 --- /dev/null +++ b/lib/shared/chat-utils.js @@ -0,0 +1,32 @@ +// @flow + +import type { LocalMessageInfo } from '../types/message-types.js'; +import type { TextMessageInfo } from '../types/messages/text.js'; + +function textMessageSendFailed( + messageInfo: TextMessageInfo, + localMessageInfo: ?LocalMessageInfo, +): boolean { + const { + id, + creator: { isViewer }, + } = messageInfo; + + if (!isViewer || !localMessageInfo || !localMessageInfo.sendFailed) { + return false; + } + + if ( + localMessageInfo.outboundP2PMessageIDs && + localMessageInfo.outboundP2PMessageIDs.length > 0 + ) { + // DM message + return true; + } else if (id === null || id === undefined) { + return true; + } + + return false; +} + +export { textMessageSendFailed }; diff --git a/native/chat/text-message-send-failed.js b/native/chat/text-message-send-failed.js index b0b2b32f3..d7b44cb41 100644 --- a/native/chat/text-message-send-failed.js +++ b/native/chat/text-message-send-failed.js @@ -1,18 +1,12 @@ // @flow +import { textMessageSendFailed as sharedTextMessageSendFailed } from 'lib/shared/chat-utils.js'; + import type { ChatTextMessageInfoItemWithHeight } from '../types/chat-types.js'; export default function textMessageSendFailed( item: ChatTextMessageInfoItemWithHeight, ): boolean { - const { - id, - creator: { isViewer }, - } = item.messageInfo; - return !!( - isViewer && - (id === null || id === undefined) && - item.localMessageInfo && - item.localMessageInfo.sendFailed - ); + const { messageInfo, localMessageInfo } = item; + return sharedTextMessageSendFailed(messageInfo, localMessageInfo); } diff --git a/web/chat/text-message-send-failed.js b/web/chat/text-message-send-failed.js index d0d14fb09..eba79ae2a 100644 --- a/web/chat/text-message-send-failed.js +++ b/web/chat/text-message-send-failed.js @@ -1,21 +1,17 @@ // @flow import type { ChatMessageInfoItem } from 'lib/selectors/chat-selectors.js'; +import { textMessageSendFailed as sharedTextMessageSendFailed } from 'lib/shared/chat-utils.js'; import { messageTypes } from 'lib/types/message-types-enum.js'; export default function textMessageSendFailed( item: ChatMessageInfoItem, ): boolean { - const { - id, - creator: { isViewer }, - type, - } = item.messageInfo; - return !!( - isViewer && - type === messageTypes.TEXT && - (id === null || id === undefined) && - item.localMessageInfo && - item.localMessageInfo.sendFailed - ); + const { messageInfo, localMessageInfo } = item; + + if (messageInfo.type !== messageTypes.TEXT) { + return false; + } + + return sharedTextMessageSendFailed(messageInfo, localMessageInfo); }