Read and write special filter icon emoji.

This commit is contained in:
John Preston 2020-03-19 16:06:36 +04:00
parent 9ad5b8ff90
commit ce7621fbd9
5 changed files with 155 additions and 27 deletions

View File

@ -104,6 +104,7 @@ not_null<FilterChatsPreview*> SetupChatsPreview(
*data = Data::ChatFilter( *data = Data::ChatFilter(
data->id(), data->id(),
data->title(), data->title(),
data->iconEmoji(),
(data->flags() & ~flag), (data->flags() & ~flag),
data->always(), data->always(),
data->pinned(), data->pinned(),
@ -121,6 +122,7 @@ not_null<FilterChatsPreview*> SetupChatsPreview(
*data = Data::ChatFilter( *data = Data::ChatFilter(
data->id(), data->id(),
data->title(), data->title(),
data->iconEmoji(),
data->flags(), data->flags(),
std::move(always), std::move(always),
std::move(pinned), std::move(pinned),
@ -295,6 +297,7 @@ void EditExceptions(
*data = Data::ChatFilter( *data = Data::ChatFilter(
data->id(), data->id(),
data->title(), data->title(),
data->iconEmoji(),
(data->flags() & ~options) | rawController->chosenOptions(), (data->flags() & ~options) | rawController->chosenOptions(),
include ? std::move(changed) : std::move(removeFrom), include ? std::move(changed) : std::move(removeFrom),
std::move(pinned), std::move(pinned),
@ -415,6 +418,7 @@ void EditFilterBox(
const auto result = Data::ChatFilter( const auto result = Data::ChatFilter(
data->id(), data->id(),
title, title,
data->iconEmoji(),
data->flags(), data->flags(),
data->always(), data->always(),
data->pinned(), data->pinned(),

View File

@ -23,12 +23,14 @@ namespace Data {
ChatFilter::ChatFilter( ChatFilter::ChatFilter(
FilterId id, FilterId id,
const QString &title, const QString &title,
const QString &iconEmoji,
Flags flags, Flags flags,
base::flat_set<not_null<History*>> always, base::flat_set<not_null<History*>> always,
std::vector<not_null<History*>> pinned, std::vector<not_null<History*>> pinned,
base::flat_set<not_null<History*>> never) base::flat_set<not_null<History*>> never)
: _id(id) : _id(id)
, _title(title) , _title(title)
, _iconEmoji(iconEmoji)
, _always(std::move(always)) , _always(std::move(always))
, _pinned(std::move(pinned)) , _pinned(std::move(pinned))
, _never(std::move(never)) , _never(std::move(never))
@ -87,6 +89,7 @@ ChatFilter ChatFilter::FromTL(
return ChatFilter( return ChatFilter(
data.vid().v, data.vid().v,
qs(data.vtitle()), qs(data.vtitle()),
qs(data.vemoticon().value_or_empty()),
flags, flags,
std::move(list), std::move(list),
std::move(pinned), std::move(pinned),
@ -128,7 +131,7 @@ MTPDialogFilter ChatFilter::tl(FilterId replaceId) const {
MTP_flags(flags), MTP_flags(flags),
MTP_int(replaceId ? replaceId : _id), MTP_int(replaceId ? replaceId : _id),
MTP_string(_title), MTP_string(_title),
MTPstring(), // emoticon MTP_string(_iconEmoji),
MTP_vector<MTPInputPeer>(pinned), MTP_vector<MTPInputPeer>(pinned),
MTP_vector<MTPInputPeer>(include), MTP_vector<MTPInputPeer>(include),
MTP_vector<MTPInputPeer>(never)); MTP_vector<MTPInputPeer>(never));
@ -142,6 +145,10 @@ QString ChatFilter::title() const {
return _title; return _title;
} }
QString ChatFilter::iconEmoji() const {
return _iconEmoji;
}
ChatFilter::Flags ChatFilter::flags() const { ChatFilter::Flags ChatFilter::flags() const {
return _flags; return _flags;
} }
@ -261,7 +268,8 @@ void ChatFilters::load(bool force) {
applyRemove(position); applyRemove(position);
changed = true; changed = true;
} }
if (changed) { if (changed || !_loaded) {
_loaded = true;
_listChanged.fire({}); _listChanged.fire({});
} }
_loadRequestId = 0; _loadRequestId = 0;
@ -308,7 +316,7 @@ void ChatFilters::applyInsert(ChatFilter filter, int position) {
_list.insert( _list.insert(
begin(_list) + position, begin(_list) + position,
ChatFilter(filter.id(), {}, {}, {}, {}, {})); ChatFilter(filter.id(), {}, {}, {}, {}, {}, {}));
applyChange(*(begin(_list) + position), std::move(filter)); applyChange(*(begin(_list) + position), std::move(filter));
} }
@ -325,7 +333,7 @@ void ChatFilters::applyRemove(int position) {
Expects(position >= 0 && position < _list.size()); Expects(position >= 0 && position < _list.size());
const auto i = begin(_list) + position; const auto i = begin(_list) + position;
applyChange(*i, ChatFilter(i->id(), {}, {}, {}, {}, {})); applyChange(*i, ChatFilter(i->id(), {}, {}, {}, {}, {}, {}));
_list.erase(i); _list.erase(i);
} }
@ -434,6 +442,7 @@ const ChatFilter &ChatFilters::applyUpdatedPinned(
set(ChatFilter( set(ChatFilter(
id, id,
i->title(), i->title(),
i->iconEmoji(),
i->flags(), i->flags(),
std::move(always), std::move(always),
std::move(pinned), std::move(pinned),

View File

@ -41,6 +41,7 @@ public:
ChatFilter( ChatFilter(
FilterId id, FilterId id,
const QString &title, const QString &title,
const QString &iconEmoji,
Flags flags, Flags flags,
base::flat_set<not_null<History*>> always, base::flat_set<not_null<History*>> always,
std::vector<not_null<History*>> pinned, std::vector<not_null<History*>> pinned,
@ -53,6 +54,7 @@ public:
[[nodiscard]] FilterId id() const; [[nodiscard]] FilterId id() const;
[[nodiscard]] QString title() const; [[nodiscard]] QString title() const;
[[nodiscard]] QString iconEmoji() const;
[[nodiscard]] Flags flags() const; [[nodiscard]] Flags flags() const;
[[nodiscard]] const base::flat_set<not_null<History*>> &always() const; [[nodiscard]] const base::flat_set<not_null<History*>> &always() const;
[[nodiscard]] const std::vector<not_null<History*>> &pinned() const; [[nodiscard]] const std::vector<not_null<History*>> &pinned() const;
@ -63,6 +65,7 @@ public:
private: private:
FilterId _id = 0; FilterId _id = 0;
QString _title; QString _title;
QString _iconEmoji;
base::flat_set<not_null<History*>> _always; base::flat_set<not_null<History*>> _always;
std::vector<not_null<History*>> _pinned; std::vector<not_null<History*>> _pinned;
base::flat_set<not_null<History*>> _never; base::flat_set<not_null<History*>> _never;
@ -119,6 +122,7 @@ private:
rpl::event_stream<> _listChanged; rpl::event_stream<> _listChanged;
rpl::event_stream<not_null<History*>> _refreshHistoryRequests; rpl::event_stream<not_null<History*>> _refreshHistoryRequests;
mtpRequestId _loadRequestId = 0; mtpRequestId _loadRequestId = 0;
bool _loaded = false;
}; };

View File

@ -7,35 +7,128 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "ui/filter_icons.h" #include "ui/filter_icons.h"
#include "ui/emoji_config.h"
#include "styles/style_filter_icons.h" #include "styles/style_filter_icons.h"
namespace Ui { namespace Ui {
namespace { namespace {
const auto kIcons = std::vector<FilterIcons>{ const auto kIcons = std::vector<FilterIcons>{
{ &st::filtersAll, &st::filtersAllActive }, {
{ &st::filtersUnread, &st::filtersAllActive }, &st::filtersAll,
{ &st::filtersUnmuted, &st::filtersAllActive }, &st::filtersAllActive,
{ &st::filtersBots, &st::filtersAllActive }, "\xF0\x9F\x92\xAC"_cs.utf16()
{ &st::filtersChannels, &st::filtersChannelsActive }, },
{ &st::filtersGroups, &st::filtersGroupsActive }, {
{ &st::filtersPrivate, &st::filtersPrivateActive }, &st::filtersUnread,
{ &st::filtersCustom, &st::filtersCustomActive }, &st::filtersUnreadActive,
{ &st::filtersSetup, &st::filtersSetup }, "\xE2\x9C\x85"_cs.utf16()
{ &st::foldersCat, &st::foldersCatActive }, },
{ &st::foldersCrown, &st::foldersCrownActive }, {
{ &st::foldersFavorite, &st::foldersFavoriteActive }, &st::filtersUnmuted,
{ &st::foldersFlower, &st::foldersFlowerActive }, &st::filtersUnmutedActive,
{ &st::foldersGame, &st::foldersGameActive }, "\xF0\x9F\x94\x94"_cs.utf16()
{ &st::foldersHome, &st::foldersHomeActive }, },
{ &st::foldersLove, &st::foldersLoveActive }, {
{ &st::foldersMask, &st::foldersMaskActive }, &st::filtersBots,
{ &st::foldersParty, &st::foldersPartyActive }, &st::filtersBotsActive,
{ &st::foldersSport, &st::foldersSportActive }, "\xF0\x9F\xA4\x96"_cs.utf16()
{ &st::foldersStudy, &st::foldersStudyActive }, },
{ &st::foldersTrade, &st::foldersTrade }, {
{ &st::foldersTravel, &st::foldersTravelActive }, &st::filtersChannels,
{ &st::foldersWork, &st::foldersWorkActive }, &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 } // namespace
@ -47,4 +140,19 @@ const FilterIcons &LookupFilterIcon(FilterIcon icon) {
return kIcons[static_cast<int>(icon)]; return kIcons[static_cast<int>(icon)];
} }
std::optional<FilterIcon> LookupFilterIconByEmoji(const QString &emoji) {
static const auto kMap = [] {
auto result = base::flat_map<EmojiPtr, FilterIcon>();
auto index = 0;
for (const auto &entry : kIcons) {
const auto emoji = Ui::Emoji::Find(entry.emoji);
Assert(emoji != nullptr);
result.emplace(emoji, static_cast<FilterIcon>(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 } // namespace Ui

View File

@ -45,8 +45,11 @@ enum class FilterIcon : uchar {
struct FilterIcons { struct FilterIcons {
not_null<const style::internal::Icon*> normal; not_null<const style::internal::Icon*> normal;
not_null<const style::internal::Icon*> active; not_null<const style::internal::Icon*> active;
QString emoji;
}; };
[[nodiscard]] const FilterIcons &LookupFilterIcon(FilterIcon icon); [[nodiscard]] const FilterIcons &LookupFilterIcon(FilterIcon icon);
[[nodiscard]] std::optional<FilterIcon> LookupFilterIconByEmoji(
const QString &emoji);
} // namespace Ui } // namespace Ui