Delete Chat Modal: Fix incorrect behaviour
This commit is contained in:
parent
92cdf9feb5
commit
46dadbeb51
@ -117,7 +117,7 @@ export function buildInputChannel(channelId: string, accessHash?: string): GramJ
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function buildInputChat(chatId: string) {
|
export function buildInputChat(chatId: string) {
|
||||||
return BigInt(chatId);
|
return BigInt(chatId.slice(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildInputPaidReactionPrivacy(isPrivate?: boolean, peerId?: string): GramJs.TypePaidReactionPrivacy {
|
export function buildInputPaidReactionPrivacy(isPrivate?: boolean, peerId?: string): GramJs.TypePaidReactionPrivacy {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { FC } from '../../lib/teact/teact';
|
import type { FC } from '../../lib/teact/teact';
|
||||||
import React, { memo, useCallback } from '../../lib/teact/teact';
|
import React, { memo } from '../../lib/teact/teact';
|
||||||
import { getActions, withGlobal } from '../../global';
|
import { getActions, withGlobal } from '../../global';
|
||||||
|
|
||||||
import type { ApiChat } from '../../api/types';
|
import type { ApiChat } from '../../api/types';
|
||||||
@ -17,6 +17,7 @@ import {
|
|||||||
import { selectIsChatWithSelf, selectUser } from '../../global/selectors';
|
import { selectIsChatWithSelf, selectUser } from '../../global/selectors';
|
||||||
import renderText from './helpers/renderText';
|
import renderText from './helpers/renderText';
|
||||||
|
|
||||||
|
import useLastCallback from '../../hooks/useLastCallback';
|
||||||
import useOldLang from '../../hooks/useOldLang';
|
import useOldLang from '../../hooks/useOldLang';
|
||||||
|
|
||||||
import Button from '../ui/Button';
|
import Button from '../ui/Button';
|
||||||
@ -68,58 +69,57 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
|
|||||||
deleteChannel,
|
deleteChannel,
|
||||||
deleteChatUser,
|
deleteChatUser,
|
||||||
blockUser,
|
blockUser,
|
||||||
|
deleteChat,
|
||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
const lang = useOldLang();
|
const lang = useOldLang();
|
||||||
const chatTitle = getChatTitle(lang, chat);
|
const chatTitle = getChatTitle(lang, chat);
|
||||||
|
|
||||||
const handleDeleteForAll = useCallback(() => {
|
const handleDeleteForAll = useLastCallback(() => {
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
}, [chat.id, onClose]);
|
});
|
||||||
|
|
||||||
const handleDeleteAndStop = useCallback(() => {
|
const handleDeleteAndStop = useLastCallback(() => {
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
||||||
blockUser({ userId: chat.id });
|
blockUser({ userId: chat.id });
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
}, [chat.id, onClose]);
|
});
|
||||||
|
|
||||||
const handleDeleteChat = useCallback(() => {
|
const handleDeleteChat = useLastCallback(() => {
|
||||||
if (isSavedDialog) {
|
if (isSavedDialog) {
|
||||||
deleteSavedHistory({ chatId: chat.id });
|
deleteSavedHistory({ chatId: chat.id });
|
||||||
} else if (isPrivateChat) {
|
} else if (isPrivateChat) {
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
||||||
} else if (isBasicGroup) {
|
} else if (isBasicGroup) {
|
||||||
deleteChatUser({ chatId: chat.id, userId: currentUserId! });
|
if (chat.isCreator) {
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
||||||
|
deleteChat({ chatId: chat.id });
|
||||||
|
} else {
|
||||||
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
||||||
|
deleteChatUser({ chatId: chat.id, userId: currentUserId! });
|
||||||
|
}
|
||||||
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
|
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
|
||||||
leaveChannel({ chatId: chat.id });
|
leaveChannel({ chatId: chat.id });
|
||||||
} else if ((isChannel || isSuperGroup) && chat.isCreator) {
|
} else if ((isChannel || isSuperGroup) && chat.isCreator) {
|
||||||
deleteChannel({ chatId: chat.id });
|
deleteChannel({ chatId: chat.id });
|
||||||
}
|
}
|
||||||
onClose();
|
onClose();
|
||||||
}, [
|
});
|
||||||
isPrivateChat,
|
|
||||||
isBasicGroup,
|
|
||||||
isChannel,
|
|
||||||
isSuperGroup,
|
|
||||||
currentUserId,
|
|
||||||
chat.isCreator,
|
|
||||||
chat.id,
|
|
||||||
isSavedDialog,
|
|
||||||
onClose,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const handleLeaveChat = useCallback(() => {
|
const handleLeaveChat = useLastCallback(() => {
|
||||||
if (isChannel || isSuperGroup) {
|
if (isChannel || isSuperGroup) {
|
||||||
leaveChannel({ chatId: chat.id });
|
leaveChannel({ chatId: chat.id });
|
||||||
onClose();
|
onClose();
|
||||||
|
} else if (isBasicGroup && chat.isCreator) {
|
||||||
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
||||||
|
deleteChatUser({ chatId: chat.id, userId: currentUserId! });
|
||||||
} else {
|
} else {
|
||||||
handleDeleteChat();
|
handleDeleteChat();
|
||||||
}
|
}
|
||||||
}, [chat.id, handleDeleteChat, isChannel, isSuperGroup, leaveChannel, onClose]);
|
});
|
||||||
|
|
||||||
function renderHeader() {
|
function renderHeader() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user