Fix deleting message history

This commit is contained in:
Alexander Zinchuk 2022-09-21 00:14:50 +02:00
parent 312cb02ce6
commit e65b078df8
3 changed files with 11 additions and 10 deletions

View File

@ -676,7 +676,7 @@ export async function deleteScheduledMessages({
}
export async function deleteHistory({
chat, shouldDeleteForAll, maxId,
chat, shouldDeleteForAll,
}: {
chat: ApiChat; shouldDeleteForAll?: boolean; maxId?: number;
}) {
@ -685,13 +685,11 @@ export async function deleteHistory({
isChannel
? new GramJs.channels.DeleteHistory({
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
maxId,
})
: new GramJs.messages.DeleteHistory({
peer: buildInputPeer(chat.id, chat.accessHash),
...(shouldDeleteForAll && { revoke: true }),
...(!shouldDeleteForAll && { just_clear: true }),
maxId,
}),
);
@ -699,6 +697,11 @@ export async function deleteHistory({
return;
}
if ('offset' in result && result.offset) {
await deleteHistory({ chat, shouldDeleteForAll });
return;
}
onUpdate({
'@type': 'deleteHistory',
chatId: chat.id,

View File

@ -72,7 +72,7 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
const lang = useLang();
const chatTitle = getChatTitle(lang, chat);
const handleDeleteMessageForAll = useCallback(() => {
const handleDeleteForAll = useCallback(() => {
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
onClose();
@ -152,7 +152,7 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
return 'DeleteChatUser';
}
function renderMessage() {
function renderContent() {
if (isChannel && chat.isCreator) {
return (
<p>
@ -191,14 +191,14 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
onClose={onClose}
onCloseAnimationEnd={onCloseAnimationEnd}
>
{renderMessage()}
{renderContent()}
{isBot && (
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteAndStop}>
{lang('DeleteAndStop')}
</Button>
)}
{canDeleteForAll && (
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteMessageForAll}>
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteForAll}>
{contactName ? renderText(lang('ChatList.DeleteForEveryone', contactName)) : lang('DeleteForAll')}
</Button>
)}

View File

@ -449,9 +449,7 @@ addActionHandler('deleteHistory', async (global, actions, payload) => {
return;
}
const maxId = chat.lastMessage?.id;
await callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
await callApi('deleteHistory', { chat, shouldDeleteForAll });
const activeChat = selectCurrentMessageList(global);
if (activeChat && activeChat.chatId === chatId) {