Allow deleting scheduled messages.

This commit is contained in:
John Preston 2019-08-08 23:39:42 +01:00
parent 815a18be94
commit ea0a616453
5 changed files with 36 additions and 15 deletions

View File

@ -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<not_null<PeerData*>, QVector<MTPint>> idsByPeer;
base::flat_map<not_null<PeerData*>, QVector<MTPint>> 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<MTPint>(ids)
)).done([=, peer=peer](const MTPUpdates &updates) {
peer->session().api().applyUpdates(updates);
}).send();
}
const auto session = _session;
Ui::hideLayer();
session->data().sendHistoryChangeNotifications();

View File

@ -746,15 +746,11 @@ bool ListWidget::isSelectedAsGroup(
return applyTo.contains(item->fullId());
}
bool ListWidget::isGoodForSelection(not_null<HistoryItem*> item) const {
return IsServerMsgId(item->id) && !item->serviceMsg();
}
bool ListWidget::isGoodForSelection(
SelectedMap &applyTo,
not_null<HistoryItem*> 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<HistoryItem*> 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);
}
};

View File

@ -62,6 +62,7 @@ public:
int limitBefore,
int limitAfter) = 0;
virtual bool listAllowsMultiSelect() = 0;
virtual bool listIsItemGoodForSelection(not_null<HistoryItem*> item) = 0;
virtual bool listIsLessInOrder(
not_null<HistoryItem*> first,
not_null<HistoryItem*> second) = 0;
@ -338,7 +339,6 @@ private:
TextSelection selection);
int itemMinimalHeight() const;
bool isGoodForSelection(not_null<HistoryItem*> item) const;
bool isGoodForSelection(
SelectedMap &applyTo,
not_null<HistoryItem*> item,

View File

@ -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<HistoryItem*> item) {
return !item->isSending() && !item->hasFailed();
}
bool ScheduledWidget::listIsLessInOrder(
not_null<HistoryItem*> first,
not_null<HistoryItem*> second) {
@ -407,13 +413,15 @@ void ScheduledWidget::confirmDeleteSelected() {
if (items.empty()) {
return;
}
//const auto weak = make_weak(this);
//const auto box = Ui::show(Box<DeleteMessagesBox>(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<DeleteMessagesBox>(
&_history->session(),
std::move(items)));
box->setDeleteConfirmedCallback([=] {
if (const auto strong = weak.data()) {
strong->clearSelected();
}
});
}
void ScheduledWidget::clearSelected() {

View File

@ -76,6 +76,7 @@ public:
int limitBefore,
int limitAfter) override;
bool listAllowsMultiSelect() override;
bool listIsItemGoodForSelection(not_null<HistoryItem*> item) override;
bool listIsLessInOrder(
not_null<HistoryItem*> first,
not_null<HistoryItem*> second) override;