diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -51,11 +51,15 @@ KeyserverStore, KeyserverInfo, } from 'lib/types/keyserver-types.js'; -import { messageTypes } from 'lib/types/message-types-enum.js'; +import { + messageTypes, + type MessageType, +} from 'lib/types/message-types-enum.js'; import { type LocalMessageInfo, type MessageStore, type MessageStoreThreads, + type RawMessageInfo, } from 'lib/types/message-types.js'; import type { ReportStore, @@ -480,17 +484,19 @@ // 3. Unshim translated `RawMessageInfos` to get the TOGGLE_PIN messages const unshimmedRawMessageInfos = rawMessageInfos.map(messageInfo => - unshimFunc(messageInfo, new Set([messageTypes.TOGGLE_PIN])), + unshimFunc(messageInfo, new Set([messageTypes.TOGGLE_PIN])), ); // 4. Filter out non-TOGGLE_PIN messages - const filteredRawMessageInfos = unshimmedRawMessageInfos.filter( - messageInfo => messageInfo.type === messageTypes.TOGGLE_PIN, - ); + const filteredRawMessageInfos = unshimmedRawMessageInfos + .map(messageInfo => + messageInfo.type === messageTypes.TOGGLE_PIN ? messageInfo : null, + ) + .filter(Boolean); // 5. We want only the last TOGGLE_PIN message for each message ID, // so 'pin', 'unpin', 'pin' don't count as 3 pins, but only 1. - const lastMessageIDToRawMessageInfoMap = new Map(); + const lastMessageIDToRawMessageInfoMap = new Map(); for (const messageInfo of filteredRawMessageInfos) { const { targetMessageID } = messageInfo; lastMessageIDToRawMessageInfoMap.set(targetMessageID, messageInfo); @@ -500,7 +506,7 @@ ); // 6. Create a Map of threadIDs to pinnedCount - const threadIDsToPinnedCount = new Map(); + const threadIDsToPinnedCount = new Map(); for (const messageInfo of lastMessageIDToRawMessageInfos) { const { threadID, type } = messageInfo; if (type === messageTypes.TOGGLE_PIN) {