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 2 years ago
parent 70156c33b3
commit db5f2d8534

@ -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}`];
}

@ -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;
}

Loading…
Cancel
Save