Added handler for SCHEDULE_STATUS_PRIVATE error when send file.

This commit is contained in:
23rd 2020-01-26 21:32:19 +03:00 committed by John Preston
parent ef5055f4f3
commit e7fbcce9d9
3 changed files with 29 additions and 0 deletions

View File

@ -579,6 +579,13 @@ void ApiWrap::sendMessageFail(
requestFullPeer(peer);
}
}
} else if (error.type() == qstr("SCHEDULE_STATUS_PRIVATE")) {
auto &scheduled = _session->data().scheduledMessages();
Assert(peer->isUser());
if (const auto item = scheduled.lookupItem(peer->id, itemId.msg)) {
scheduled.removeSending(item);
Ui::show(Box<InformBox>(tr::lng_cant_do_this(tr::now)));
}
}
if (const auto item = _session->data().message(itemId)) {
Assert(randomId != 0);

View File

@ -112,6 +112,27 @@ MsgId ScheduledMessages::lookupId(not_null<HistoryItem*> item) const {
return j->second;
}
HistoryItem *ScheduledMessages::lookupItem(PeerId peer, MsgId msg) const {
const auto history = _session->data().historyLoaded(peer);
if (!history) {
return nullptr;
}
const auto i = _data.find(history);
if (i == end(_data)) {
return nullptr;
}
const auto &items = i->second.items;
const auto j = ranges::find_if(items, [&](auto &item) {
return item->id == msg;
});
if (j == end(items)) {
return nullptr;
}
return (*j).get();
}
int ScheduledMessages::count(not_null<History*> history) const {
const auto i = _data.find(history);
return (i != end(_data)) ? i->second.items.size() : 0;

View File

@ -29,6 +29,7 @@ public:
~ScheduledMessages();
[[nodiscard]] MsgId lookupId(not_null<HistoryItem*> item) const;
[[nodiscard]] HistoryItem *lookupItem(PeerId peer, MsgId msg) const;
[[nodiscard]] int count(not_null<History*> history) const;
void checkEntitiesAndUpdate(const MTPDmessage &data);