2021-09-28 21:23:58 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "base/timer.h"
|
|
|
|
|
|
|
|
class ApiWrap;
|
|
|
|
class PeerData;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
|
|
|
|
class ViewsManager final {
|
|
|
|
public:
|
|
|
|
explicit ViewsManager(not_null<ApiWrap*> api);
|
|
|
|
|
|
|
|
void scheduleIncrement(not_null<HistoryItem*> item);
|
|
|
|
void removeIncremented(not_null<PeerData*> peer);
|
|
|
|
|
2022-09-12 14:18:31 +00:00
|
|
|
void pollExtendedMedia(not_null<HistoryItem*> item);
|
|
|
|
|
2021-09-28 21:23:58 +00:00
|
|
|
private:
|
2022-09-12 14:18:31 +00:00
|
|
|
struct PollExtendedMediaRequest {
|
|
|
|
crl::time when = 0;
|
|
|
|
mtpRequestId id = 0;
|
|
|
|
base::flat_set<MsgId> ids;
|
|
|
|
base::flat_set<MsgId> sent;
|
|
|
|
};
|
|
|
|
|
2021-09-28 21:23:58 +00:00
|
|
|
void viewsIncrement();
|
2022-09-12 14:18:31 +00:00
|
|
|
void sendPollRequests();
|
|
|
|
void sendPollRequests(
|
|
|
|
const base::flat_map<
|
|
|
|
not_null<PeerData*>,
|
|
|
|
QVector<MTPint>> &prepared);
|
2021-09-28 21:23:58 +00:00
|
|
|
|
|
|
|
void done(
|
|
|
|
QVector<MTPint> ids,
|
|
|
|
const MTPmessages_MessageViews &result,
|
|
|
|
mtpRequestId requestId);
|
|
|
|
void fail(const MTP::Error &error, mtpRequestId requestId);
|
|
|
|
|
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
MTP::Sender _api;
|
|
|
|
|
|
|
|
base::flat_map<not_null<PeerData*>, base::flat_set<MsgId>> _incremented;
|
|
|
|
base::flat_map<not_null<PeerData*>, base::flat_set<MsgId>> _toIncrement;
|
|
|
|
base::flat_map<not_null<PeerData*>, mtpRequestId> _incrementRequests;
|
|
|
|
base::flat_map<mtpRequestId, not_null<PeerData*>> _incrementByRequest;
|
|
|
|
base::Timer _incrementTimer;
|
|
|
|
|
2022-09-12 14:18:31 +00:00
|
|
|
base::flat_map<
|
|
|
|
not_null<PeerData*>,
|
|
|
|
PollExtendedMediaRequest> _pollRequests;
|
|
|
|
base::Timer _pollTimer;
|
|
|
|
|
2021-09-28 21:23:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Api
|