From ce7621fbd9f880e54dfa35291f3d611edcdc0bf7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 19 Mar 2020 16:06:36 +0400 Subject: [PATCH] Read and write special filter icon emoji. --- .../boxes/filters/edit_filter_box.cpp | 4 + .../SourceFiles/data/data_chat_filters.cpp | 17 +- Telegram/SourceFiles/data/data_chat_filters.h | 4 + Telegram/SourceFiles/ui/filter_icons.cpp | 154 +++++++++++++++--- Telegram/SourceFiles/ui/filter_icons.h | 3 + 5 files changed, 155 insertions(+), 27 deletions(-) diff --git a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp index 0584c746f..f5c0a12cf 100644 --- a/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp +++ b/Telegram/SourceFiles/boxes/filters/edit_filter_box.cpp @@ -104,6 +104,7 @@ not_null SetupChatsPreview( *data = Data::ChatFilter( data->id(), data->title(), + data->iconEmoji(), (data->flags() & ~flag), data->always(), data->pinned(), @@ -121,6 +122,7 @@ not_null SetupChatsPreview( *data = Data::ChatFilter( data->id(), data->title(), + data->iconEmoji(), data->flags(), std::move(always), std::move(pinned), @@ -295,6 +297,7 @@ void EditExceptions( *data = Data::ChatFilter( data->id(), data->title(), + data->iconEmoji(), (data->flags() & ~options) | rawController->chosenOptions(), include ? std::move(changed) : std::move(removeFrom), std::move(pinned), @@ -415,6 +418,7 @@ void EditFilterBox( const auto result = Data::ChatFilter( data->id(), title, + data->iconEmoji(), data->flags(), data->always(), data->pinned(), diff --git a/Telegram/SourceFiles/data/data_chat_filters.cpp b/Telegram/SourceFiles/data/data_chat_filters.cpp index 0042cb5de..ca9899453 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.cpp +++ b/Telegram/SourceFiles/data/data_chat_filters.cpp @@ -23,12 +23,14 @@ namespace Data { ChatFilter::ChatFilter( FilterId id, const QString &title, + const QString &iconEmoji, Flags flags, base::flat_set> always, std::vector> pinned, base::flat_set> never) : _id(id) , _title(title) +, _iconEmoji(iconEmoji) , _always(std::move(always)) , _pinned(std::move(pinned)) , _never(std::move(never)) @@ -87,6 +89,7 @@ ChatFilter ChatFilter::FromTL( return ChatFilter( data.vid().v, qs(data.vtitle()), + qs(data.vemoticon().value_or_empty()), flags, std::move(list), std::move(pinned), @@ -128,7 +131,7 @@ MTPDialogFilter ChatFilter::tl(FilterId replaceId) const { MTP_flags(flags), MTP_int(replaceId ? replaceId : _id), MTP_string(_title), - MTPstring(), // emoticon + MTP_string(_iconEmoji), MTP_vector(pinned), MTP_vector(include), MTP_vector(never)); @@ -142,6 +145,10 @@ QString ChatFilter::title() const { return _title; } +QString ChatFilter::iconEmoji() const { + return _iconEmoji; +} + ChatFilter::Flags ChatFilter::flags() const { return _flags; } @@ -261,7 +268,8 @@ void ChatFilters::load(bool force) { applyRemove(position); changed = true; } - if (changed) { + if (changed || !_loaded) { + _loaded = true; _listChanged.fire({}); } _loadRequestId = 0; @@ -308,7 +316,7 @@ void ChatFilters::applyInsert(ChatFilter filter, int position) { _list.insert( begin(_list) + position, - ChatFilter(filter.id(), {}, {}, {}, {}, {})); + ChatFilter(filter.id(), {}, {}, {}, {}, {}, {})); applyChange(*(begin(_list) + position), std::move(filter)); } @@ -325,7 +333,7 @@ void ChatFilters::applyRemove(int position) { Expects(position >= 0 && position < _list.size()); const auto i = begin(_list) + position; - applyChange(*i, ChatFilter(i->id(), {}, {}, {}, {}, {})); + applyChange(*i, ChatFilter(i->id(), {}, {}, {}, {}, {}, {})); _list.erase(i); } @@ -434,6 +442,7 @@ const ChatFilter &ChatFilters::applyUpdatedPinned( set(ChatFilter( id, i->title(), + i->iconEmoji(), i->flags(), std::move(always), std::move(pinned), diff --git a/Telegram/SourceFiles/data/data_chat_filters.h b/Telegram/SourceFiles/data/data_chat_filters.h index 02a749b06..9ad279fa6 100644 --- a/Telegram/SourceFiles/data/data_chat_filters.h +++ b/Telegram/SourceFiles/data/data_chat_filters.h @@ -41,6 +41,7 @@ public: ChatFilter( FilterId id, const QString &title, + const QString &iconEmoji, Flags flags, base::flat_set> always, std::vector> pinned, @@ -53,6 +54,7 @@ public: [[nodiscard]] FilterId id() const; [[nodiscard]] QString title() const; + [[nodiscard]] QString iconEmoji() const; [[nodiscard]] Flags flags() const; [[nodiscard]] const base::flat_set> &always() const; [[nodiscard]] const std::vector> &pinned() const; @@ -63,6 +65,7 @@ public: private: FilterId _id = 0; QString _title; + QString _iconEmoji; base::flat_set> _always; std::vector> _pinned; base::flat_set> _never; @@ -119,6 +122,7 @@ private: rpl::event_stream<> _listChanged; rpl::event_stream> _refreshHistoryRequests; mtpRequestId _loadRequestId = 0; + bool _loaded = false; }; diff --git a/Telegram/SourceFiles/ui/filter_icons.cpp b/Telegram/SourceFiles/ui/filter_icons.cpp index cbff50b6d..eab770ac5 100644 --- a/Telegram/SourceFiles/ui/filter_icons.cpp +++ b/Telegram/SourceFiles/ui/filter_icons.cpp @@ -7,35 +7,128 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/filter_icons.h" +#include "ui/emoji_config.h" #include "styles/style_filter_icons.h" namespace Ui { namespace { const auto kIcons = std::vector{ - { &st::filtersAll, &st::filtersAllActive }, - { &st::filtersUnread, &st::filtersAllActive }, - { &st::filtersUnmuted, &st::filtersAllActive }, - { &st::filtersBots, &st::filtersAllActive }, - { &st::filtersChannels, &st::filtersChannelsActive }, - { &st::filtersGroups, &st::filtersGroupsActive }, - { &st::filtersPrivate, &st::filtersPrivateActive }, - { &st::filtersCustom, &st::filtersCustomActive }, - { &st::filtersSetup, &st::filtersSetup }, - { &st::foldersCat, &st::foldersCatActive }, - { &st::foldersCrown, &st::foldersCrownActive }, - { &st::foldersFavorite, &st::foldersFavoriteActive }, - { &st::foldersFlower, &st::foldersFlowerActive }, - { &st::foldersGame, &st::foldersGameActive }, - { &st::foldersHome, &st::foldersHomeActive }, - { &st::foldersLove, &st::foldersLoveActive }, - { &st::foldersMask, &st::foldersMaskActive }, - { &st::foldersParty, &st::foldersPartyActive }, - { &st::foldersSport, &st::foldersSportActive }, - { &st::foldersStudy, &st::foldersStudyActive }, - { &st::foldersTrade, &st::foldersTrade }, - { &st::foldersTravel, &st::foldersTravelActive }, - { &st::foldersWork, &st::foldersWorkActive }, + { + &st::filtersAll, + &st::filtersAllActive, + "\xF0\x9F\x92\xAC"_cs.utf16() + }, + { + &st::filtersUnread, + &st::filtersUnreadActive, + "\xE2\x9C\x85"_cs.utf16() + }, + { + &st::filtersUnmuted, + &st::filtersUnmutedActive, + "\xF0\x9F\x94\x94"_cs.utf16() + }, + { + &st::filtersBots, + &st::filtersBotsActive, + "\xF0\x9F\xA4\x96"_cs.utf16() + }, + { + &st::filtersChannels, + &st::filtersChannelsActive, + "\xF0\x9F\x93\xA2"_cs.utf16() + }, + { + &st::filtersGroups, + &st::filtersGroupsActive, + "\xF0\x9F\x91\xA5"_cs.utf16() + }, + { + &st::filtersPrivate, + &st::filtersPrivateActive, + "\xF0\x9F\x91\xA4"_cs.utf16() + }, + { + &st::filtersCustom, + &st::filtersCustomActive, + "\xF0\x9F\x93\x81"_cs.utf16() + }, + { + &st::filtersSetup, + &st::filtersSetup, + "\xF0\x9F\x93\x8B"_cs.utf16() + }, + { + &st::foldersCat, + &st::foldersCatActive, + "\xF0\x9F\x90\x88"_cs.utf16() + }, + { + &st::foldersCrown, + &st::foldersCrownActive, + "\xF0\x9F\x91\x91"_cs.utf16() + }, + { + &st::foldersFavorite, + &st::foldersFavoriteActive, + "\xE2\xAD\x90\xEF\xB8\x8F"_cs.utf16() + }, + { + &st::foldersFlower, + &st::foldersFlowerActive, + "\xF0\x9F\x8C\xB9"_cs.utf16() + }, + { + &st::foldersGame, + &st::foldersGameActive, + "\xF0\x9F\x8E\xAE"_cs.utf16() + }, + { + &st::foldersHome, + &st::foldersHomeActive, + "\xF0\x9F\x8F\xA0"_cs.utf16() + }, + { + &st::foldersLove, + &st::foldersLoveActive, + "\xE2\x9D\xA4\xEF\xB8\x8F"_cs.utf16() + }, + { + &st::foldersMask, + &st::foldersMaskActive, + "\xF0\x9F\x8E\xAD"_cs.utf16() + }, + { + &st::foldersParty, + &st::foldersPartyActive, + "\xF0\x9F\x8D\xB8"_cs.utf16() + }, + { + &st::foldersSport, + &st::foldersSportActive, + "\xE2\x9A\xBD\xEF\xB8\x8F"_cs.utf16() + }, + { + &st::foldersStudy, + &st::foldersStudyActive, + "\xF0\x9F\x8E\x93"_cs.utf16() + }, + { + &st::foldersTrade, + &st::foldersTrade, + "\xF0\x9F\x93\x88"_cs.utf16() + }, + { + &st::foldersTravel, + &st::foldersTravelActive, + "\xE2\x9C\x88\xEF\xB8\x8F"_cs.utf16() + }, + { + &st::foldersWork, + &st::foldersWorkActive, + "\xF0\x9F\x92\xBC"_cs.utf16() + }, }; } // namespace @@ -47,4 +140,19 @@ const FilterIcons &LookupFilterIcon(FilterIcon icon) { return kIcons[static_cast(icon)]; } +std::optional LookupFilterIconByEmoji(const QString &emoji) { + static const auto kMap = [] { + auto result = base::flat_map(); + auto index = 0; + for (const auto &entry : kIcons) { + const auto emoji = Ui::Emoji::Find(entry.emoji); + Assert(emoji != nullptr); + result.emplace(emoji, static_cast(index++)); + } + return result; + }(); + const auto i = kMap.find(Ui::Emoji::Find(emoji)); + return (i != end(kMap)) ? std::make_optional(i->second) : std::nullopt; +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/filter_icons.h b/Telegram/SourceFiles/ui/filter_icons.h index cbddff819..d687942cc 100644 --- a/Telegram/SourceFiles/ui/filter_icons.h +++ b/Telegram/SourceFiles/ui/filter_icons.h @@ -45,8 +45,11 @@ enum class FilterIcon : uchar { struct FilterIcons { not_null normal; not_null active; + QString emoji; }; [[nodiscard]] const FilterIcons &LookupFilterIcon(FilterIcon icon); +[[nodiscard]] std::optional LookupFilterIconByEmoji( + const QString &emoji); } // namespace Ui