From 21a97ba0ec2693bae45d7c619f63d9f40928dcff Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 9 Nov 2020 11:58:51 +1100 Subject: [PATCH] fix deleteMessages from headermenu and load unread_count message on show --- js/models/conversations.d.ts | 2 ++ js/models/conversations.js | 2 -- .../conversation/SessionConversation.tsx | 17 +++++++++----- .../SessionConversationMessagesList.tsx | 22 ++++++++++++++----- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/js/models/conversations.d.ts b/js/models/conversations.d.ts index 746e5dd29..e3d197a7e 100644 --- a/js/models/conversations.d.ts +++ b/js/models/conversations.d.ts @@ -92,6 +92,8 @@ export interface ConversationModel makeQuote: any; unblock: any; deleteContact: any; + deleteMessages(); + endSession: () => Promise; block: any; copyPublicKey: any; diff --git a/js/models/conversations.js b/js/models/conversations.js index 3acac23a8..8eb80229c 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -2234,8 +2234,6 @@ }, deleteMessages() { - this.resetMessageSelection(); - let params; if (this.isPublic()) { throw new Error( diff --git a/ts/components/session/conversation/SessionConversation.tsx b/ts/components/session/conversation/SessionConversation.tsx index 5857978ae..8f3909abd 100644 --- a/ts/components/session/conversation/SessionConversation.tsx +++ b/ts/components/session/conversation/SessionConversation.tsx @@ -334,13 +334,18 @@ export class SessionConversation extends React.Component { if (this.state.initialFetchComplete) { return; } - - return this.getMessages( + const { conversationKey } = this.props; + const conversationModel = window.ConversationController.getOrThrow( + conversationKey + ); + const unreadCount = await conversationModel.getUnreadCount(); + const messagesToFetch = Math.max( Constants.CONVERSATION.DEFAULT_MESSAGE_FETCH_COUNT, - () => { - this.setState({ initialFetchComplete: true }); - } + unreadCount ); + return this.getMessages(messagesToFetch, () => { + this.setState({ initialFetchComplete: true }); + }); } // tslint:disable-next-line: no-empty @@ -440,7 +445,7 @@ export class SessionConversation extends React.Component { onSetDisappearingMessages: (seconds: any) => conversation.updateExpirationTimer(seconds), - onDeleteMessages: () => null, + onDeleteMessages: () => conversation.deleteMessages(), onDeleteSelectedMessages: this.deleteSelectedMessages, onCloseOverlay: () => { this.setState({ selectedMessages: [] }); diff --git a/ts/components/session/conversation/SessionConversationMessagesList.tsx b/ts/components/session/conversation/SessionConversationMessagesList.tsx index a30d78ac6..3de86b07a 100644 --- a/ts/components/session/conversation/SessionConversationMessagesList.tsx +++ b/ts/components/session/conversation/SessionConversationMessagesList.tsx @@ -135,6 +135,16 @@ export class SessionConversationMessagesList extends React.Component< if (findFirstUnreadIndex === -1 && conversation.unreadCount !== 0) { findFirstUnreadIndex = messages.length - 1; } + if (conversation.unreadCount === 0) { + findFirstUnreadIndex = -1; + } + // console.log( + // 'findFirstUnreadIndex', + // findFirstUnreadIndex, + // 'unreadCount', + // conversation.unreadCount + // ); + return ( <> {messages.map((message: MessageModel) => { @@ -165,8 +175,8 @@ export class SessionConversationMessagesList extends React.Component< if (groupNotificationProps) { return ( <> - {unreadIndicator} + {unreadIndicator} ); } @@ -174,8 +184,8 @@ export class SessionConversationMessagesList extends React.Component< if (propsForGroupInvitation) { return ( <> - {unreadIndicator} + {unreadIndicator} ); } @@ -183,8 +193,8 @@ export class SessionConversationMessagesList extends React.Component< if (verificationSessionProps) { return ( <> - {unreadIndicator} + {unreadIndicator} ); } @@ -192,8 +202,8 @@ export class SessionConversationMessagesList extends React.Component< if (resetSessionProps) { return ( <> - {unreadIndicator} + {unreadIndicator} ); } @@ -201,8 +211,8 @@ export class SessionConversationMessagesList extends React.Component< if (timerProps) { return ( <> - {unreadIndicator} + {unreadIndicator} ); } @@ -211,12 +221,12 @@ export class SessionConversationMessagesList extends React.Component< // in a series of messages from the same user return ( <> - {unreadIndicator} {this.renderMessage( messageProps, message.firstMessageOfSeries, multiSelectMode )} + {unreadIndicator} ); })}