2019-08-01 14:13:02 +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
|
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
#include "ui/text/text_isolated_emoji.h"
|
2020-05-29 14:29:21 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-08-05 14:08:20 +00:00
|
|
|
#include "base/timer.h"
|
2019-08-02 18:19:14 +00:00
|
|
|
|
|
|
|
#include <crl/crl_object_on_queue.h>
|
|
|
|
|
2019-08-07 14:22:51 +00:00
|
|
|
class HistoryItem;
|
|
|
|
class DocumentData;
|
|
|
|
|
2019-08-01 14:13:02 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-08-07 14:22:51 +00:00
|
|
|
namespace Lottie {
|
|
|
|
struct ColorReplacements;
|
|
|
|
} // namespace Lottie
|
2019-08-01 14:13:02 +00:00
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
namespace Ui {
|
|
|
|
namespace Text {
|
|
|
|
class String;
|
|
|
|
} // namespace Text
|
2019-08-05 14:08:20 +00:00
|
|
|
namespace Emoji {
|
|
|
|
class UniversalImages;
|
|
|
|
} // namespace Emoji
|
2019-08-02 18:19:14 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2019-08-01 14:13:02 +00:00
|
|
|
namespace Stickers {
|
2019-08-02 18:19:14 +00:00
|
|
|
|
|
|
|
using IsolatedEmoji = Ui::Text::IsolatedEmoji;
|
2019-08-01 14:13:02 +00:00
|
|
|
|
2020-05-29 14:29:21 +00:00
|
|
|
struct LargeEmojiImage {
|
|
|
|
std::optional<Image> image;
|
|
|
|
FnMut<void()> load;
|
|
|
|
|
|
|
|
[[nodiscard]] static QSize Size();
|
|
|
|
};
|
|
|
|
|
2019-08-01 14:13:02 +00:00
|
|
|
class EmojiPack final {
|
|
|
|
public:
|
2019-08-07 14:22:51 +00:00
|
|
|
struct Sticker {
|
|
|
|
DocumentData *document = nullptr;
|
|
|
|
const Lottie::ColorReplacements *replacements = nullptr;
|
|
|
|
|
|
|
|
[[nodiscard]] bool empty() const {
|
|
|
|
return (document == nullptr);
|
|
|
|
}
|
|
|
|
[[nodiscard]] explicit operator bool() const {
|
|
|
|
return !empty();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-01 14:13:02 +00:00
|
|
|
explicit EmojiPack(not_null<Main::Session*> session);
|
2019-08-02 18:19:14 +00:00
|
|
|
~EmojiPack();
|
2019-08-01 14:13:02 +00:00
|
|
|
|
2019-08-02 18:19:14 +00:00
|
|
|
bool add(not_null<HistoryItem*> item);
|
|
|
|
void remove(not_null<const HistoryItem*> item);
|
2019-08-01 21:14:19 +00:00
|
|
|
|
2019-08-07 14:22:51 +00:00
|
|
|
[[nodiscard]] Sticker stickerForEmoji(const IsolatedEmoji &emoji);
|
2020-05-29 14:29:21 +00:00
|
|
|
[[nodiscard]] std::shared_ptr<LargeEmojiImage> image(EmojiPtr emoji);
|
2019-08-01 14:13:02 +00:00
|
|
|
|
|
|
|
private:
|
2019-08-02 18:19:14 +00:00
|
|
|
class ImageLoader;
|
|
|
|
|
2019-08-01 14:13:02 +00:00
|
|
|
void refresh();
|
|
|
|
void refreshDelayed();
|
2019-08-01 21:14:19 +00:00
|
|
|
void applySet(const MTPDmessages_stickerSet &data);
|
|
|
|
void applyPack(
|
|
|
|
const MTPDstickerPack &data,
|
|
|
|
const base::flat_map<uint64, not_null<DocumentData*>> &map);
|
|
|
|
base::flat_map<uint64, not_null<DocumentData*>> collectStickers(
|
|
|
|
const QVector<MTPDocument> &list) const;
|
2019-08-02 18:19:14 +00:00
|
|
|
void refreshAll();
|
2019-08-01 21:14:19 +00:00
|
|
|
void refreshItems(EmojiPtr emoji);
|
2019-08-02 18:19:14 +00:00
|
|
|
void refreshItems(const base::flat_set<not_null<HistoryItem*>> &list);
|
2019-08-01 14:13:02 +00:00
|
|
|
|
|
|
|
not_null<Main::Session*> _session;
|
|
|
|
base::flat_map<EmojiPtr, not_null<DocumentData*>> _map;
|
2019-08-02 18:19:14 +00:00
|
|
|
base::flat_map<
|
|
|
|
IsolatedEmoji,
|
|
|
|
base::flat_set<not_null<HistoryItem*>>> _items;
|
2020-05-29 14:29:21 +00:00
|
|
|
base::flat_map<EmojiPtr, std::weak_ptr<LargeEmojiImage>> _images;
|
2019-08-01 14:13:02 +00:00
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Stickers
|