From bbfb55f211631bb863de522b8cb8ceb07f7a4622 Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 30 Aug 2022 11:53:35 +1000 Subject: [PATCH] fix: pr review fixes --- ts/components/dialog/ReactListModal.tsx | 9 +- .../sogsv3/sogsV3MutationCache.ts | 100 ++++++++---------- 2 files changed, 50 insertions(+), 59 deletions(-) diff --git a/ts/components/dialog/ReactListModal.tsx b/ts/components/dialog/ReactListModal.tsx index d833bbff2..cc2257e0a 100644 --- a/ts/components/dialog/ReactListModal.tsx +++ b/ts/components/dialog/ReactListModal.tsx @@ -216,15 +216,17 @@ const handleSenders = (senders: Array, me: string) => { export const ReactListModal = (props: Props): ReactElement => { const { reaction, messageId } = props; + const dispatch = useDispatch(); const [reactions, setReactions] = useState([]); const reactionsMap = (reactions && Object.fromEntries(reactions)) || {}; const [currentReact, setCurrentReact] = useState(''); const [reactAriaLabel, setReactAriaLabel] = useState(); const [count, setCount] = useState(null); const [senders, setSenders] = useState>([]); - const me = UserUtils.getOurPubKeyStrFromCache(); const msgProps = useMessageReactsPropsById(messageId); + const weAreModerator = useWeAreModerator(msgProps?.convoId); + const me = UserUtils.getOurPubKeyStrFromCache(); // tslint:disable: cyclomatic-complexity useEffect(() => { @@ -281,10 +283,7 @@ export const ReactListModal = (props: Props): ReactElement => { return <>; } - const dispatch = useDispatch(); - - const { convoId, isPublic } = msgProps; - const weAreModerator = useWeAreModerator(convoId); + const { isPublic } = msgProps; const handleSelectedReaction = (emoji: string): boolean => { return currentReact === emoji; diff --git a/ts/session/apis/open_group_api/sogsv3/sogsV3MutationCache.ts b/ts/session/apis/open_group_api/sogsv3/sogsV3MutationCache.ts index 90f5d442d..3c90a66b9 100644 --- a/ts/session/apis/open_group_api/sogsv3/sogsV3MutationCache.ts +++ b/ts/session/apis/open_group_api/sogsv3/sogsV3MutationCache.ts @@ -57,10 +57,8 @@ export function updateMutationCache(entry: SogsV3Mutation, seqno: number) { } else { const entryIndex = findIndex(sogsMutationCache, entry); if (entryIndex >= 0) { - const updatedEntry = entry; - updatedEntry.seqno = seqno; - sogsMutationCache[entryIndex] = updatedEntry; - window.log.info('SOGS Mutation Cache: Entry updated!', updatedEntry); + sogsMutationCache[entryIndex].seqno = seqno; + window.log.info('SOGS Mutation Cache: Entry updated!', sogsMutationCache[entryIndex]); } else { window.log.error('SOGS Mutation Cache: Updated failed! Cannot find entry', entry); } @@ -75,63 +73,57 @@ export async function processMessagesUsingCache( const updatedReactions = message.reactions; const roomMatches: Array = filter(sogsMutationCache, { server, room }); - if (roomMatches?.length) { - for (const roomMatch of roomMatches) { - if (message.seqno && roomMatch.seqno && roomMatch.seqno <= message.seqno) { - const removedEntry = remove(sogsMutationCache, roomMatch); - window.log.info('SOGS Mutation Cache: Entry ignored and removed!', removedEntry); - } else if ( - !message.seqno || - (message.seqno && roomMatch.seqno && roomMatch.seqno > message.seqno) - ) { - for (const reaction of Object.keys(message.reactions)) { - const reactionMatches = filter(sogsMutationCache, { - server, - room, - changeType: ChangeType.REACTIONS, - metadata: { - messageId: message.id, - emoji: reaction, - }, - }); - if (reactionMatches?.length) { - for (const reactionMatch of reactionMatches) { - switch (reactionMatch.metadata.action) { - case 'ADD': - updatedReactions[reaction].you = true; - updatedReactions[reaction].count += 1; - window.log.info( - 'SOGS Mutation Cache: Added our reaction based on the cache', - updatedReactions[reaction] - ); - break; - case 'REMOVE': - updatedReactions[reaction].you = false; - updatedReactions[reaction].count -= 1; - window.log.info( - 'SOGS Mutation Cache: Removed our reaction based on the cache', - updatedReactions[reaction] - ); - break; - default: - window.log.warn( - 'SOGS Mutation Cache: Unsupported metadata action in OpenGroupMessageV4', - reactionMatch - ); - } - } + for (const roomMatch of roomMatches) { + if (message.seqno && roomMatch.seqno && roomMatch.seqno <= message.seqno) { + const removedEntry = remove(sogsMutationCache, roomMatch); + window.log.info('SOGS Mutation Cache: Entry ignored and removed!', removedEntry); + } else if ( + !message.seqno || + (message.seqno && roomMatch.seqno && roomMatch.seqno > message.seqno) + ) { + for (const reaction of Object.keys(message.reactions)) { + const reactionMatches = filter(sogsMutationCache, { + server, + room, + changeType: ChangeType.REACTIONS, + metadata: { + messageId: message.id, + emoji: reaction, + }, + }); - const removedMatches = remove(sogsMutationCache, ...roomMatches); - window.log.info( - 'SOGS Mutation Cache: Removed processed entries from cache!', - removedMatches - ); + for (const reactionMatch of reactionMatches) { + switch (reactionMatch.metadata.action) { + case 'ADD': + updatedReactions[reaction].you = true; + updatedReactions[reaction].count += 1; + window.log.info( + 'SOGS Mutation Cache: Added our reaction based on the cache', + updatedReactions[reaction] + ); + break; + case 'REMOVE': + updatedReactions[reaction].you = false; + updatedReactions[reaction].count -= 1; + window.log.info( + 'SOGS Mutation Cache: Removed our reaction based on the cache', + updatedReactions[reaction] + ); + break; + default: + window.log.warn( + 'SOGS Mutation Cache: Unsupported metadata action in OpenGroupMessageV4', + reactionMatch + ); } } } } } + const removedMatches = remove(sogsMutationCache, ...roomMatches); + window.log.info('SOGS Mutation Cache: Removed processed entries from cache!', removedMatches); + message.reactions = updatedReactions; await handleOpenGroupMessageReactions(message.reactions, message.id); }