diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -1190,39 +1190,37 @@ usersSearchResults: $ReadOnlyArray, viewerID: ?string, ): $ReadOnlyArray { - const chatItems = []; if (!searchText) { - chatItems.push( - ...chatListData.filter( - item => - threadIsTopLevel(item.threadInfo) && threadFilter(item.threadInfo), - ), + return chatListData.filter( + item => + threadIsTopLevel(item.threadInfo) && threadFilter(item.threadInfo), ); - } else { - const privateThreads = []; - const personalThreads = []; - const otherThreads = []; - for (const item of chatListData) { - if (!threadSearchResults.has(item.threadInfo.id)) { - continue; - } - if (item.threadInfo.type === threadTypes.PRIVATE) { - privateThreads.push({ ...item, sidebars: [] }); - } else if (item.threadInfo.type === threadTypes.PERSONAL) { - personalThreads.push({ ...item, sidebars: [] }); - } else { - otherThreads.push({ ...item, sidebars: [] }); - } + } + + const privateThreads = []; + const personalThreads = []; + const otherThreads = []; + for (const item of chatListData) { + if (!threadSearchResults.has(item.threadInfo.id)) { + continue; } - chatItems.push(...privateThreads, ...personalThreads, ...otherThreads); - if (viewerID) { - chatItems.push( - ...usersSearchResults.map(user => - createPendingThreadItem(viewerID, user), - ), - ); + if (item.threadInfo.type === threadTypes.PRIVATE) { + privateThreads.push({ ...item, sidebars: [] }); + } else if (item.threadInfo.type === threadTypes.PERSONAL) { + personalThreads.push({ ...item, sidebars: [] }); + } else { + otherThreads.push({ ...item, sidebars: [] }); } } + + const chatItems = [...privateThreads, ...personalThreads, ...otherThreads]; + if (viewerID) { + chatItems.push( + ...usersSearchResults.map(user => + createPendingThreadItem(viewerID, user), + ), + ); + } return chatItems; }