Skip to content

Commit

Permalink
fix: pinned chats are toggled as selected when editing folder
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenii-minkov committed Dec 14, 2023
1 parent fdd5c31 commit 01e5dc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/global/actions/api/chats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,12 @@ addActionHandler('editChatFolders', (global, actions, payload): ActionReturnType
const limit = selectCurrentLimit(global, 'dialogFiltersChats');

const isLimitReached = idsToAdd
.some((id) => selectChatFolder(global, id)!.includedChatIds.length >= limit);
.some((id) => {
const { includedChatIds, pinnedChatIds } = selectChatFolder(global, id);
const totalChatsInFolder = (includedChatIds?.length || 0) + (pinnedChatIds?.length || 0);

return totalChatsInFolder >= limit;
});
if (isLimitReached) {
actions.openLimitReachedModal({ limit: 'dialogFiltersChats', tabId });
return;
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/reducers/useFoldersReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const EXCLUDED_CHAT_TYPES: FolderChatType[] = [
];

const INCLUDE_FILTER_FIELDS: Array<keyof FolderIncludeFilters> = [
'includedChatIds', 'bots', 'channels', 'groups', 'contacts', 'nonContacts',
'includedChatIds', 'pinnedChatIds', 'bots', 'channels', 'groups', 'contacts', 'nonContacts',
];
const EXCLUDE_FILTER_FIELDS: Array<keyof FolderExcludeFilters> = [
'excludedChatIds', 'excludeArchived', 'excludeMuted', 'excludeRead',
Expand All @@ -42,6 +42,7 @@ export function selectChatFilters(state: FoldersState, mode: 'included' | 'exclu
if (mode === 'included') {
const {
includedChatIds,
pinnedChatIds,
...includeFilters
} = selectTemp
? state.includeFilters || {}
Expand All @@ -50,7 +51,7 @@ export function selectChatFilters(state: FoldersState, mode: 'included' | 'exclu
INCLUDE_FILTER_FIELDS,
);

selectedChatIds = includedChatIds || [];
selectedChatIds = (includedChatIds || []).concat(pinnedChatIds || []);
selectedChatTypes = (Object.keys(includeFilters) as Array<keyof typeof includeFilters>)
.filter((key) => Boolean(includeFilters[key]));
} else {
Expand Down Expand Up @@ -106,7 +107,7 @@ function getSuggestedFolderName(includeFilters?: FolderIncludeFilters) {
}

type FolderIncludeFilters = Pick<ApiChatFolder, (
'includedChatIds' | 'bots' | 'channels' | 'groups' | 'contacts' | 'nonContacts'
'includedChatIds' | 'pinnedChatIds' | 'bots' | 'channels' | 'groups' | 'contacts' | 'nonContacts'
)>;
type FolderExcludeFilters = Pick<ApiChatFolder, 'excludedChatIds' | 'excludeArchived' | 'excludeMuted' | 'excludeRead'>;

Expand Down

0 comments on commit 01e5dc0

Please sign in to comment.