From db5f2d853404e0b332d0e0acf253d0c00593e676 Mon Sep 17 00:00:00 2001 From: William Grant Date: Fri, 19 May 2023 11:48:53 +1000 Subject: [PATCH] feat: created util funciton lookupQuote to read from the quote lookup map this consolidates the key lookup logic to one place for future proofing --- ts/state/ducks/conversations.ts | 17 ++++++++++++++++- ts/state/selectors/conversations.ts | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 16bc8314d..b4c131a07 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -569,7 +569,7 @@ function handleMessageExpiredOrDeleted( const msgProps = state.messages[messageInStoreIndex].propsForMessage; const { timestamp, sender } = msgProps; if (timestamp && sender) { - const message2Delete = editedQuotes[`${timestamp}-${sender}`]; + const message2Delete = lookupQuote(editedQuotes, timestamp, sender); window.log.debug( `Deleting quote {${timestamp}-${sender}} ${JSON.stringify(message2Delete)}` ); @@ -1152,3 +1152,18 @@ export async function openConversationToSpecificMessage(args: { }) ); } + +/** + * Look for quote matching the timestamp and author in the quote lookup map + * @param quotes - the lookup map of the selected conversations quotes + * @param author - the pubkey of the quoted author + * @param timestamp - usually the id prop on the quote object of a message + * @returns - the message model if found, undefined otherwise + */ +export function lookupQuote( + quotes: QuoteLookupType, + timestamp: number, + author: string +): MessageModelPropsWithoutConvoProps | undefined { + return quotes[`${timestamp}-${author}`]; +} diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 4e6fc7553..351196769 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -4,6 +4,7 @@ import { StateType } from '../reducer'; import { ConversationLookupType, ConversationsStateType, + lookupQuote, MentionsMembersType, MessageModelPropsWithConvoProps, MessageModelPropsWithoutConvoProps, @@ -1021,7 +1022,7 @@ export const getMessageQuoteProps = createSelector( return quoteNotFound; } - const sourceMessage = quotesProps[`${id}-${author}`]; + const sourceMessage = lookupQuote(quotesProps, Number(id), author); if (!sourceMessage) { return quoteNotFound; }