fix: resolved object is not extensible bug

forEach and async still don't play nice so used a regular for loop, added QuoteLookupType
pull/2757/head
William Grant 2 years ago
parent a83bc64d0a
commit 331a4e1e12

@ -22,7 +22,7 @@ import { ToastUtils, UserUtils } from '../session/utils';
import { BlockedNumberController } from '../util'; import { BlockedNumberController } from '../util';
import { leaveClosedGroup } from '../session/group/closed-group'; import { leaveClosedGroup } from '../session/group/closed-group';
import { SignalService } from '../protobuf'; import { SignalService } from '../protobuf';
import { MessageModel, sliceQuoteText } from './message'; import { MessageModel } from './message';
import { MessageAttributesOptionals, MessageDirection } from './messageType'; import { MessageAttributesOptionals, MessageDirection } from './messageType';
import autoBind from 'auto-bind'; import autoBind from 'auto-bind';

@ -284,6 +284,10 @@ export type ConversationLookupType = {
[key: string]: ReduxConversationType; [key: string]: ReduxConversationType;
}; };
export type QuoteLookupType = {
[key: string]: MessageModelPropsWithoutConvoProps;
};
export type ConversationsStateType = { export type ConversationsStateType = {
conversationLookup: ConversationLookupType; conversationLookup: ConversationLookupType;
selectedConversation?: string; selectedConversation?: string;
@ -291,7 +295,7 @@ export type ConversationsStateType = {
messages: Array<MessageModelPropsWithoutConvoProps>; messages: Array<MessageModelPropsWithoutConvoProps>;
// NOTE the quotes that are in view // NOTE the quotes that are in view
// key is message [timestamp]-[author-pubkey] // key is message [timestamp]-[author-pubkey]
quotes: Record<string, MessageModelPropsWithoutConvoProps>; quotes: QuoteLookupType;
firstUnreadMessageId: string | undefined; firstUnreadMessageId: string | undefined;
messageDetailProps?: MessagePropsDetails; messageDetailProps?: MessagePropsDetails;
showRightPanel: boolean; showRightPanel: boolean;
@ -345,7 +349,7 @@ async function getMessages({
messageId: string | null; messageId: string | null;
}): Promise<{ }): Promise<{
messagesProps: Array<MessageModelPropsWithoutConvoProps>; messagesProps: Array<MessageModelPropsWithoutConvoProps>;
quotesProps: Record<string, MessageModelPropsWithoutConvoProps>; quotesProps: QuoteLookupType;
}> { }> {
const beforeTimestamp = Date.now(); const beforeTimestamp = Date.now();
@ -366,14 +370,14 @@ async function getMessages({
const time = Date.now() - beforeTimestamp; const time = Date.now() - beforeTimestamp;
window?.log?.info(`Loading ${messagesProps.length} messages took ${time}ms to load.`); window?.log?.info(`Loading ${messagesProps.length} messages took ${time}ms to load.`);
const quotesProps: Record<string, MessageModelPropsWithoutConvoProps> = {}; const quotesProps: QuoteLookupType = {};
messagesProps const quotes = messagesProps.filter(
.filter(
message => message.propsForMessage?.quote?.messageId && message.propsForMessage.quote?.sender message => message.propsForMessage?.quote?.messageId && message.propsForMessage.quote?.sender
) );
.forEach(async message => {
const id = message.propsForMessage?.quote?.messageId; for (let i = 0; i < quotes.length; i++) {
const sender = message.propsForMessage.quote?.sender; const id = quotes[i].propsForMessage?.quote?.messageId;
const sender = quotes[i].propsForMessage.quote?.sender;
// TODO use this is the renderering process // TODO use this is the renderering process
// const contact = message.findAndFormatContact(author); // const contact = message.findAndFormatContact(author);
@ -381,27 +385,26 @@ async function getMessages({
if (id && sender) { if (id && sender) {
const timestamp = Number(id); const timestamp = Number(id);
// See if message is already in memory if not lookup in db // See if a quoted message is already in memory if not lookup in db
let results = []; let results = messagesProps.filter(
results = messagesProps.filter(
message => message =>
message.propsForMessage.timestamp === timestamp && message.propsForMessage.timestamp === timestamp &&
message.propsForMessage.sender === sender message.propsForMessage.sender === sender
); );
if (results.length) { if (!results.length) {
message = results[0];
} else {
const dbResult = ( const dbResult = (
await Data.getMessageBySenderAndTimestamp({ source: sender, timestamp }) await Data.getMessageBySenderAndTimestamp({ source: sender, timestamp })
)?.getMessageModelProps(); )?.getMessageModelProps();
if (dbResult) { if (dbResult) {
message = dbResult; results = [dbResult];
} }
} }
quotesProps[`${timestamp}-${sender}`] = message; quotesProps[`${timestamp}-${sender}`] = results[0];
} }
}); }
window.log.debug(`WIP: quoteProps`, quotesProps);
return { messagesProps, quotesProps }; return { messagesProps, quotesProps };
} }
@ -798,7 +801,7 @@ const conversationsSlice = createSlice({
firstUnreadIdOnOpen: string | undefined; firstUnreadIdOnOpen: string | undefined;
mostRecentMessageIdOnOpen: string | null; mostRecentMessageIdOnOpen: string | null;
initialMessages: Array<MessageModelPropsWithoutConvoProps>; initialMessages: Array<MessageModelPropsWithoutConvoProps>;
initialQuotes: Record<string, MessageModelPropsWithoutConvoProps>; initialQuotes: QuoteLookupType;
}> }>
) { ) {
// this is quite hacky, but we don't want to show the showScrollButton if we have only a small amount of messages, // this is quite hacky, but we don't want to show the showScrollButton if we have only a small amount of messages,
@ -850,7 +853,7 @@ const conversationsSlice = createSlice({
mostRecentMessageIdOnOpen: string | null; mostRecentMessageIdOnOpen: string | null;
initialMessages: Array<MessageModelPropsWithoutConvoProps>; initialMessages: Array<MessageModelPropsWithoutConvoProps>;
initialQuotes: Record<string, MessageModelPropsWithoutConvoProps>; initialQuotes: QuoteLookupType;
}> }>
) { ) {
return { return {

Loading…
Cancel
Save