From e7f3bb5abf3ba7947bd73e2eabc9d2b35530c62b Mon Sep 17 00:00:00 2001 From: William Grant Date: Thu, 15 Jun 2023 16:09:20 +1000 Subject: [PATCH] fix: if there is no last message, we still want to display the interaction status loading state shows correctly in all cases, cleanup as well --- ts/components/dialog/SessionConfirm.tsx | 5 ----- .../InteractionItem.tsx | 19 +++++++++++-------- ts/interactions/conversationInteractions.ts | 6 +++--- ts/models/conversation.ts | 14 ++++++++++++-- ts/models/conversationAttributes.ts | 2 -- .../conversations/ConversationController.ts | 1 - ts/state/ducks/conversations.ts | 1 - 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/ts/components/dialog/SessionConfirm.tsx b/ts/components/dialog/SessionConfirm.tsx index 95d4b3cf5..55fe0182d 100644 --- a/ts/components/dialog/SessionConfirm.tsx +++ b/ts/components/dialog/SessionConfirm.tsx @@ -11,7 +11,6 @@ import { shell } from 'electron'; import { MessageInteraction } from '../../interactions'; import { ConversationInteractionStatus, - ConversationInteractionType, updateConversationInteractionState, } from '../../interactions/conversationInteractions'; import { useLastMessage } from '../../hooks/useParamSelector'; @@ -27,10 +26,6 @@ const StyledSubMessageText = styled(SessionHtmlRenderer)` margin-bottom: var(--margins-md); `; -// NOTE could be other confirmation statuses and types in future -export type ConfirmationStatus = ConversationInteractionStatus | undefined; -export type ConfirmationType = ConversationInteractionType | undefined; - export interface SessionConfirmDialogProps { message?: string; messageSub?: string; diff --git a/ts/components/leftpane/conversation-list-item/InteractionItem.tsx b/ts/components/leftpane/conversation-list-item/InteractionItem.tsx index 6e8de26ea..2d81a2492 100644 --- a/ts/components/leftpane/conversation-list-item/InteractionItem.tsx +++ b/ts/components/leftpane/conversation-list-item/InteractionItem.tsx @@ -51,30 +51,33 @@ export const InteractionItem = (props: InteractionItemProps) => { setStoredLastMessageText(convo.get('lastMessage')); } } - }, [conversationId, interactionStatus, lastMessage?.interactionStatus]); + }, [conversationId]); let text = storedLastMessageText || ''; - let failText = ''; + let errorText = ''; + switch (interactionType) { case ConversationInteractionType.Hide: - failText = window.i18n('hideConversationFailed'); + errorText = window.i18n('hideConversationFailed'); text = interactionStatus === ConversationInteractionStatus.Error - ? failText - : interactionStatus === ConversationInteractionStatus.Loading + ? errorText + : interactionStatus === ConversationInteractionStatus.Start || + interactionStatus === ConversationInteractionStatus.Loading ? window.i18n('hiding') : text; break; case ConversationInteractionType.Leave: - failText = isCommunity + errorText = isCommunity ? window.i18n('leaveCommunityFailed') : isGroup ? window.i18n('leaveGroupFailed') : window.i18n('deleteConversationFailed'); text = interactionStatus === ConversationInteractionStatus.Error - ? failText - : interactionStatus === ConversationInteractionStatus.Loading + ? errorText + : interactionStatus === ConversationInteractionStatus.Start || + interactionStatus === ConversationInteractionStatus.Loading ? window.i18n('leaving') : text; break; diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 436210b84..8302794f3 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -269,7 +269,7 @@ export function showLeavePrivateConversationbyConvoId( await clearConversationInteractionState({ conversationId }); } catch (err) { window.log.warn(`showLeavePrivateConversationbyConvoId error: ${err}`); - await handleConversationInteractionError({ + await saveConversationInteractionErrorAsMessage({ conversationId, interactionType: isMe ? ConversationInteractionType.Hide @@ -335,7 +335,7 @@ export function showLeaveGroupByConvoId(conversationId: string, name: string | u await clearConversationInteractionState({ conversationId }); } catch (err) { window.log.warn(`showLeaveGroupByConvoId error: ${err}`); - await handleConversationInteractionError({ + await saveConversationInteractionErrorAsMessage({ conversationId, interactionType: ConversationInteractionType.Leave, }); @@ -731,7 +731,7 @@ export async function clearConversationInteractionState({ } } -async function handleConversationInteractionError({ +async function saveConversationInteractionErrorAsMessage({ conversationId, interactionType, }: { diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 99463932a..333fd510b 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -380,11 +380,11 @@ export class ConversationModel extends Backbone.Model { } // -- Handle the last message status, if present -- + const lastMessageInteractionType = this.get('lastMessageInteractionType'); + const lastMessageInteractionStatus = this.get('lastMessageInteractionStatus'); const lastMessageText = this.get('lastMessage'); if (lastMessageText && lastMessageText.length) { const lastMessageStatus = this.get('lastMessageStatus'); - const lastMessageInteractionType = this.get('lastMessageInteractionType'); - const lastMessageInteractionStatus = this.get('lastMessageInteractionStatus'); toRet.lastMessage = { status: lastMessageStatus, @@ -392,6 +392,16 @@ export class ConversationModel extends Backbone.Model { interactionType: lastMessageInteractionType, interactionStatus: lastMessageInteractionStatus, }; + } else { + // if there is no last message, we still want to display the interaction status + if (lastMessageInteractionType && lastMessageInteractionStatus) { + toRet.lastMessage = { + text: '', + status: 'sent', + interactionType: lastMessageInteractionType, + interactionStatus: lastMessageInteractionStatus, + }; + } } return toRet; } diff --git a/ts/models/conversationAttributes.ts b/ts/models/conversationAttributes.ts index c3b262877..14766b5fa 100644 --- a/ts/models/conversationAttributes.ts +++ b/ts/models/conversationAttributes.ts @@ -107,8 +107,6 @@ export interface ConversationAttributes { didApproveMe: boolean; // if our message request was approved already (or they've sent us a message request/message themselves). If isApproved & didApproveMe, a message request becomes a contact markedAsUnread: boolean; // Force the conversation as unread even if all the messages are read. Used to highlight a conversation the user wants to check again later, synced. - - // the last interaction we had with this conversation e.g. failed to leave a group } /** diff --git a/ts/session/conversations/ConversationController.ts b/ts/session/conversations/ConversationController.ts index 9a7d93a5f..0dddc0e1a 100644 --- a/ts/session/conversations/ConversationController.ts +++ b/ts/session/conversations/ConversationController.ts @@ -266,7 +266,6 @@ export class ConversationController { conversation.set({ priority: CONVERSATION_PRIORITIES.hidden, }); - // TODO based on some sort of arg we should remove the contacts messages // We don't remove entries from the contacts wrapper, so better keep corresponding convo volatile info for now (it will be pruned if needed) await conversation.commit(); // this updates the wrappers content to reflect the hidden state } else { diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 7bec9bd8c..417c1322a 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -232,7 +232,6 @@ export type LastMessageType = { interactionStatus: ConversationInteractionStatus | null; }; -// NOTE This is used for failed interactions that are saved as messages to the db and rendered in a conversation export type InteractionNotificationType = { interactionType: ConversationInteractionType; interactionStatus: ConversationInteractionStatus;