tdesktop/Telegram/SourceFiles/chat_helpers/emoji_keywords.h

88 lines
2.1 KiB
C
Raw Normal View History

/*
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
class ApiWrap;
namespace ChatHelpers {
namespace details {
class EmojiKeywordsLangPackDelegate {
public:
virtual ApiWrap *api() = 0;
virtual void langPackRefreshed() = 0;
protected:
~EmojiKeywordsLangPackDelegate() = default;
};
} // namespace details
class EmojiKeywords final : private details::EmojiKeywordsLangPackDelegate {
public:
EmojiKeywords();
EmojiKeywords(const EmojiKeywords &other) = delete;
EmojiKeywords &operator=(const EmojiKeywords &other) = delete;
~EmojiKeywords();
void refresh();
[[nodiscard]] rpl::producer<> refreshed() const;
struct Result {
EmojiPtr emoji = nullptr;
QString label;
QString replacement;
};
[[nodiscard]] std::vector<Result> query(
const QString &query,
bool exact = false) const;
2023-01-20 16:44:08 +00:00
[[nodiscard]] std::vector<Result> queryMine(
const QString &query,
bool exact = false) const;
2019-03-29 13:51:18 +00:00
[[nodiscard]] int maxQueryLength() const;
private:
class LangPack;
not_null<details::EmojiKeywordsLangPackDelegate*> delegate();
ApiWrap *api() override;
void langPackRefreshed() override;
2023-01-20 16:44:08 +00:00
[[nodiscard]] static std::vector<Result> PrioritizeRecent(
std::vector<Result> list);
[[nodiscard]] static std::vector<Result> ApplyVariants(
std::vector<Result> list);
2019-07-24 11:45:24 +00:00
void handleSessionChanges();
void apiChanged(ApiWrap *api);
2019-03-29 14:23:15 +00:00
void refreshInputLanguages();
[[nodiscard]] std::vector<QString> languages();
void refreshRemoteList();
void setRemoteList(std::vector<QString> &&list);
void refreshFromRemoteList();
ApiWrap *_api = nullptr;
std::vector<QString> _localList;
std::vector<QString> _remoteList;
2019-03-29 11:25:10 +00:00
mtpRequestId _langsRequestId = 0;
base::flat_map<QString, std::unique_ptr<LangPack>> _data;
2019-03-29 12:21:11 +00:00
std::deque<std::unique_ptr<LangPack>> _notUsedData;
2019-03-29 14:23:15 +00:00
std::deque<QStringList> _inputLanguages;
rpl::event_stream<> _refreshed;
rpl::lifetime _suggestedChangeLifetime;
rpl::lifetime _lifetime;
base::has_weak_ptr _guard;
};
} // namespace ChatHelpers