2021-09-26 18:24:47 +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 "history/history_item.h"
|
|
|
|
#include "base/timer.h"
|
2022-02-15 02:20:55 +00:00
|
|
|
#include "ui/image/image_location.h"
|
2021-09-26 18:24:47 +00:00
|
|
|
|
|
|
|
class History;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
class Session;
|
|
|
|
|
2021-12-31 12:47:23 +00:00
|
|
|
struct SponsoredFrom {
|
|
|
|
PeerData *peer = nullptr;
|
|
|
|
QString title;
|
|
|
|
bool isBroadcast = false;
|
|
|
|
bool isMegagroup = false;
|
|
|
|
bool isChannel = false;
|
|
|
|
bool isPublic = false;
|
|
|
|
bool isBot = false;
|
2021-12-31 13:05:20 +00:00
|
|
|
bool isExactPost = false;
|
2022-05-10 15:04:29 +00:00
|
|
|
bool isRecommended = false;
|
2022-02-15 02:20:55 +00:00
|
|
|
ImageWithLocation userpic;
|
2021-12-31 12:47:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SponsoredMessage {
|
2021-09-26 18:24:47 +00:00
|
|
|
QByteArray randomId;
|
2021-12-31 12:47:23 +00:00
|
|
|
SponsoredFrom from;
|
2021-09-26 18:24:47 +00:00
|
|
|
TextWithEntities textWithEntities;
|
|
|
|
History *history = nullptr;
|
2021-10-07 16:44:33 +00:00
|
|
|
MsgId msgId;
|
2021-12-23 16:48:36 +00:00
|
|
|
QString chatInviteHash;
|
2021-09-26 18:24:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SponsoredMessages final {
|
|
|
|
public:
|
2021-12-31 12:47:23 +00:00
|
|
|
struct Details {
|
2021-12-23 16:48:36 +00:00
|
|
|
std::optional<QString> hash;
|
2021-12-31 12:47:23 +00:00
|
|
|
PeerData *peer = nullptr;
|
|
|
|
MsgId msgId;
|
2021-12-23 16:48:36 +00:00
|
|
|
};
|
2021-09-26 18:24:47 +00:00
|
|
|
using RandomId = QByteArray;
|
|
|
|
explicit SponsoredMessages(not_null<Session*> owner);
|
|
|
|
SponsoredMessages(const SponsoredMessages &other) = delete;
|
|
|
|
SponsoredMessages &operator=(const SponsoredMessages &other) = delete;
|
|
|
|
~SponsoredMessages();
|
|
|
|
|
2021-11-03 11:49:48 +00:00
|
|
|
[[nodiscard]] bool canHaveFor(not_null<History*> history) const;
|
2021-09-26 18:24:47 +00:00
|
|
|
void request(not_null<History*> history);
|
|
|
|
[[nodiscard]] bool append(not_null<History*> history);
|
|
|
|
void clearItems(not_null<History*> history);
|
2021-12-31 12:47:23 +00:00
|
|
|
[[nodiscard]] Details lookupDetails(const FullMsgId &fullId) const;
|
2021-09-26 18:24:47 +00:00
|
|
|
|
2021-11-02 17:54:15 +00:00
|
|
|
void view(const FullMsgId &fullId);
|
|
|
|
|
2021-09-26 18:24:47 +00:00
|
|
|
private:
|
|
|
|
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
|
|
|
struct Entry {
|
|
|
|
OwnedItem item;
|
|
|
|
SponsoredMessage sponsored;
|
|
|
|
};
|
|
|
|
struct List {
|
|
|
|
std::vector<Entry> entries;
|
|
|
|
bool showedAll = false;
|
2021-11-05 07:44:51 +00:00
|
|
|
crl::time received = 0;
|
2021-09-26 18:24:47 +00:00
|
|
|
};
|
|
|
|
struct Request {
|
|
|
|
mtpRequestId requestId = 0;
|
|
|
|
crl::time lastReceived = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void parse(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPmessages_sponsoredMessages &list);
|
|
|
|
void append(
|
|
|
|
not_null<History*> history,
|
|
|
|
List &list,
|
|
|
|
const MTPSponsoredMessage &message);
|
|
|
|
void clearOldRequests();
|
|
|
|
|
2021-11-02 17:54:15 +00:00
|
|
|
const Entry *find(const FullMsgId &fullId) const;
|
2021-09-26 18:24:47 +00:00
|
|
|
|
|
|
|
const not_null<Main::Session*> _session;
|
|
|
|
|
|
|
|
base::Timer _clearTimer;
|
|
|
|
base::flat_map<not_null<History*>, List> _data;
|
|
|
|
base::flat_map<not_null<History*>, Request> _requests;
|
|
|
|
base::flat_map<RandomId, Request> _viewRequests;
|
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|