2022-06-23 13:52:15 +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
|
|
|
|
|
2022-06-29 14:56:59 +00:00
|
|
|
#include "data/stickers/data_stickers_set.h"
|
2022-06-24 11:14:23 +00:00
|
|
|
#include "ui/text/custom_emoji_instance.h"
|
2022-06-28 13:13:20 +00:00
|
|
|
#include "base/timer.h"
|
|
|
|
#include "base/weak_ptr.h"
|
2022-06-24 11:14:23 +00:00
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
class Session;
|
2022-06-24 11:14:23 +00:00
|
|
|
class CustomEmojiLoader;
|
2022-06-23 13:52:15 +00:00
|
|
|
|
2022-06-29 14:56:59 +00:00
|
|
|
struct CustomEmojiId {
|
2022-08-15 10:17:24 +00:00
|
|
|
DocumentId id = 0;
|
2022-06-29 14:56:59 +00:00
|
|
|
};
|
|
|
|
|
2022-09-06 16:53:42 +00:00
|
|
|
enum class CustomEmojiSizeTag : uchar {
|
|
|
|
Normal,
|
|
|
|
Large,
|
|
|
|
Isolated,
|
|
|
|
|
|
|
|
kCount,
|
|
|
|
};
|
|
|
|
|
2022-06-28 13:13:20 +00:00
|
|
|
class CustomEmojiManager final : public base::has_weak_ptr {
|
2022-06-23 13:52:15 +00:00
|
|
|
public:
|
2022-09-06 16:53:42 +00:00
|
|
|
using SizeTag = CustomEmojiSizeTag;
|
2022-06-28 13:13:20 +00:00
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
CustomEmojiManager(not_null<Session*> owner);
|
|
|
|
~CustomEmojiManager();
|
|
|
|
|
|
|
|
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> create(
|
2022-06-29 14:56:59 +00:00
|
|
|
QStringView data,
|
2022-07-25 08:30:38 +00:00
|
|
|
Fn<void()> update,
|
2022-08-26 19:53:48 +00:00
|
|
|
SizeTag tag = SizeTag::Normal,
|
|
|
|
int sizeOverride = 0);
|
2022-07-25 08:30:38 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> create(
|
|
|
|
DocumentId documentId,
|
|
|
|
Fn<void()> update,
|
2022-08-26 19:53:48 +00:00
|
|
|
SizeTag tag = SizeTag::Normal,
|
|
|
|
int sizeOverride = 0);
|
2022-07-25 08:30:38 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> create(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
Fn<void()> update,
|
2022-08-26 19:53:48 +00:00
|
|
|
SizeTag tag = SizeTag::Normal,
|
|
|
|
int sizeOverride = 0);
|
2022-06-23 13:52:15 +00:00
|
|
|
|
2022-08-04 11:31:15 +00:00
|
|
|
class Listener {
|
|
|
|
public:
|
|
|
|
virtual void customEmojiResolveDone(
|
|
|
|
not_null<DocumentData*> document) = 0;
|
|
|
|
};
|
|
|
|
void resolve(QStringView data, not_null<Listener*> listener);
|
|
|
|
void resolve(DocumentId documentId, not_null<Listener*> listener);
|
|
|
|
void unregisterListener(not_null<Listener*> listener);
|
2022-08-03 17:26:39 +00:00
|
|
|
|
2022-07-08 15:00:30 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<Ui::CustomEmoji::Loader> createLoader(
|
|
|
|
not_null<DocumentData*> document,
|
2022-08-26 19:53:48 +00:00
|
|
|
SizeTag tag,
|
|
|
|
int sizeOverride = 0);
|
2022-07-14 11:20:56 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<Ui::CustomEmoji::Loader> createLoader(
|
|
|
|
DocumentId documentId,
|
2022-08-26 19:53:48 +00:00
|
|
|
SizeTag tag,
|
|
|
|
int sizeOverride = 0);
|
2022-07-08 15:00:30 +00:00
|
|
|
|
2022-07-18 13:56:14 +00:00
|
|
|
[[nodiscard]] QString lookupSetName(uint64 setId);
|
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const;
|
|
|
|
[[nodiscard]] Session &owner() const;
|
|
|
|
|
2022-09-02 14:51:57 +00:00
|
|
|
[[nodiscard]] uint64 coloredSetId() const;
|
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
private:
|
2022-07-25 14:54:37 +00:00
|
|
|
static constexpr auto kSizeCount = int(SizeTag::kCount);
|
|
|
|
|
2022-06-28 13:13:20 +00:00
|
|
|
struct RepaintBunch {
|
|
|
|
crl::time when = 0;
|
|
|
|
std::vector<base::weak_ptr<Ui::CustomEmoji::Instance>> instances;
|
|
|
|
};
|
2022-08-31 08:29:09 +00:00
|
|
|
struct LoaderWithSetId {
|
|
|
|
std::unique_ptr<Ui::CustomEmoji::Loader> loader;
|
|
|
|
uint64 setId = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] LoaderWithSetId createLoaderWithSetId(
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
SizeTag tag,
|
|
|
|
int sizeOverride = 0);
|
|
|
|
[[nodiscard]] LoaderWithSetId createLoaderWithSetId(
|
|
|
|
DocumentId documentId,
|
|
|
|
SizeTag tag,
|
|
|
|
int sizeOverride = 0);
|
2022-06-24 11:14:23 +00:00
|
|
|
|
2022-07-05 19:36:25 +00:00
|
|
|
void request();
|
|
|
|
void requestFinished();
|
2022-06-28 13:13:20 +00:00
|
|
|
void repaintLater(
|
|
|
|
not_null<Ui::CustomEmoji::Instance*> instance,
|
|
|
|
Ui::CustomEmoji::RepaintRequest request);
|
|
|
|
void scheduleRepaintTimer();
|
|
|
|
void invokeRepaints();
|
2022-08-31 08:29:09 +00:00
|
|
|
void fillColoredFlags(not_null<DocumentData*> document);
|
|
|
|
void processLoaders(not_null<DocumentData*> document);
|
|
|
|
void processListeners(not_null<DocumentData*> document);
|
2022-07-18 13:56:14 +00:00
|
|
|
void requestSetFor(not_null<DocumentData*> document);
|
2022-06-24 11:14:23 +00:00
|
|
|
|
2022-07-25 09:38:56 +00:00
|
|
|
[[nodiscard]] Ui::CustomEmoji::Preview prepareNonExactPreview(
|
|
|
|
DocumentId documentId,
|
2022-08-26 19:53:48 +00:00
|
|
|
SizeTag tag,
|
|
|
|
int sizeOverride) const;
|
2022-07-25 08:30:38 +00:00
|
|
|
template <typename LoaderFactory>
|
|
|
|
[[nodiscard]] std::unique_ptr<Ui::Text::CustomEmoji> create(
|
|
|
|
DocumentId documentId,
|
|
|
|
Fn<void()> update,
|
|
|
|
SizeTag tag,
|
2022-08-26 19:53:48 +00:00
|
|
|
int sizeOverride,
|
2022-07-25 08:30:38 +00:00
|
|
|
LoaderFactory factory);
|
|
|
|
[[nodiscard]] static int SizeIndex(SizeTag tag);
|
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
const not_null<Session*> _owner;
|
|
|
|
|
2022-07-25 14:54:37 +00:00
|
|
|
std::array<
|
|
|
|
base::flat_map<
|
2022-08-03 17:26:39 +00:00
|
|
|
DocumentId,
|
2022-07-25 14:54:37 +00:00
|
|
|
std::unique_ptr<Ui::CustomEmoji::Instance>>,
|
|
|
|
kSizeCount> _instances;
|
|
|
|
std::array<
|
|
|
|
base::flat_map<
|
2022-08-03 17:26:39 +00:00
|
|
|
DocumentId,
|
2022-07-25 14:54:37 +00:00
|
|
|
std::vector<base::weak_ptr<CustomEmojiLoader>>>,
|
|
|
|
kSizeCount> _loaders;
|
2022-08-04 11:31:15 +00:00
|
|
|
base::flat_map<
|
|
|
|
DocumentId,
|
|
|
|
base::flat_set<not_null<Listener*>>> _resolvers;
|
|
|
|
base::flat_map<
|
|
|
|
not_null<Listener*>,
|
|
|
|
base::flat_set<DocumentId>> _listeners;
|
2022-08-03 17:26:39 +00:00
|
|
|
base::flat_set<DocumentId> _pendingForRequest;
|
2022-08-31 08:29:09 +00:00
|
|
|
base::flat_map<
|
|
|
|
uint64,
|
|
|
|
base::flat_set<
|
|
|
|
not_null<Ui::CustomEmoji::Instance*>>> _coloredSetPending;
|
|
|
|
|
2022-07-05 19:36:25 +00:00
|
|
|
mtpRequestId _requestId = 0;
|
2022-06-24 11:14:23 +00:00
|
|
|
|
2022-08-31 08:29:09 +00:00
|
|
|
uint64 _coloredSetId = 0;
|
|
|
|
|
2022-06-28 13:13:20 +00:00
|
|
|
base::flat_map<crl::time, RepaintBunch> _repaints;
|
|
|
|
crl::time _repaintNext = 0;
|
|
|
|
base::Timer _repaintTimer;
|
|
|
|
bool _repaintTimerScheduled = false;
|
2022-07-18 13:56:14 +00:00
|
|
|
bool _requestSetsScheduled = false;
|
2022-06-28 13:13:20 +00:00
|
|
|
|
2022-08-31 08:29:09 +00:00
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
};
|
|
|
|
|
2022-08-03 17:26:39 +00:00
|
|
|
[[nodiscard]] int FrameSizeFromTag(CustomEmojiManager::SizeTag tag);
|
|
|
|
|
2022-06-29 14:56:59 +00:00
|
|
|
[[nodiscard]] QString SerializeCustomEmojiId(const CustomEmojiId &id);
|
|
|
|
[[nodiscard]] QString SerializeCustomEmojiId(
|
|
|
|
not_null<DocumentData*> document);
|
|
|
|
[[nodiscard]] CustomEmojiId ParseCustomEmojiData(QStringView data);
|
2022-06-23 13:52:15 +00:00
|
|
|
|
2022-08-01 13:24:51 +00:00
|
|
|
[[nodiscard]] bool AllowEmojiWithoutPremium(not_null<PeerData*> peer);
|
|
|
|
|
2022-07-05 19:36:25 +00:00
|
|
|
void InsertCustomEmoji(
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
not_null<DocumentData*> document);
|
|
|
|
|
2022-08-26 19:53:48 +00:00
|
|
|
[[nodiscard]] Ui::Text::CustomEmojiFactory ReactedMenuFactory(
|
|
|
|
not_null<Main::Session*> session);
|
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
} // namespace Data
|