emoji_keywords.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. class ApiWrap;
  9. namespace ChatHelpers {
  10. namespace details {
  11. class EmojiKeywordsLangPackDelegate {
  12. public:
  13. virtual ApiWrap *api() = 0;
  14. virtual void langPackRefreshed() = 0;
  15. protected:
  16. ~EmojiKeywordsLangPackDelegate() = default;
  17. };
  18. } // namespace details
  19. class EmojiKeywords final : private details::EmojiKeywordsLangPackDelegate {
  20. public:
  21. EmojiKeywords();
  22. EmojiKeywords(const EmojiKeywords &other) = delete;
  23. EmojiKeywords &operator=(const EmojiKeywords &other) = delete;
  24. ~EmojiKeywords();
  25. void refresh();
  26. [[nodiscard]] rpl::producer<> refreshed() const;
  27. struct Result {
  28. EmojiPtr emoji = nullptr;
  29. QString label;
  30. QString replacement;
  31. };
  32. [[nodiscard]] std::vector<Result> query(
  33. const QString &query,
  34. bool exact = false) const;
  35. [[nodiscard]] std::vector<Result> queryMine(
  36. const QString &query,
  37. bool exact = false) const;
  38. [[nodiscard]] int maxQueryLength() const;
  39. private:
  40. class LangPack;
  41. not_null<details::EmojiKeywordsLangPackDelegate*> delegate();
  42. ApiWrap *api() override;
  43. void langPackRefreshed() override;
  44. [[nodiscard]] static std::vector<Result> PrioritizeRecent(
  45. std::vector<Result> list);
  46. [[nodiscard]] static std::vector<Result> ApplyVariants(
  47. std::vector<Result> list);
  48. void handleSessionChanges();
  49. void apiChanged(ApiWrap *api);
  50. void refreshInputLanguages();
  51. [[nodiscard]] std::vector<QString> languages();
  52. void refreshRemoteList();
  53. void setRemoteList(std::vector<QString> &&list);
  54. void refreshFromRemoteList();
  55. ApiWrap *_api = nullptr;
  56. std::vector<QString> _localList;
  57. std::vector<QString> _remoteList;
  58. mtpRequestId _langsRequestId = 0;
  59. base::flat_map<QString, std::unique_ptr<LangPack>> _data;
  60. std::deque<std::unique_ptr<LangPack>> _notUsedData;
  61. std::deque<QStringList> _inputLanguages;
  62. rpl::event_stream<> _refreshed;
  63. rpl::lifetime _suggestedChangeLifetime;
  64. rpl::lifetime _lifetime;
  65. base::has_weak_ptr _guard;
  66. };
  67. } // namespace ChatHelpers