mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Handle report_delivery_until_date.
This commit is contained in:
parent
0d821c3630
commit
6cfbccd955
3 changed files with 67 additions and 0 deletions
|
@ -32,6 +32,7 @@ namespace Data {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kReadRequestTimeout = 3 * crl::time(1000);
|
constexpr auto kReadRequestTimeout = 3 * crl::time(1000);
|
||||||
|
constexpr auto kReportDeliveriesPerRequest = 50;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -566,6 +567,58 @@ void Histories::sendPendingReadInbox(not_null<History*> history) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Histories::reportDelivery(not_null<HistoryItem*> item) {
|
||||||
|
auto &set = _pendingDeliveryReport[item->history()->peer];
|
||||||
|
if (!set.emplace(item->id).second) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
crl::on_main(&session(), [=] {
|
||||||
|
reportPendingDeliveries();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Histories::reportPendingDeliveries() {
|
||||||
|
auto &pending = _pendingDeliveryReport;
|
||||||
|
for (auto i = begin(pending); i != end(pending);) {
|
||||||
|
auto &[peer, ids] = *i;
|
||||||
|
auto list = QVector<MTPint>();
|
||||||
|
if (_deliveryReportSent.contains(peer)) {
|
||||||
|
++i;
|
||||||
|
continue;
|
||||||
|
} else if (ids.size() > kReportDeliveriesPerRequest) {
|
||||||
|
const auto count = kReportDeliveriesPerRequest;
|
||||||
|
list.reserve(count);
|
||||||
|
for (auto j = begin(ids), till = j + count; j != till; ++j) {
|
||||||
|
list.push_back(MTP_int(*j));
|
||||||
|
}
|
||||||
|
ids.erase(begin(ids), begin(ids) + count);
|
||||||
|
} else if (!ids.empty()) {
|
||||||
|
list.reserve(ids.size());
|
||||||
|
for (const auto &id : ids) {
|
||||||
|
list.push_back(MTP_int(id));
|
||||||
|
}
|
||||||
|
ids.clear();
|
||||||
|
}
|
||||||
|
if (ids.empty()) {
|
||||||
|
i = pending.erase(i);
|
||||||
|
} else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
_deliveryReportSent.emplace(peer);
|
||||||
|
const auto finish = [=] {
|
||||||
|
_deliveryReportSent.remove(peer);
|
||||||
|
if (_pendingDeliveryReport.contains(peer)) {
|
||||||
|
reportPendingDeliveries();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
session().api().request(MTPmessages_ReportMessagesDelivery(
|
||||||
|
MTP_flags(0),
|
||||||
|
peer->input,
|
||||||
|
MTP_vector(std::move(list))
|
||||||
|
)).done(finish).fail(finish).send();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Histories::sendReadRequests() {
|
void Histories::sendReadRequests() {
|
||||||
DEBUG_LOG(("Reading: send requests with count %1.").arg(_states.size()));
|
DEBUG_LOG(("Reading: send requests with count %1.").arg(_states.size()));
|
||||||
if (_states.empty()) {
|
if (_states.empty()) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
void readInboxOnNewMessage(not_null<HistoryItem*> item);
|
void readInboxOnNewMessage(not_null<HistoryItem*> item);
|
||||||
void readClientSideMessage(not_null<HistoryItem*> item);
|
void readClientSideMessage(not_null<HistoryItem*> item);
|
||||||
void sendPendingReadInbox(not_null<History*> history);
|
void sendPendingReadInbox(not_null<History*> history);
|
||||||
|
void reportDelivery(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
void requestDialogEntry(not_null<Data::Folder*> folder);
|
void requestDialogEntry(not_null<Data::Folder*> folder);
|
||||||
void requestDialogEntry(
|
void requestDialogEntry(
|
||||||
|
@ -201,6 +202,7 @@ private:
|
||||||
void postponeRequestDialogEntries();
|
void postponeRequestDialogEntries();
|
||||||
|
|
||||||
void sendDialogRequests();
|
void sendDialogRequests();
|
||||||
|
void reportPendingDeliveries();
|
||||||
|
|
||||||
[[nodiscard]] bool isCreatingTopic(
|
[[nodiscard]] bool isCreatingTopic(
|
||||||
not_null<History*> history,
|
not_null<History*> history,
|
||||||
|
@ -236,6 +238,11 @@ private:
|
||||||
base::flat_map<FullMsgId, MsgId> _createdTopicIds;
|
base::flat_map<FullMsgId, MsgId> _createdTopicIds;
|
||||||
base::flat_set<mtpRequestId> _creatingTopicRequests;
|
base::flat_set<mtpRequestId> _creatingTopicRequests;
|
||||||
|
|
||||||
|
base::flat_map<
|
||||||
|
not_null<PeerData*>,
|
||||||
|
base::flat_set<MsgId>> _pendingDeliveryReport;
|
||||||
|
base::flat_set<not_null<PeerData*>> _deliveryReportSent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
|
@ -59,6 +59,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
#include "data/data_chat.h"
|
#include "data/data_chat.h"
|
||||||
#include "data/data_game.h"
|
#include "data/data_game.h"
|
||||||
|
#include "data/data_histories.h"
|
||||||
#include "data/data_history_messages.h"
|
#include "data/data_history_messages.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_group_call.h" // Data::GroupCall::id().
|
#include "data/data_group_call.h" // Data::GroupCall::id().
|
||||||
|
@ -449,6 +450,12 @@ HistoryItem::HistoryItem(
|
||||||
Get<HistoryMessageFactcheck>()->data = check;
|
Get<HistoryMessageFactcheck>()->data = check;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (const auto until = data.vreport_delivery_until_date()) {
|
||||||
|
if (base::unixtime::now() < TimeId(until->v)) {
|
||||||
|
history->owner().histories().reportDelivery(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryItem::HistoryItem(
|
HistoryItem::HistoryItem(
|
||||||
|
|
Loading…
Add table
Reference in a new issue