From bec667ebee22f9324f690adb64fb7b8f5db915f2 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 22 Jun 2023 14:12:30 +0200 Subject: [PATCH] fix: remove row_number ordering when looking up message --- ts/components/avatar/Avatar.tsx | 1 + .../leftpane/LeftPaneMessageSection.tsx | 3 +- ts/node/sql.ts | 65 ++++++++++++------- ts/state/selectors/conversations.ts | 10 ++- ts/state/selectors/messages.ts | 2 +- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/ts/components/avatar/Avatar.tsx b/ts/components/avatar/Avatar.tsx index 0318dfedc..c441b759e 100644 --- a/ts/components/avatar/Avatar.tsx +++ b/ts/components/avatar/Avatar.tsx @@ -98,6 +98,7 @@ const AvatarImage = (props: { } const dataToDisplay = base64Data ? `data:image/jpeg;base64,${base64Data}` : avatarPath; + // tslint:disable: react-a11y-img-has-alt return ( { // Note: conversations is not a known prop for List, but it is required to ensure that // it re-renders when our conversations data changes. Otherwise it would just render // on startup and scroll. - + // TODO do need that `conversations` prop? I again don't see why it is needed. Especially because the list item use hook to fetch their details. return ( {({ height, width }) => ( $msgTimestamp + ${orderByClauseASC} + LIMIT $limit` ) - .all({ - conversationId, - messageId: messageId || firstUnread, - limit: - numberOfMessagesInConvo < floorLoadAllMessagesInConvo - ? floorLoadAllMessagesInConvo - : absLimit, - }); - - return map(rows, row => jsonToObject(row.json)); + .all(commonArgs); + + console.info(`getMessagesByConversation around took ${Date.now() - start}ms `); + + // sorting is made in redux already when rendered, but some things are made outside of redux, so let's make sure the order is right + return map([...messagesBefore, ...messagesAfter], row => jsonToObject(row.json)).sort( + (a, b) => { + return ( + (b.serverTimestamp || b.sent_at || b.received_at) - + (a.serverTimestamp || a.sent_at || a.received_at) + ); + } + ); } console.info( `getMessagesByConversation: Could not find messageId ${messageId} in db with conversationId: ${conversationId}. Just fetching the convo as usual.` diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 68de73d4b..b6c4dfab1 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -250,7 +250,9 @@ const _getLeftPaneLists = ( sortedConversations: Array ): Array => { return sortedConversations.filter(conversation => { - if (conversation.isBlocked) return false; + if (conversation.isBlocked) { + return false; + } // a private conversation not approved is a message request. Exclude them from the left pane lists @@ -285,12 +287,14 @@ const _getPrivateFriendsConversations = ( sortedConversations: Array ): Array => { return sortedConversations.filter(convo => { - convo.isPrivate && + return ( + convo.isPrivate && !convo.isMe && !convo.isBlocked && convo.isApproved && convo.didApproveMe && - convo.activeAt !== undefined; + convo.activeAt !== undefined + ); }); }; diff --git a/ts/state/selectors/messages.ts b/ts/state/selectors/messages.ts index 5f4618f8b..2c3fe68c4 100644 --- a/ts/state/selectors/messages.ts +++ b/ts/state/selectors/messages.ts @@ -83,7 +83,7 @@ export const useMessageDirection = (messageId: string | undefined): string | und return useMessageIdProps(messageId)?.propsForMessage.direction; }; -export const useMessageLinkPreview = (messageId: string | undefined): any[] | undefined => { +export const useMessageLinkPreview = (messageId: string | undefined): Array | undefined => { return useMessageIdProps(messageId)?.propsForMessage.previews; };