tdesktop/Telegram/SourceFiles/chat_helpers/stickers_emoji_pack.h

98 lines
2.3 KiB
C
Raw Normal View History

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"
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
namespace details {
class EmojiImageLoader;
} // namespace details
using IsolatedEmoji = Ui::Text::IsolatedEmoji;
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);
2019-08-05 11:44:40 +00:00
[[nodiscard]] std::shared_ptr<Image> 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-05 14:08:20 +00:00
std::shared_ptr<Ui::Emoji::UniversalImages> prepareSourceImages();
void clearSourceImages();
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;
2019-08-05 11:44:40 +00:00
base::flat_map<EmojiPtr, std::weak_ptr<Image>> _images;
2019-08-01 14:13:02 +00:00
mtpRequestId _requestId = 0;
2019-08-02 18:19:14 +00:00
crl::object_on_queue<details::EmojiImageLoader> _imageLoader;
2019-08-05 14:08:20 +00:00
base::Timer _clearTimer;
2019-08-02 18:19:14 +00:00
2019-08-01 14:13:02 +00:00
rpl::lifetime _lifetime;
};
} // namespace Stickers