Skip to content

Commit d12571b

Browse files
committed
refactor: clean up SidebarRoomListGroup type by removing unnecessary comments and simplifying room category handling
1 parent 761ba96 commit d12571b

1 file changed

Lines changed: 2 additions & 25 deletions

File tree

apps/meteor/client/sidebar/hooks/useRoomList.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,15 @@ type GroupUnreadInfo = {
4040
};
4141

4242
export type SidebarRoomListGroup = {
43-
/** Collapse/show-unreads identity: translation key for system groups, category id for custom ones. */
4443
key: string;
45-
/** Raw title — a translation key for system groups (translate it), the category name for custom ones. */
4644
title: string;
4745
translateTitle: boolean;
4846
category?: ISidebarCustomCategory;
4947
showUnreads: boolean;
50-
/** When opened, whether unread rooms are sorted to the top of the category. */
5148
keepUnreadsOnTop: boolean;
5249
collapsed: boolean;
53-
/** Rooms to render — already filtered for collapse + "Show unreads". */
5450
rooms: SubscriptionWithRoom[];
5551
unreadInfo: GroupUnreadInfo;
56-
/** A custom category with no rooms (renders the empty placeholder). */
5752
empty: boolean;
5853
};
5954

@@ -68,9 +63,7 @@ export const isUnreadRoom = (room: SubscriptionWithRoom): boolean =>
6863

6964
export const useRoomList = ({ collapsedGroups }: { collapsedGroups?: string[] }): useRoomListReturnType => {
7065
const showOmnichannel = useOmnichannelEnabled();
71-
// "Types" grouping toggle: on = Teams/Channels/Discussions/DMs; off = everything in "Conversations".
7266
const sidebarGroupByType = useUserPreference('sidebarGroupByType');
73-
// "Group by" checkboxes: group favorites into a "Favorites" group / unread rooms into an "Unread" group.
7467
const favoritesEnabled = useUserPreference<boolean>('sidebarShowFavorites', true);
7568
const sidebarOrder = useUserPreference<typeof SYSTEM_GROUP_KEYS>('sidebarSectionsOrder') ?? SYSTEM_GROUP_KEYS;
7669
const isDiscussionEnabled = useSetting('Discussion_enabled');
@@ -106,18 +99,10 @@ export const useRoomList = ({ collapsedGroups }: { collapsedGroups?: string[] })
10699
const conversation = new Set<SubscriptionWithRoom>();
107100
const onHold = new Set<SubscriptionWithRoom>();
108101

109-
// Seed an empty set for each custom category.
110-
const roomToCategory = new Map<string, string>();
111102
const customSets = new Map<string, Set<SubscriptionWithRoom>>();
112103
customCategories.forEach((category) => {
113104
customSets.set(category._id, new Set<SubscriptionWithRoom>());
114105
});
115-
// Build the rid → categoryId map from the subscription's `category` field.
116-
rooms.forEach((room) => {
117-
if (room.category && customSets.has(room.category)) {
118-
roomToCategory.set(room.rid, room.category);
119-
}
120-
});
121106

122107
rooms.forEach((room) => {
123108
if (room.archived) {
@@ -128,21 +113,15 @@ export const useRoomList = ({ collapsedGroups }: { collapsedGroups?: string[] })
128113
return incomingCall.add(room);
129114
}
130115

131-
// "Unread" grouping has priority over everything below, including custom categories.
132116
if (sidebarShowUnread && isUnreadRoom(room)) {
133117
return unread.add(room);
134118
}
135119

136-
// A room in a custom category is shown only there (exclusive with everything below).
137-
// "keep unreads on top" handles unread emphasis within the category.
138-
// When custom categories are hidden, the room falls through.
139-
const categoryId = roomToCategory.get(room.rid);
140-
if (categoryId && customSets.has(categoryId)) {
141-
customSets.get(categoryId)?.add(room);
120+
if (room.category && customSets.has(room.category)) {
121+
customSets.get(room.category)?.add(room);
142122
return;
143123
}
144124

145-
// "Favorites" grouping: gated by its own "Group by" checkbox.
146125
if (favoritesEnabled && room.f) {
147126
return favorite.add(room);
148127
}
@@ -184,7 +163,6 @@ export const useRoomList = ({ collapsedGroups }: { collapsedGroups?: string[] })
184163
showOmnichannel && omnichannel.size && groups.set('Open_Livechats', omnichannel);
185164
showOmnichannel && onHold.size && groups.set('On_Hold_Chats', onHold);
186165

187-
// "Unread" grouping renders only when the toggle is on and there are unread rooms.
188166
sidebarShowUnread && unread.size && groups.set('Unread', unread);
189167

190168
favoritesEnabled && (hasLicenseModule || favorite.size > 0) && groups.set('Favorites', favorite);
@@ -255,7 +233,6 @@ export const useRoomList = ({ collapsedGroups }: { collapsedGroups?: string[] })
255233
};
256234
};
257235

258-
// Custom categories render above the system groups and persist even when empty — unless hidden.
259236
const customGroups = customCategories.map((category) =>
260237
makeGroup(category._id, category.name, false, customSets.get(category._id) ?? new Set<SubscriptionWithRoom>(), category),
261238
);

0 commit comments

Comments
 (0)