Chat List: Fix deleted chat being stuck at the bottom (#3127)
This commit is contained in:
parent
43eb7e7020
commit
ec8e99127b
@ -242,7 +242,7 @@ const SettingsFoldersEdit: FC<OwnProps & StateProps> = ({
|
||||
|
||||
const isExpanded = mode === 'included' ? isIncludedChatsListExpanded : isExcludedChatsListExpanded;
|
||||
const allChatIds = mode === 'included' ? includedChatIds : excludedChatIds;
|
||||
const leftChatsCount = allChatIds.length - selectedChatTypes.length - visibleChatIds.length;
|
||||
const leftChatsCount = allChatIds.length - visibleChatIds.length;
|
||||
const clickHandler = mode === 'included'
|
||||
? () => setIsIncludedChatsListExpanded(true)
|
||||
: () => setIsExcludedChatsListExpanded(true);
|
||||
|
||||
@ -327,7 +327,10 @@ addActionHandler('loadFullChat', (global, actions, payload): ActionReturnType =>
|
||||
});
|
||||
|
||||
addActionHandler('loadTopChats', (global): ActionReturnType => {
|
||||
runThrottledForLoadTopChats(() => loadChats(global, 'active'));
|
||||
runThrottledForLoadTopChats(() => {
|
||||
loadChats(global, 'active');
|
||||
loadChats(global, 'archived');
|
||||
});
|
||||
});
|
||||
|
||||
addActionHandler('requestChatUpdate', (global, actions, payload): ActionReturnType => {
|
||||
|
||||
@ -523,6 +523,26 @@ addActionHandler('deleteHistory', async (global, actions, payload): Promise<void
|
||||
if (activeChat && activeChat.chatId === chatId) {
|
||||
actions.openChat({ id: undefined, tabId });
|
||||
}
|
||||
|
||||
// Delete chat from folders
|
||||
const folders = global.chatFolders.byId;
|
||||
Object.values(folders).forEach((folder) => {
|
||||
if (folder.includedChatIds.includes(chatId) || folder.pinnedChatIds?.includes(chatId)) {
|
||||
const newIncludedChatIds = folder.includedChatIds.filter((id) => id !== chatId);
|
||||
const newPinnedChatIds = folder.pinnedChatIds?.filter((id) => id !== chatId);
|
||||
|
||||
const updatedFolder = {
|
||||
...folder,
|
||||
includedChatIds: newIncludedChatIds,
|
||||
pinnedChatIds: newPinnedChatIds,
|
||||
};
|
||||
|
||||
callApi('editChatFolder', {
|
||||
id: folder.id,
|
||||
folderUpdate: updatedFolder,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
addActionHandler('reportMessages', async (global, actions, payload): Promise<void> => {
|
||||
|
||||
@ -29,6 +29,7 @@ import {
|
||||
deleteTopic,
|
||||
updateMessageTranslations,
|
||||
clearMessageTranslation,
|
||||
removeChatFromChatLists,
|
||||
} from '../../reducers';
|
||||
import {
|
||||
selectChatMessage,
|
||||
@ -133,7 +134,7 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
|
||||
setGlobal(global);
|
||||
|
||||
// Edge case: New message in an old (not loaded) chat.
|
||||
// Reload dialogs if chat is not present in the list
|
||||
if (!selectIsChatListed(global, chatId)) {
|
||||
actions.loadTopChats();
|
||||
}
|
||||
@ -436,6 +437,10 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
||||
actions.requestChatUpdate({ chatId });
|
||||
}
|
||||
|
||||
global = getGlobal();
|
||||
global = removeChatFromChatLists(global, chatId);
|
||||
setGlobal(global);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import { ARCHIVED_FOLDER_ID } from '../../config';
|
||||
import {
|
||||
areSortedArraysEqual, buildCollectionByKey, omit, unique,
|
||||
} from '../../util/iteratees';
|
||||
import { selectChat, selectChatFullInfo, selectChatListType } from '../selectors';
|
||||
import { selectChat, selectChatFullInfo } from '../selectors';
|
||||
import { updateThread, updateThreadInfo } from './messages';
|
||||
import { areDeepEqual } from '../../util/areDeepEqual';
|
||||
|
||||
@ -275,22 +275,22 @@ export function updateChatListSecondaryInfo<T extends GlobalState>(
|
||||
}
|
||||
|
||||
export function leaveChat<T extends GlobalState>(global: T, leftChatId: string): T {
|
||||
const listType = selectChatListType(global, leftChatId);
|
||||
if (!listType) {
|
||||
return global;
|
||||
}
|
||||
|
||||
const { [listType]: listIds } = global.chats.listIds;
|
||||
|
||||
if (listIds) {
|
||||
global = replaceChatListIds(global, listType, listIds.filter((listId) => listId !== leftChatId));
|
||||
}
|
||||
global = removeChatFromChatLists(global, leftChatId);
|
||||
|
||||
global = updateChat(global, leftChatId, { isNotJoined: true });
|
||||
|
||||
return global;
|
||||
}
|
||||
|
||||
export function removeChatFromChatLists<T extends GlobalState>(global: T, chatId: string): T {
|
||||
const lists = global.chats.listIds;
|
||||
Object.entries(lists).forEach(([listType, listIds]) => {
|
||||
global = replaceChatListIds(global, listType as keyof typeof lists, listIds.filter((id) => id !== chatId));
|
||||
});
|
||||
|
||||
return global;
|
||||
}
|
||||
|
||||
export function addChatMembers<T extends GlobalState>(global: T, chat: ApiChat, membersToAdd: ApiChatMember[]): T {
|
||||
const currentMembers = selectChatFullInfo(global, chat.id)?.members;
|
||||
const newMemberIds = new Set(membersToAdd.map((m) => m.userId));
|
||||
|
||||
@ -362,7 +362,9 @@ function updateChats(
|
||||
|
||||
const newAllFolderListIds = global.chats.listIds.active;
|
||||
const newArchivedFolderListIds = global.chats.listIds.archived;
|
||||
let allIds = [...newAllFolderListIds || [], ...newArchivedFolderListIds || []];
|
||||
|
||||
const newAllIds = [...newAllFolderListIds || [], ...newArchivedFolderListIds || []];
|
||||
let allIds = newAllIds;
|
||||
if (newAllFolderListIds !== prevAllFolderListIds || newArchivedFolderListIds !== prevArchivedFolderListIds) {
|
||||
allIds = unique(allIds.concat(prevAllFolderListIds || [], prevArchivedFolderListIds || []));
|
||||
}
|
||||
@ -383,7 +385,11 @@ function updateChats(
|
||||
let newFolderIds: number[];
|
||||
if (chat) {
|
||||
const currentSummary = prepared.chatSummariesById.get(chatId);
|
||||
const newSummary = buildChatSummary(chat, newNotifySettings, newNotifyExceptions, newUsersById[chatId]);
|
||||
const isRemoved = !newAllIds.includes(chatId);
|
||||
const newSummary = buildChatSummary(
|
||||
chat, newNotifySettings, newNotifyExceptions, newUsersById[chatId], isRemoved,
|
||||
);
|
||||
|
||||
if (!areFoldersChanged && currentSummary && arePropsShallowEqual(newSummary, currentSummary)) {
|
||||
return;
|
||||
}
|
||||
@ -423,6 +429,7 @@ function buildChatSummary(
|
||||
notifySettings: NotifySettings,
|
||||
notifyExceptions?: Record<number, NotifyException>,
|
||||
user?: ApiUser,
|
||||
isRemoved?: boolean,
|
||||
): ChatSummary {
|
||||
const {
|
||||
id, type, lastMessage, isRestricted, isNotJoined, migratedTo, folderId,
|
||||
@ -447,7 +454,7 @@ function buildChatSummary(
|
||||
return {
|
||||
id,
|
||||
type,
|
||||
isListed: Boolean(!isRestricted && !isNotJoined && !migratedTo && !shouldHideServiceChat),
|
||||
isListed: Boolean(!isRestricted && !isNotJoined && !migratedTo && !shouldHideServiceChat && !isRemoved),
|
||||
isArchived: folderId === ARCHIVED_FOLDER_ID,
|
||||
isMuted: selectIsChatMuted(chat, notifySettings, notifyExceptions),
|
||||
isUnread: Boolean(unreadCount || unreadMentionsCount || hasUnreadMark),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user