Fix deleting message history
This commit is contained in:
parent
312cb02ce6
commit
e65b078df8
@ -676,7 +676,7 @@ export async function deleteScheduledMessages({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteHistory({
|
export async function deleteHistory({
|
||||||
chat, shouldDeleteForAll, maxId,
|
chat, shouldDeleteForAll,
|
||||||
}: {
|
}: {
|
||||||
chat: ApiChat; shouldDeleteForAll?: boolean; maxId?: number;
|
chat: ApiChat; shouldDeleteForAll?: boolean; maxId?: number;
|
||||||
}) {
|
}) {
|
||||||
@ -685,13 +685,11 @@ export async function deleteHistory({
|
|||||||
isChannel
|
isChannel
|
||||||
? new GramJs.channels.DeleteHistory({
|
? new GramJs.channels.DeleteHistory({
|
||||||
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
channel: buildInputEntity(chat.id, chat.accessHash) as GramJs.InputChannel,
|
||||||
maxId,
|
|
||||||
})
|
})
|
||||||
: new GramJs.messages.DeleteHistory({
|
: new GramJs.messages.DeleteHistory({
|
||||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||||
...(shouldDeleteForAll && { revoke: true }),
|
...(shouldDeleteForAll && { revoke: true }),
|
||||||
...(!shouldDeleteForAll && { just_clear: true }),
|
...(!shouldDeleteForAll && { just_clear: true }),
|
||||||
maxId,
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -699,6 +697,11 @@ export async function deleteHistory({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('offset' in result && result.offset) {
|
||||||
|
await deleteHistory({ chat, shouldDeleteForAll });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onUpdate({
|
onUpdate({
|
||||||
'@type': 'deleteHistory',
|
'@type': 'deleteHistory',
|
||||||
chatId: chat.id,
|
chatId: chat.id,
|
||||||
|
|||||||
@ -72,7 +72,7 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
|
|||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
const chatTitle = getChatTitle(lang, chat);
|
const chatTitle = getChatTitle(lang, chat);
|
||||||
|
|
||||||
const handleDeleteMessageForAll = useCallback(() => {
|
const handleDeleteForAll = useCallback(() => {
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
@ -152,7 +152,7 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
|
|||||||
return 'DeleteChatUser';
|
return 'DeleteChatUser';
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMessage() {
|
function renderContent() {
|
||||||
if (isChannel && chat.isCreator) {
|
if (isChannel && chat.isCreator) {
|
||||||
return (
|
return (
|
||||||
<p>
|
<p>
|
||||||
@ -191,14 +191,14 @@ const DeleteChatModal: FC<OwnProps & StateProps> = ({
|
|||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onCloseAnimationEnd={onCloseAnimationEnd}
|
onCloseAnimationEnd={onCloseAnimationEnd}
|
||||||
>
|
>
|
||||||
{renderMessage()}
|
{renderContent()}
|
||||||
{isBot && (
|
{isBot && (
|
||||||
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteAndStop}>
|
<Button color="danger" className="confirm-dialog-button" isText onClick={handleDeleteAndStop}>
|
||||||
{lang('DeleteAndStop')}
|
{lang('DeleteAndStop')}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{canDeleteForAll && (
|
{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')}
|
{contactName ? renderText(lang('ChatList.DeleteForEveryone', contactName)) : lang('DeleteForAll')}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -449,9 +449,7 @@ addActionHandler('deleteHistory', async (global, actions, payload) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxId = chat.lastMessage?.id;
|
await callApi('deleteHistory', { chat, shouldDeleteForAll });
|
||||||
|
|
||||||
await callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
|
|
||||||
|
|
||||||
const activeChat = selectCurrentMessageList(global);
|
const activeChat = selectCurrentMessageList(global);
|
||||||
if (activeChat && activeChat.chatId === chatId) {
|
if (activeChat && activeChat.chatId === chatId) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user