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 "base/timer.h"
|
2023-11-23 14:09:12 +00:00
|
|
|
#include "history/history_item.h"
|
2022-02-15 02:20:55 +00:00
|
|
|
#include "ui/image/image_location.h"
|
2023-11-23 14:09:12 +00:00
|
|
|
#include "window/window_session_controller_link_info.h"
|
2021-09-26 18:24:47 +00:00
|
|
|
|
|
|
|
class History;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
2024-03-27 01:47:42 +00:00
|
|
|
struct SponsoredReportResult final {
|
|
|
|
using Id = QByteArray;
|
|
|
|
struct Option final {
|
|
|
|
Id id = 0;
|
|
|
|
QString text;
|
|
|
|
};
|
|
|
|
using Options = std::vector<Option>;
|
|
|
|
enum class FinalStep {
|
|
|
|
Hidden,
|
|
|
|
Reported,
|
|
|
|
Premium,
|
2024-03-31 17:52:19 +00:00
|
|
|
Silence,
|
2024-03-27 01:47:42 +00:00
|
|
|
};
|
|
|
|
Options options;
|
|
|
|
QString title;
|
|
|
|
QString error;
|
|
|
|
FinalStep result;
|
|
|
|
};
|
|
|
|
|
2021-12-31 12:47:23 +00:00
|
|
|
struct SponsoredFrom {
|
|
|
|
QString title;
|
2024-04-11 23:42:18 +00:00
|
|
|
QString link;
|
2023-11-23 14:09:12 +00:00
|
|
|
QString buttonText;
|
2024-04-11 23:42:18 +00:00
|
|
|
PhotoId photoId = PhotoId(0);
|
|
|
|
uint64 backgroundEmojiId = 0;
|
|
|
|
uint8 colorIndex : 6 = 0;
|
|
|
|
bool isLinkInternal = false;
|
|
|
|
bool isRecommended = false;
|
2024-03-26 23:56:17 +00:00
|
|
|
bool canReport = false;
|
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;
|
2024-04-11 23:42:18 +00:00
|
|
|
QString link;
|
2023-03-01 13:28:06 +00:00
|
|
|
TextWithEntities sponsorInfo;
|
|
|
|
TextWithEntities additionalInfo;
|
2021-09-26 18:24:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SponsoredMessages final {
|
|
|
|
public:
|
2022-11-05 12:41:27 +00:00
|
|
|
enum class State {
|
|
|
|
None,
|
|
|
|
AppendToEnd,
|
|
|
|
InjectToMiddle,
|
|
|
|
};
|
2021-12-31 12:47:23 +00:00
|
|
|
struct Details {
|
2023-03-01 13:28:06 +00:00
|
|
|
std::vector<TextWithEntities> info;
|
2024-04-11 23:42:18 +00:00
|
|
|
QString link;
|
2023-11-15 15:18:18 +00:00
|
|
|
QString buttonText;
|
2024-04-11 23:42:18 +00:00
|
|
|
PhotoId photoId = PhotoId(0);
|
|
|
|
uint64 backgroundEmojiId = 0;
|
|
|
|
uint8 colorIndex : 6 = 0;
|
|
|
|
bool isLinkInternal = false;
|
2024-03-26 23:56:17 +00:00
|
|
|
bool canReport = false;
|
2021-12-23 16:48:36 +00:00
|
|
|
};
|
2021-09-26 18:24:47 +00:00
|
|
|
using RandomId = QByteArray;
|
2024-04-13 14:56:45 +00:00
|
|
|
explicit SponsoredMessages(not_null<Main::Session*> session);
|
2021-09-26 18:24:47 +00:00
|
|
|
~SponsoredMessages();
|
|
|
|
|
2021-11-03 11:49:48 +00:00
|
|
|
[[nodiscard]] bool canHaveFor(not_null<History*> history) const;
|
2022-11-05 12:41:27 +00:00
|
|
|
void request(not_null<History*> history, Fn<void()> done);
|
2021-09-26 18:24:47 +00:00
|
|
|
void clearItems(not_null<History*> history);
|
2021-12-31 12:47:23 +00:00
|
|
|
[[nodiscard]] Details lookupDetails(const FullMsgId &fullId) const;
|
2023-06-23 16:05:58 +00:00
|
|
|
void clicked(const FullMsgId &fullId);
|
2021-09-26 18:24:47 +00:00
|
|
|
|
2022-11-05 12:41:27 +00:00
|
|
|
[[nodiscard]] bool append(not_null<History*> history);
|
|
|
|
void inject(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId injectAfterMsgId,
|
|
|
|
int betweenHeight,
|
|
|
|
int fallbackWidth);
|
|
|
|
|
2021-11-02 17:54:15 +00:00
|
|
|
void view(const FullMsgId &fullId);
|
|
|
|
|
2022-11-05 12:41:27 +00:00
|
|
|
[[nodiscard]] State state(not_null<History*> history) const;
|
2024-03-27 01:47:42 +00:00
|
|
|
|
|
|
|
[[nodiscard]] auto createReportCallback(const FullMsgId &fullId)
|
|
|
|
-> Fn<void(SponsoredReportResult::Id, Fn<void(SponsoredReportResult)>)>;
|
2024-04-24 12:35:05 +00:00
|
|
|
|
|
|
|
void clear();
|
2022-11-05 12:41:27 +00:00
|
|
|
|
2021-09-26 18:24:47 +00:00
|
|
|
private:
|
|
|
|
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
|
|
|
struct Entry {
|
|
|
|
OwnedItem item;
|
2023-11-23 11:45:38 +00:00
|
|
|
FullMsgId itemFullId;
|
2021-09-26 18:24:47 +00:00
|
|
|
SponsoredMessage sponsored;
|
|
|
|
};
|
|
|
|
struct List {
|
|
|
|
std::vector<Entry> entries;
|
2022-11-05 12:41:27 +00:00
|
|
|
// Data between history displays.
|
|
|
|
size_t injectedCount = 0;
|
2021-09-26 18:24:47 +00:00
|
|
|
bool showedAll = false;
|
2022-11-05 12:41:27 +00:00
|
|
|
//
|
2021-11-05 07:44:51 +00:00
|
|
|
crl::time received = 0;
|
2022-11-05 12:41:27 +00:00
|
|
|
int postsBetween = 0;
|
|
|
|
State state = State::None;
|
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
|