fix: pr review fixes

pull/2454/head
William Grant 3 years ago
parent b33ea096b4
commit bbfb55f211

@ -216,15 +216,17 @@ const handleSenders = (senders: Array<string>, me: string) => {
export const ReactListModal = (props: Props): ReactElement => { export const ReactListModal = (props: Props): ReactElement => {
const { reaction, messageId } = props; const { reaction, messageId } = props;
const dispatch = useDispatch();
const [reactions, setReactions] = useState<SortedReactionList>([]); const [reactions, setReactions] = useState<SortedReactionList>([]);
const reactionsMap = (reactions && Object.fromEntries(reactions)) || {}; const reactionsMap = (reactions && Object.fromEntries(reactions)) || {};
const [currentReact, setCurrentReact] = useState(''); const [currentReact, setCurrentReact] = useState('');
const [reactAriaLabel, setReactAriaLabel] = useState<string | undefined>(); const [reactAriaLabel, setReactAriaLabel] = useState<string | undefined>();
const [count, setCount] = useState<number | null>(null); const [count, setCount] = useState<number | null>(null);
const [senders, setSenders] = useState<Array<string>>([]); const [senders, setSenders] = useState<Array<string>>([]);
const me = UserUtils.getOurPubKeyStrFromCache();
const msgProps = useMessageReactsPropsById(messageId); const msgProps = useMessageReactsPropsById(messageId);
const weAreModerator = useWeAreModerator(msgProps?.convoId);
const me = UserUtils.getOurPubKeyStrFromCache();
// tslint:disable: cyclomatic-complexity // tslint:disable: cyclomatic-complexity
useEffect(() => { useEffect(() => {
@ -281,10 +283,7 @@ export const ReactListModal = (props: Props): ReactElement => {
return <></>; return <></>;
} }
const dispatch = useDispatch(); const { isPublic } = msgProps;
const { convoId, isPublic } = msgProps;
const weAreModerator = useWeAreModerator(convoId);
const handleSelectedReaction = (emoji: string): boolean => { const handleSelectedReaction = (emoji: string): boolean => {
return currentReact === emoji; return currentReact === emoji;

@ -57,10 +57,8 @@ export function updateMutationCache(entry: SogsV3Mutation, seqno: number) {
} else { } else {
const entryIndex = findIndex(sogsMutationCache, entry); const entryIndex = findIndex(sogsMutationCache, entry);
if (entryIndex >= 0) { if (entryIndex >= 0) {
const updatedEntry = entry; sogsMutationCache[entryIndex].seqno = seqno;
updatedEntry.seqno = seqno; window.log.info('SOGS Mutation Cache: Entry updated!', sogsMutationCache[entryIndex]);
sogsMutationCache[entryIndex] = updatedEntry;
window.log.info('SOGS Mutation Cache: Entry updated!', updatedEntry);
} else { } else {
window.log.error('SOGS Mutation Cache: Updated failed! Cannot find entry', entry); 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 updatedReactions = message.reactions;
const roomMatches: Array<SogsV3Mutation> = filter(sogsMutationCache, { server, room }); const roomMatches: Array<SogsV3Mutation> = filter(sogsMutationCache, { server, room });
if (roomMatches?.length) { for (const roomMatch of roomMatches) {
for (const roomMatch of roomMatches) { if (message.seqno && roomMatch.seqno && roomMatch.seqno <= message.seqno) {
if (message.seqno && roomMatch.seqno && roomMatch.seqno <= message.seqno) { const removedEntry = remove(sogsMutationCache, roomMatch);
const removedEntry = remove(sogsMutationCache, roomMatch); window.log.info('SOGS Mutation Cache: Entry ignored and removed!', removedEntry);
window.log.info('SOGS Mutation Cache: Entry ignored and removed!', removedEntry); } else if (
} else if ( !message.seqno ||
!message.seqno || (message.seqno && roomMatch.seqno && roomMatch.seqno > message.seqno)
(message.seqno && roomMatch.seqno && roomMatch.seqno > message.seqno) ) {
) { for (const reaction of Object.keys(message.reactions)) {
for (const reaction of Object.keys(message.reactions)) { const reactionMatches = filter(sogsMutationCache, {
const reactionMatches = filter(sogsMutationCache, { server,
server, room,
room, changeType: ChangeType.REACTIONS,
changeType: ChangeType.REACTIONS, metadata: {
metadata: { messageId: message.id,
messageId: message.id, emoji: reaction,
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
);
}
}
const removedMatches = remove(sogsMutationCache, ...roomMatches); for (const reactionMatch of reactionMatches) {
window.log.info( switch (reactionMatch.metadata.action) {
'SOGS Mutation Cache: Removed processed entries from cache!', case 'ADD':
removedMatches 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; message.reactions = updatedReactions;
await handleOpenGroupMessageReactions(message.reactions, message.id); await handleOpenGroupMessageReactions(message.reactions, message.id);
} }

Loading…
Cancel
Save