diff --git a/lib/hooks/sidebar-hooks.js b/lib/hooks/sidebar-hooks.js --- a/lib/hooks/sidebar-hooks.js +++ b/lib/hooks/sidebar-hooks.js @@ -44,7 +44,9 @@ mostRecentNonLocalMessage, }); } - result[parentID] = _orderBy('lastUpdatedTime')('desc')(sidebarInfos); + result[parentID] = _orderBy('lastUpdatedAtLeastTime')('desc')( + sidebarInfos, + ); } return result; }, [childThreadInfoByParentID, messageStore, getLastUpdatedTimes]); diff --git a/lib/selectors/chat-selectors.js b/lib/selectors/chat-selectors.js --- a/lib/selectors/chat-selectors.js +++ b/lib/selectors/chat-selectors.js @@ -115,12 +115,13 @@ : lastUpdatedAtLeastTime; const lastUpdatedTimeIncludingSidebars = (async () => { - if (sidebars.length === 0) { - return await lastUpdatedTime; - } - const [lastUpdatedTimeResult, sidebarLastUpdatedTimeResult] = - await Promise.all([lastUpdatedTime, sidebars[0].lastUpdatedTime]); - return Math.max(lastUpdatedTimeResult, sidebarLastUpdatedTimeResult); + const lastUpdatedTimePromises = [ + lastUpdatedTime, + ...sidebars.map(sidebar => sidebar.lastUpdatedTime), + ]; + const lastUpdatedTimes = await Promise.all(lastUpdatedTimePromises); + const max = lastUpdatedTimes.reduce((a, b) => Math.max(a, b), -1); + return max; })(); const allInitialSidebarItems = getAllInitialSidebarItems(sidebars); diff --git a/lib/shared/sidebar-item-utils.js b/lib/shared/sidebar-item-utils.js --- a/lib/shared/sidebar-item-utils.js +++ b/lib/shared/sidebar-item-utils.js @@ -1,5 +1,7 @@ // @flow +import _orderBy from 'lodash/fp/orderBy.js'; + import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; import { maxReadSidebars, @@ -94,7 +96,8 @@ lastUpdatedTime: finalLastUpdatedTime, }; }); - return await Promise.all(allSidebarItemPromises); + const sidebarItems = await Promise.all(allSidebarItemPromises); + return _orderBy('lastUpdatedTime')('desc')(sidebarItems); } export { getSidebarItems, getAllInitialSidebarItems, getAllFinalSidebarItems };