From ea0a61645367ea59e764275fa3c5d14b493142b1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 8 Aug 2019 23:39:42 +0100 Subject: [PATCH] Allow deleting scheduled messages. --- Telegram/SourceFiles/boxes/confirm_box.cpp | 16 ++++++++++++++ .../history/view/history_view_list_widget.cpp | 10 +++------ .../history/view/history_view_list_widget.h | 2 +- .../view/history_view_scheduled_section.cpp | 22 +++++++++++++------ .../view/history_view_scheduled_section.h | 1 + 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 3d79848cbb..f83449b44a 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "window/window_session_controller.h" #include "storage/localstorage.h" +#include "data/data_scheduled_messages.h" #include "data/data_session.h" #include "data/data_photo.h" #include "data/data_channel.h" @@ -765,9 +766,15 @@ void DeleteMessagesBox::deleteAndClear() { } base::flat_map, QVector> idsByPeer; + base::flat_map, QVector> scheduledIdsByPeer; for (const auto itemId : _ids) { if (const auto item = _session->data().message(itemId)) { const auto history = item->history(); + if (item->isScheduled()) { + scheduledIdsByPeer[history->peer].push_back(MTP_int( + _session->data().scheduledMessages().lookupId(item))); + continue; + } const auto wasOnServer = IsServerMsgId(item->id); const auto wasLast = (history->lastMessage() == item); const auto wasInChats = (history->chatListMessage() == item); @@ -784,6 +791,15 @@ void DeleteMessagesBox::deleteAndClear() { for (const auto &[peer, ids] : idsByPeer) { peer->session().api().deleteMessages(peer, ids, revoke); } + for (const auto &[peer, ids] : scheduledIdsByPeer) { + peer->session().api().request(MTPmessages_DeleteScheduledMessages( + peer->input, + MTP_vector(ids) + )).done([=, peer=peer](const MTPUpdates &updates) { + peer->session().api().applyUpdates(updates); + }).send(); + } + const auto session = _session; Ui::hideLayer(); session->data().sendHistoryChangeNotifications(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 409b2d41f2..52a5c74db8 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -746,15 +746,11 @@ bool ListWidget::isSelectedAsGroup( return applyTo.contains(item->fullId()); } -bool ListWidget::isGoodForSelection(not_null item) const { - return IsServerMsgId(item->id) && !item->serviceMsg(); -} - bool ListWidget::isGoodForSelection( SelectedMap &applyTo, not_null item, int &totalCount) const { - if (!isGoodForSelection(item)) { + if (!_delegate->listIsItemGoodForSelection(item)) { return false; } else if (!applyTo.contains(item->fullId())) { ++totalCount; @@ -1814,14 +1810,14 @@ void ListWidget::updateDragSelection( const auto changeGroup = [&](not_null item, bool add) { if (const auto group = groups.find(item)) { for (const auto item : group->items) { - if (!isGoodForSelection(item)) { + if (!_delegate->listIsItemGoodForSelection(item)) { return; } } for (const auto item : group->items) { changeItem(item, add); } - } else if (isGoodForSelection(item)) { + } else if (_delegate->listIsItemGoodForSelection(item)) { changeItem(item, add); } }; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 83ff6e0d75..209c20b252 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -62,6 +62,7 @@ public: int limitBefore, int limitAfter) = 0; virtual bool listAllowsMultiSelect() = 0; + virtual bool listIsItemGoodForSelection(not_null item) = 0; virtual bool listIsLessInOrder( not_null first, not_null second) = 0; @@ -338,7 +339,6 @@ private: TextSelection selection); int itemMinimalHeight() const; - bool isGoodForSelection(not_null item) const; bool isGoodForSelection( SelectedMap &applyTo, not_null item, diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 7bd672442c..f60a89e7dc 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/special_buttons.h" +#include "boxes/confirm_box.h" #include "window/window_session_controller.h" #include "core/event_filter.h" #include "main/main_session.h" @@ -367,6 +368,11 @@ bool ScheduledWidget::listAllowsMultiSelect() { return true; } +bool ScheduledWidget::listIsItemGoodForSelection( + not_null item) { + return !item->isSending() && !item->hasFailed(); +} + bool ScheduledWidget::listIsLessInOrder( not_null first, not_null second) { @@ -407,13 +413,15 @@ void ScheduledWidget::confirmDeleteSelected() { if (items.empty()) { return; } - //const auto weak = make_weak(this); - //const auto box = Ui::show(Box(std::move(items))); - //box->setDeleteConfirmedCallback([=] { - // if (const auto strong = weak.data()) { - // strong->clearSelected(); - // } - //}); + const auto weak = make_weak(this); + const auto box = Ui::show(Box( + &_history->session(), + std::move(items))); + box->setDeleteConfirmedCallback([=] { + if (const auto strong = weak.data()) { + strong->clearSelected(); + } + }); } void ScheduledWidget::clearSelected() { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h index 21c9a13106..ee8ae326cf 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.h +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.h @@ -76,6 +76,7 @@ public: int limitBefore, int limitAfter) override; bool listAllowsMultiSelect() override; + bool listIsItemGoodForSelection(not_null item) override; bool listIsLessInOrder( not_null first, not_null second) override;