feat: created util funciton lookupQuote to read from the quote lookup map

this consolidates the key lookup logic to one place for future proofing
pull/2757/head
William Grant 3 years ago
parent 70156c33b3
commit db5f2d8534

@ -569,7 +569,7 @@ function handleMessageExpiredOrDeleted(
const msgProps = state.messages[messageInStoreIndex].propsForMessage; const msgProps = state.messages[messageInStoreIndex].propsForMessage;
const { timestamp, sender } = msgProps; const { timestamp, sender } = msgProps;
if (timestamp && sender) { if (timestamp && sender) {
const message2Delete = editedQuotes[`${timestamp}-${sender}`]; const message2Delete = lookupQuote(editedQuotes, timestamp, sender);
window.log.debug( window.log.debug(
`Deleting quote {${timestamp}-${sender}} ${JSON.stringify(message2Delete)}` `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}`];
}

@ -4,6 +4,7 @@ import { StateType } from '../reducer';
import { import {
ConversationLookupType, ConversationLookupType,
ConversationsStateType, ConversationsStateType,
lookupQuote,
MentionsMembersType, MentionsMembersType,
MessageModelPropsWithConvoProps, MessageModelPropsWithConvoProps,
MessageModelPropsWithoutConvoProps, MessageModelPropsWithoutConvoProps,
@ -1021,7 +1022,7 @@ export const getMessageQuoteProps = createSelector(
return quoteNotFound; return quoteNotFound;
} }
const sourceMessage = quotesProps[`${id}-${author}`]; const sourceMessage = lookupQuote(quotesProps, Number(id), author);
if (!sourceMessage) { if (!sourceMessage) {
return quoteNotFound; return quoteNotFound;
} }

Loading…
Cancel
Save