diff --git a/lib/hooks/thread-time.js b/lib/hooks/thread-time.js --- a/lib/hooks/thread-time.js +++ b/lib/hooks/thread-time.js @@ -38,6 +38,10 @@ }; } + const mostRecentMessage = messageStore.messages[thread.messageIDs[0]]; + const lastUpdatedAtMostTime = + mostRecentMessage?.time ?? threadInfo.creationTime; + // We default to the most recent message time. // - This default will only be relevant in the case that // getLastUpdatedTime is implemented for every message in the loop @@ -48,9 +52,7 @@ // - We default to the most recent message time because the best // alternative is the thread creation time, but this is likely very // far in the past. - const mostRecentMessage = messageStore.messages[thread.messageIDs[0]]; - let lastUpdatedAtLeastTime = - mostRecentMessage?.time ?? threadInfo.creationTime; + let lastUpdatedAtLeastTime = lastUpdatedAtMostTime; const getLastUpdatedTimeParams = { threadInfo, @@ -60,7 +62,6 @@ }; let lastUpdatedTime: ?() => Promise<?number>; - let highestTimestamp: ?number; for (const messageID of thread.messageIDs) { const messageInfo = messageStore.messages[messageID]; if (!messageInfo) { @@ -75,16 +76,6 @@ ? getLastUpdatedTime(messageInfo, getLastUpdatedTimeParams) : messageInfo.time; - // We only need to consider the first positive number result because - // thread.messageIDs is ordered chronologically. - if ( - !highestTimestamp && - lastUpdatedTimeResult && - typeof lastUpdatedTimeResult === 'number' - ) { - highestTimestamp = lastUpdatedTimeResult; - } - // We rely on the fact that thread.messageIDs is ordered chronologically // (newest first) to chain together lastUpdatedTime. An older message's // lastUpdatedTime is only considered if all of the newer messages @@ -128,8 +119,6 @@ return lastUpdatedAtLeastTime; }; - const lastUpdatedAtMostTime = highestTimestamp ?? threadInfo.creationTime; - return { lastUpdatedAtLeastTime, lastUpdatedAtMostTime,