Skip to content

Commit

Permalink
Revert "[lib] Extract getSidebarItems"
Browse files Browse the repository at this point in the history
This reverts commit 4816903.
  • Loading branch information
Ashoat committed Dec 10, 2024
1 parent 00bb994 commit d5b919b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 75 deletions.
63 changes: 58 additions & 5 deletions lib/selectors/chat-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ import {
sortMessageInfoList,
} from '../shared/message-utils.js';
import { messageSpecs } from '../shared/messages/message-specs.js';
import {
getSidebarItems,
type SidebarItem,
} from '../shared/sidebar-item-utils.js';
import { threadInChatList, threadIsPending } from '../shared/thread-utils.js';
import { messageTypes } from '../types/message-types-enum.js';
import {
Expand All @@ -43,15 +39,32 @@ import type {
} from '../types/minimally-encoded-thread-permissions-types.js';
import type { BaseAppState } from '../types/redux-types.js';
import { threadTypeIsSidebar } from '../types/thread-types-enum.js';
import {
maxReadSidebars,
maxUnreadSidebars,
type SidebarInfo,
} from '../types/thread-types.js';
import type {
AccountUserInfo,
RelativeUserInfo,
UserInfo,
} from '../types/user-types.js';
import { threeDays } from '../utils/date-utils.js';
import type { EntityText } from '../utils/entity-text.js';
import memoize2 from '../utils/memoize.js';
import { useSelector } from '../utils/redux-utils.js';

export type SidebarItem =
| {
...SidebarInfo,
+type: 'sidebar',
}
| {
+type: 'seeMore',
+unread: boolean,
}
| { +type: 'spacer' };

export type ChatThreadItem = {
+type: 'chatThreadItem',
+threadInfo: ThreadInfo,
Expand Down Expand Up @@ -108,7 +121,47 @@ function useCreateChatThreadItem(): ThreadInfo => ChatThreadItem {
? Math.max(lastUpdatedTime, allSidebarItems[0].lastUpdatedTime)
: lastUpdatedTime;

const sidebarItems = getSidebarItems(allSidebarItems);
const numUnreadSidebars = allSidebarItems.filter(
sidebar => sidebar.threadInfo.currentUser.unread,
).length;
let numReadSidebarsToShow = maxReadSidebars - numUnreadSidebars;
const threeDaysAgo = Date.now() - threeDays;

const sidebarItems: SidebarItem[] = [];
for (const sidebar of allSidebarItems) {
if (sidebarItems.length >= maxUnreadSidebars) {
break;
} else if (sidebar.threadInfo.currentUser.unread) {
sidebarItems.push(sidebar);
} else if (
sidebar.lastUpdatedTime > threeDaysAgo &&
numReadSidebarsToShow > 0
) {
sidebarItems.push(sidebar);
numReadSidebarsToShow--;
}
}

const numReadButRecentSidebars = allSidebarItems.filter(
sidebar =>
!sidebar.threadInfo.currentUser.unread &&
sidebar.lastUpdatedTime > threeDaysAgo,
).length;
if (
sidebarItems.length < numUnreadSidebars + numReadButRecentSidebars ||
(sidebarItems.length < allSidebarItems.length &&
sidebarItems.length > 0)
) {
sidebarItems.push({
type: 'seeMore',
unread: numUnreadSidebars > maxUnreadSidebars,
});
}
if (sidebarItems.length !== 0) {
sidebarItems.push({
type: 'spacer',
});
}

return {
type: 'chatThreadItem',
Expand Down
68 changes: 0 additions & 68 deletions lib/shared/sidebar-item-utils.js

This file was deleted.

6 changes: 4 additions & 2 deletions lib/shared/thread-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { getUserAvatarForThread } from './avatar-utils.js';
import { generatePendingThreadColor } from './color-utils.js';
import { extractUserMentionsFromText } from './mention-utils.js';
import { relationshipBlockedInEitherDirection } from './relationship-utils.js';
import type { SidebarItem } from './sidebar-item-utils.js';
import ashoat from '../facts/ashoat.js';
import genesis from '../facts/genesis.js';
import { useLoggedInUserInfo } from '../hooks/account-hooks.js';
Expand All @@ -31,7 +30,10 @@ import {
getAllThreadPermissions,
makePermissionsBlob,
} from '../permissions/thread-permissions.js';
import type { ChatThreadItem } from '../selectors/chat-selectors.js';
import type {
ChatThreadItem,
SidebarItem,
} from '../selectors/chat-selectors.js';
import {
threadInfoSelector,
pendingToRealizedThreadIDsSelector,
Expand Down

0 comments on commit d5b919b

Please sign in to comment.