From fc5bfeaee1aeaec9c860b473a4c45fcbc2f109e1 Mon Sep 17 00:00:00 2001 From: Ireina <140869597+re-zero001@users.noreply.github.com> Date: Mon, 30 Mar 2026 21:50:29 +0800 Subject: [PATCH] feat: add clear deleted messages action for chats --- .../SourceFiles/ayu/data/ayu_database.cpp | 13 ++++++++ Telegram/SourceFiles/ayu/data/ayu_database.h | 1 + .../SourceFiles/ayu/data/messages_storage.cpp | 5 +++ .../SourceFiles/ayu/data/messages_storage.h | 1 + .../ayu/ui/context_menu/context_menu.cpp | 32 +++++++++++++++++++ .../ayu/ui/message_history/history_inner.cpp | 26 +++++++++++++++ 6 files changed, 78 insertions(+) diff --git a/Telegram/SourceFiles/ayu/data/ayu_database.cpp b/Telegram/SourceFiles/ayu/data/ayu_database.cpp index cda6a21935..211b3b728d 100644 --- a/Telegram/SourceFiles/ayu/data/ayu_database.cpp +++ b/Telegram/SourceFiles/ayu/data/ayu_database.cpp @@ -348,6 +348,19 @@ bool hasDeletedMessages(ID userId, ID dialogId, ID topicId) { } } +void clearDeletedMessages(ID userId, ID dialogId, ID topicId) { + try { + storage.remove_all( + where( + column(&DeletedMessage::userId) == userId and + column(&DeletedMessage::dialogId) == dialogId and + (column(&DeletedMessage::topicId) == topicId or topicId == 0) + ) + ); + } catch (std::exception &) { + } +} + template std::vector getAllT() { try { diff --git a/Telegram/SourceFiles/ayu/data/ayu_database.h b/Telegram/SourceFiles/ayu/data/ayu_database.h index c78c0e1b1c..b1103dc05e 100644 --- a/Telegram/SourceFiles/ayu/data/ayu_database.h +++ b/Telegram/SourceFiles/ayu/data/ayu_database.h @@ -28,6 +28,7 @@ bool hasRevisions(ID userId, ID dialogId, ID messageId); void addDeletedMessage(const DeletedMessage &message); std::vector getDeletedMessages(ID userId, ID dialogId, ID topicId, ID minId, ID maxId, int totalLimit, const std::string &searchQuery = ""); bool hasDeletedMessages(ID userId, ID dialogId, ID topicId); +void clearDeletedMessages(ID userId, ID dialogId, ID topicId); std::vector getAllRegexFilters(); RegexFilter getById(std::vector id); diff --git a/Telegram/SourceFiles/ayu/data/messages_storage.cpp b/Telegram/SourceFiles/ayu/data/messages_storage.cpp index bc827ba5cf..97f332a966 100644 --- a/Telegram/SourceFiles/ayu/data/messages_storage.cpp +++ b/Telegram/SourceFiles/ayu/data/messages_storage.cpp @@ -134,4 +134,9 @@ bool hasDeletedMessages(not_null peer, ID topicId) { return AyuDatabase::hasDeletedMessages(userId, getDialogIdFromPeer(peer), topicId); } +void clearDeletedMessages(not_null peer, ID topicId) { + const ID userId = peer->session().userId().bare & PeerId::kChatTypeMask; + AyuDatabase::clearDeletedMessages(userId, getDialogIdFromPeer(peer), topicId); +} + } diff --git a/Telegram/SourceFiles/ayu/data/messages_storage.h b/Telegram/SourceFiles/ayu/data/messages_storage.h index abb14f4abb..66935d9c4d 100644 --- a/Telegram/SourceFiles/ayu/data/messages_storage.h +++ b/Telegram/SourceFiles/ayu/data/messages_storage.h @@ -17,5 +17,6 @@ bool hasRevisions(not_null item); void addDeletedMessage(not_null item); std::vector getDeletedMessages(not_null peer, ID topicId, ID minId, ID maxId, int totalLimit, const QString &searchQuery = QString()); bool hasDeletedMessages(not_null peer, ID topicId); +void clearDeletedMessages(not_null peer, ID topicId); } diff --git a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp index e29d23fff2..9d4407403e 100644 --- a/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp +++ b/Telegram/SourceFiles/ayu/ui/context_menu/context_menu.cpp @@ -29,6 +29,7 @@ #include "data/data_search_controller.h" #include "data/data_session.h" #include "data/data_user.h" +#include "history/history.h" #include "history/history_item_components.h" #include "history/view/history_view_context_menu.h" #include "history/view/history_view_element.h" @@ -46,6 +47,33 @@ namespace AyuUi { namespace { +Fn ClearDeletedMessagesHandler(not_null controller, not_null peer, ID topicId) { + return [=] { + controller->show(Ui::MakeConfirmBox({ + .text = tr::ayu_ClearDeletedMessagesText(tr::now), + .confirmed = [=](Fn &&close) { + auto items = std::vector>(); + for (const auto &block : peer->owner().history(peer)->blocks) { + for (const auto &view : block->messages) { + const auto item = view->data(); + if (item->isDeleted() && (!topicId || (item->topicRootId().bare == topicId))) { + items.push_back(item); + } + } + } + AyuMessages::clearDeletedMessages(peer, topicId); + for (const auto item : items) { + item->destroy(); + } + close(); + }, + .confirmText = tr::ayu_ClearDeletedMessagesActionText(tr::now), + .cancelText = tr::lng_cancel(), + .confirmStyle = &st::attentionBoxButton, + })); + }; +} + void DeleteMyMessagesAfterConfirm(not_null peer) { const auto session = &peer->session(); @@ -211,6 +239,10 @@ void AddDeletedMessagesActions(PeerData *peerData, ->showSection(std::make_shared(peerData, nullptr, topicId)); }, &st::menuIconArchive); + addCallback( + tr::ayu_ClearDeletedMenuText(tr::now), + ClearDeletedMessagesHandler(sessionController, peerData, topicId), + &st::menuIconDelete); // todo view filters } diff --git a/Telegram/SourceFiles/ayu/ui/message_history/history_inner.cpp b/Telegram/SourceFiles/ayu/ui/message_history/history_inner.cpp index b8151bc6b0..4593bfe128 100644 --- a/Telegram/SourceFiles/ayu/ui/message_history/history_inner.cpp +++ b/Telegram/SourceFiles/ayu/ui/message_history/history_inner.cpp @@ -634,6 +634,17 @@ bool InnerWidget::elementHideTopicButton(not_null view) { } void InnerWidget::saveState(not_null memento) { + if (!_item) { + memento->setItems({}, {}, false, true); + memento->setSearchQuery(base::take(_searchQuery)); + _items.clear(); + _messageIds.clear(); + _itemsByData.clear(); + _upLoaded = false; + _downLoaded = true; + return; + } + for (auto &item : _items) { item.clearView(); } @@ -648,6 +659,21 @@ void InnerWidget::saveState(not_null memento) { } void InnerWidget::restoreState(not_null memento) { + if (!_item) { + _items.clear(); + _messageIds.clear(); + _itemsByData.clear(); + _itemDates.clear(); + _upLoaded = false; + _downLoaded = true; + _searchQuery = memento->takeSearchQuery(); + updateMinMaxIds(); + updateEmptyText(); + updateSize(); + preloadMore(Direction::Up); + return; + } + _items = memento->takeItems(); for (auto &item : _items) { item.refreshView(this);