mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 04:45:08 +01:00
Management: Fix chat history being deleted along with deleted contact (#1632)
This commit is contained in:
parent
34933fd064
commit
9251b468a5
@ -28,7 +28,7 @@ export {
|
||||
|
||||
export {
|
||||
fetchFullUser, fetchNearestCountry, fetchTopUsers, fetchContactList, fetchUsers,
|
||||
addContact, updateContact, deleteUser, fetchProfilePhotos, fetchCommonChats,
|
||||
addContact, updateContact, deleteContact, fetchProfilePhotos, fetchCommonChats,
|
||||
} from './users';
|
||||
|
||||
export {
|
||||
|
@ -181,7 +181,7 @@ export function addContact({
|
||||
}), true);
|
||||
}
|
||||
|
||||
export async function deleteUser({
|
||||
export async function deleteContact({
|
||||
id,
|
||||
accessHash,
|
||||
}: {
|
||||
@ -200,7 +200,7 @@ export async function deleteUser({
|
||||
}
|
||||
|
||||
onUpdate({
|
||||
'@type': 'deleteUser',
|
||||
'@type': 'deleteContact',
|
||||
id,
|
||||
});
|
||||
}
|
||||
|
@ -758,7 +758,7 @@ export function updater(update: Update, originRequest?: GramJs.AnyRequest) {
|
||||
.filter((e) => e instanceof GramJs.User && !e.contact)
|
||||
.forEach((user) => {
|
||||
onUpdate({
|
||||
'@type': 'deleteUser',
|
||||
'@type': 'deleteContact',
|
||||
id: buildApiPeerId(user.id, 'user'),
|
||||
});
|
||||
});
|
||||
|
@ -284,8 +284,8 @@ export type ApiUpdateDraftMessage = {
|
||||
replyingToId?: number;
|
||||
};
|
||||
|
||||
export type ApiDeleteUser = {
|
||||
'@type': 'deleteUser';
|
||||
export type ApiDeleteContact = {
|
||||
'@type': 'deleteContact';
|
||||
id: string;
|
||||
};
|
||||
|
||||
@ -433,7 +433,7 @@ export type ApiUpdate = (
|
||||
ApiUpdateNewMessage | ApiUpdateMessage | ApiUpdateThreadInfo | ApiUpdateCommonBoxMessages | ApiUpdateChannelMessages |
|
||||
ApiUpdateDeleteMessages | ApiUpdateMessagePoll | ApiUpdateMessagePollVote | ApiUpdateDeleteHistory |
|
||||
ApiUpdateMessageSendSucceeded | ApiUpdateMessageSendFailed | ApiUpdateServiceNotification |
|
||||
ApiDeleteUser | ApiUpdateUser | ApiUpdateUserStatus | ApiUpdateUserFullInfo | ApiUpdateDeleteProfilePhotos |
|
||||
ApiDeleteContact | ApiUpdateUser | ApiUpdateUserStatus | ApiUpdateUserFullInfo | ApiUpdateDeleteProfilePhotos |
|
||||
ApiUpdateAvatar | ApiUpdateMessageImage | ApiUpdateDraftMessage |
|
||||
ApiUpdateError | ApiUpdateResetContacts |
|
||||
ApiUpdateFavoriteStickers | ApiUpdateStickerSet |
|
||||
|
@ -4,7 +4,7 @@ import React, {
|
||||
} from '../../../lib/teact/teact';
|
||||
import { getDispatch, withGlobal } from '../../../lib/teact/teactn';
|
||||
|
||||
import { ApiChat, ApiUser } from '../../../api/types';
|
||||
import { ApiUser } from '../../../api/types';
|
||||
import { ManagementProgress } from '../../../types';
|
||||
|
||||
import {
|
||||
@ -33,7 +33,6 @@ type OwnProps = {
|
||||
|
||||
type StateProps = {
|
||||
user?: ApiUser;
|
||||
chat: ApiChat;
|
||||
progress?: ManagementProgress;
|
||||
isMuted?: boolean;
|
||||
};
|
||||
@ -43,7 +42,6 @@ const ERROR_FIRST_NAME_MISSING = 'Please provide first name';
|
||||
const ManageUser: FC<OwnProps & StateProps> = ({
|
||||
userId,
|
||||
user,
|
||||
chat,
|
||||
progress,
|
||||
isMuted,
|
||||
onClose,
|
||||
@ -51,10 +49,8 @@ const ManageUser: FC<OwnProps & StateProps> = ({
|
||||
}) => {
|
||||
const {
|
||||
updateContact,
|
||||
deleteUser,
|
||||
deleteHistory,
|
||||
deleteContact,
|
||||
closeManagement,
|
||||
openChat,
|
||||
} = getDispatch();
|
||||
|
||||
const [isDeleteDialogOpen, openDeleteDialog, closeDeleteDialog] = useFlag();
|
||||
@ -125,15 +121,10 @@ const ManageUser: FC<OwnProps & StateProps> = ({
|
||||
}, [firstName, lastName, updateContact, userId, isNotificationsEnabled]);
|
||||
|
||||
const handleDeleteContact = useCallback(() => {
|
||||
deleteHistory({
|
||||
chatId: chat.id,
|
||||
shouldDeleteForAll: false,
|
||||
});
|
||||
deleteUser({ userId });
|
||||
deleteContact({ userId });
|
||||
closeDeleteDialog();
|
||||
closeManagement();
|
||||
openChat({ id: undefined });
|
||||
}, [chat.id, closeDeleteDialog, closeManagement, deleteHistory, deleteUser, openChat, userId]);
|
||||
}, [closeDeleteDialog, closeManagement, deleteContact, userId]);
|
||||
|
||||
if (!user) {
|
||||
return undefined;
|
||||
@ -213,7 +204,7 @@ export default memo(withGlobal<OwnProps>(
|
||||
const isMuted = selectIsChatMuted(chat, selectNotifySettings(global), selectNotifyExceptions(global));
|
||||
|
||||
return {
|
||||
user, chat, progress, isMuted,
|
||||
user, progress, isMuted,
|
||||
};
|
||||
},
|
||||
)(ManageUser));
|
||||
|
@ -529,7 +529,7 @@ export type ActionTypes = (
|
||||
// users
|
||||
'loadFullUser' | 'openUserInfo' | 'loadNearestCountry' | 'loadTopUsers' | 'loadContactList' |
|
||||
'loadCurrentUser' | 'updateProfile' | 'checkUsername' | 'addContact' | 'updateContact' |
|
||||
'deleteUser' | 'loadUser' | 'setUserSearchQuery' | 'loadCommonChats' |
|
||||
'deleteContact' | 'loadUser' | 'setUserSearchQuery' | 'loadCommonChats' |
|
||||
// chat creation
|
||||
'createChannel' | 'createGroupChat' | 'resetChatCreation' |
|
||||
// settings
|
||||
|
@ -114,10 +114,10 @@ addReducer('updateContact', (global, actions, payload) => {
|
||||
void updateContact(userId, isMuted, firstName, lastName);
|
||||
});
|
||||
|
||||
addReducer('deleteUser', (global, actions, payload) => {
|
||||
addReducer('deleteContact', (global, actions, payload) => {
|
||||
const { userId } = payload!;
|
||||
|
||||
void deleteUser(userId);
|
||||
void deleteContact(userId);
|
||||
});
|
||||
|
||||
async function loadTopUsers() {
|
||||
@ -210,7 +210,7 @@ async function updateContact(
|
||||
setGlobal(updateManagementProgress(getGlobal(), ManagementProgress.Complete));
|
||||
}
|
||||
|
||||
async function deleteUser(userId: string) {
|
||||
async function deleteContact(userId: string) {
|
||||
const global = getGlobal();
|
||||
const user = selectUser(global, userId);
|
||||
|
||||
@ -220,7 +220,7 @@ async function deleteUser(userId: string) {
|
||||
|
||||
const { id, accessHash } = user;
|
||||
|
||||
await callApi('deleteUser', { id, accessHash });
|
||||
await callApi('deleteContact', { id, accessHash });
|
||||
}
|
||||
|
||||
addReducer('loadProfilePhotos', (global, actions, payload) => {
|
||||
|
@ -2,7 +2,7 @@ import { addReducer, getGlobal, setGlobal } from '../../../lib/teact/teactn';
|
||||
|
||||
import { ApiUpdate, ApiUserStatus } from '../../../api/types';
|
||||
|
||||
import { deleteUser, replaceUserStatuses, updateUser } from '../../reducers';
|
||||
import { deleteContact, replaceUserStatuses, updateUser } from '../../reducers';
|
||||
import { throttle } from '../../../util/schedulers';
|
||||
|
||||
const STATUS_UPDATE_THROTTLE = 3000;
|
||||
@ -29,8 +29,8 @@ function flushStatusUpdates() {
|
||||
|
||||
addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
switch (update['@type']) {
|
||||
case 'deleteUser': {
|
||||
return deleteUser(global, update.id);
|
||||
case 'deleteContact': {
|
||||
return deleteContact(global, update.id);
|
||||
}
|
||||
|
||||
case 'updateUser': {
|
||||
|
@ -136,10 +136,9 @@ export function updateSelectedUserId(global: GlobalState, selectedId?: string):
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteUser(global: GlobalState, userId: string): GlobalState {
|
||||
export function deleteContact(global: GlobalState, userId: string): GlobalState {
|
||||
const { byId } = global.users;
|
||||
const { userIds } = global.contactList || {};
|
||||
delete byId[userId];
|
||||
|
||||
global = {
|
||||
...global,
|
||||
@ -148,7 +147,13 @@ export function deleteUser(global: GlobalState, userId: string): GlobalState {
|
||||
},
|
||||
};
|
||||
|
||||
return replaceUsers(global, byId);
|
||||
return replaceUsers(global, {
|
||||
...byId,
|
||||
[userId]: {
|
||||
...byId[userId],
|
||||
isContact: undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function updateUserSearch(
|
||||
|
Loading…
Reference in New Issue
Block a user