mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added api support for enabled tags of chats filters.
This commit is contained in:
parent
e314c68a56
commit
ba082081b3
5 changed files with 72 additions and 23 deletions
|
@ -377,6 +377,7 @@ void ChatFilters::load(bool force) {
|
||||||
api.request(_loadRequestId).cancel();
|
api.request(_loadRequestId).cancel();
|
||||||
_loadRequestId = api.request(MTPmessages_GetDialogFilters(
|
_loadRequestId = api.request(MTPmessages_GetDialogFilters(
|
||||||
)).done([=](const MTPmessages_DialogFilters &result) {
|
)).done([=](const MTPmessages_DialogFilters &result) {
|
||||||
|
_tagsEnabled = result.data().is_tags_enabled();
|
||||||
received(result.data().vfilters().v);
|
received(result.data().vfilters().v);
|
||||||
_loadRequestId = 0;
|
_loadRequestId = 0;
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
|
@ -388,6 +389,14 @@ void ChatFilters::load(bool force) {
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ChatFilters::tagsEnabled() const {
|
||||||
|
return _tagsEnabled.current();
|
||||||
|
}
|
||||||
|
|
||||||
|
rpl::producer<bool> ChatFilters::tagsEnabledValue() const {
|
||||||
|
return _tagsEnabled.value();
|
||||||
|
}
|
||||||
|
|
||||||
void ChatFilters::received(const QVector<MTPDialogFilter> &list) {
|
void ChatFilters::received(const QVector<MTPDialogFilter> &list) {
|
||||||
auto position = 0;
|
auto position = 0;
|
||||||
auto changed = false;
|
auto changed = false;
|
||||||
|
@ -619,7 +628,8 @@ bool ChatFilters::applyChange(ChatFilter &filter, ChatFilter &&updated) {
|
||||||
|| pinnedChanged
|
|| pinnedChanged
|
||||||
|| (filter.title() != updated.title())
|
|| (filter.title() != updated.title())
|
||||||
|| (filter.iconEmoji() != updated.iconEmoji());
|
|| (filter.iconEmoji() != updated.iconEmoji());
|
||||||
if (!listUpdated && !chatlistChanged) {
|
const auto colorChanged = filter.colorIndex() != updated.colorIndex();
|
||||||
|
if (!listUpdated && !chatlistChanged && !colorChanged) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto wasFilter = std::move(filter);
|
const auto wasFilter = std::move(filter);
|
||||||
|
@ -627,8 +637,9 @@ bool ChatFilters::applyChange(ChatFilter &filter, ChatFilter &&updated) {
|
||||||
auto entryToRefreshHeight = (Dialogs::Entry*)(nullptr);
|
auto entryToRefreshHeight = (Dialogs::Entry*)(nullptr);
|
||||||
if (rulesChanged) {
|
if (rulesChanged) {
|
||||||
const auto filterList = _owner->chatsFilters().chatsList(id);
|
const auto filterList = _owner->chatsFilters().chatsList(id);
|
||||||
|
const auto areTagsEnabled = tagsEnabled();
|
||||||
const auto tagsExistence = [&](not_null<Dialogs::Row*> row) {
|
const auto tagsExistence = [&](not_null<Dialogs::Row*> row) {
|
||||||
return entryToRefreshHeight
|
return (!areTagsEnabled || entryToRefreshHeight)
|
||||||
? false
|
? false
|
||||||
: row->entry()->hasChatsFilterTags(0);
|
: row->entry()->hasChatsFilterTags(0);
|
||||||
};
|
};
|
||||||
|
@ -672,6 +683,9 @@ bool ChatFilters::applyChange(ChatFilter &filter, ChatFilter &&updated) {
|
||||||
if (chatlistChanged) {
|
if (chatlistChanged) {
|
||||||
_isChatlistChanged.fire_copy(id);
|
_isChatlistChanged.fire_copy(id);
|
||||||
}
|
}
|
||||||
|
if (colorChanged) {
|
||||||
|
_tagColorChanged.fire_copy(id);
|
||||||
|
}
|
||||||
if (entryToRefreshHeight) {
|
if (entryToRefreshHeight) {
|
||||||
// Trigger a full refresh of height for the main list.
|
// Trigger a full refresh of height for the main list.
|
||||||
entryToRefreshHeight->updateChatListEntryHeight();
|
entryToRefreshHeight->updateChatListEntryHeight();
|
||||||
|
@ -818,6 +832,10 @@ rpl::producer<FilterId> ChatFilters::isChatlistChanged() const {
|
||||||
return _isChatlistChanged.events();
|
return _isChatlistChanged.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<FilterId> ChatFilters::tagColorChanged() const {
|
||||||
|
return _tagColorChanged.events();
|
||||||
|
}
|
||||||
|
|
||||||
bool ChatFilters::loadNextExceptions(bool chatsListLoaded) {
|
bool ChatFilters::loadNextExceptions(bool chatsListLoaded) {
|
||||||
if (_exceptionsLoadRequestId) {
|
if (_exceptionsLoadRequestId) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -139,6 +139,7 @@ public:
|
||||||
[[nodiscard]] const std::vector<ChatFilter> &list() const;
|
[[nodiscard]] const std::vector<ChatFilter> &list() const;
|
||||||
[[nodiscard]] rpl::producer<> changed() const;
|
[[nodiscard]] rpl::producer<> changed() const;
|
||||||
[[nodiscard]] rpl::producer<FilterId> isChatlistChanged() const;
|
[[nodiscard]] rpl::producer<FilterId> isChatlistChanged() const;
|
||||||
|
[[nodiscard]] rpl::producer<FilterId> tagColorChanged() const;
|
||||||
[[nodiscard]] bool loaded() const;
|
[[nodiscard]] bool loaded() const;
|
||||||
[[nodiscard]] bool has() const;
|
[[nodiscard]] bool has() const;
|
||||||
|
|
||||||
|
@ -185,6 +186,9 @@ public:
|
||||||
FilterId id) const;
|
FilterId id) const;
|
||||||
void moreChatsHide(FilterId id, bool localOnly = false);
|
void moreChatsHide(FilterId id, bool localOnly = false);
|
||||||
|
|
||||||
|
[[nodiscard]] bool tagsEnabled() const;
|
||||||
|
[[nodiscard]] rpl::producer<bool> tagsEnabledValue() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct MoreChatsData {
|
struct MoreChatsData {
|
||||||
std::vector<not_null<PeerData*>> missing;
|
std::vector<not_null<PeerData*>> missing;
|
||||||
|
@ -209,6 +213,7 @@ private:
|
||||||
base::flat_map<FilterId, std::unique_ptr<Dialogs::MainList>> _chatsLists;
|
base::flat_map<FilterId, std::unique_ptr<Dialogs::MainList>> _chatsLists;
|
||||||
rpl::event_stream<> _listChanged;
|
rpl::event_stream<> _listChanged;
|
||||||
rpl::event_stream<FilterId> _isChatlistChanged;
|
rpl::event_stream<FilterId> _isChatlistChanged;
|
||||||
|
rpl::event_stream<FilterId> _tagColorChanged;
|
||||||
mtpRequestId _loadRequestId = 0;
|
mtpRequestId _loadRequestId = 0;
|
||||||
mtpRequestId _saveOrderRequestId = 0;
|
mtpRequestId _saveOrderRequestId = 0;
|
||||||
mtpRequestId _saveOrderAfterId = 0;
|
mtpRequestId _saveOrderAfterId = 0;
|
||||||
|
@ -220,6 +225,8 @@ private:
|
||||||
rpl::event_stream<> _suggestedUpdated;
|
rpl::event_stream<> _suggestedUpdated;
|
||||||
crl::time _suggestedLastReceived = 0;
|
crl::time _suggestedLastReceived = 0;
|
||||||
|
|
||||||
|
rpl::variable<bool> _tagsEnabled = false;
|
||||||
|
|
||||||
std::deque<FilterId> _exceptionsToLoad;
|
std::deque<FilterId> _exceptionsToLoad;
|
||||||
mtpRequestId _exceptionsLoadRequestId = 0;
|
mtpRequestId _exceptionsLoadRequestId = 0;
|
||||||
|
|
||||||
|
|
|
@ -415,6 +415,9 @@ void Entry::updateChatListEntryHeight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool Entry::hasChatsFilterTags(FilterId exclude) const {
|
[[nodiscard]] bool Entry::hasChatsFilterTags(FilterId exclude) const {
|
||||||
|
if (!owner().chatsFilters().tagsEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (exclude) {
|
if (exclude) {
|
||||||
if (_tagColors.size() == 1) {
|
if (_tagColors.size() == 1) {
|
||||||
if (_tagColors.begin()->first == exclude) {
|
if (_tagColors.begin()->first == exclude) {
|
||||||
|
|
|
@ -297,6 +297,47 @@ InnerWidget::InnerWidget(
|
||||||
refreshWithCollapsedRows();
|
refreshWithCollapsedRows();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
session().data().chatsFilters().tagsEnabledValue(
|
||||||
|
) | rpl::distinct_until_changed() | rpl::start_with_next([=](bool tags) {
|
||||||
|
_handleChatListEntryTagRefreshesLifetime.destroy();
|
||||||
|
if (_shownList->updateHeights(_narrowRatio)) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
if (!tags) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using Event = Data::Session::ChatListEntryRefresh;
|
||||||
|
session().data().chatListEntryRefreshes(
|
||||||
|
) | rpl::filter([=](const Event &event) {
|
||||||
|
if (_waitingAllChatListEntryRefreshesForTags) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (event.existenceChanged) {
|
||||||
|
if (event.key.entry()->inChatList(_filterId)) {
|
||||||
|
_waitingAllChatListEntryRefreshesForTags = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}) | rpl::start_with_next([=](const Event &event) {
|
||||||
|
Ui::PostponeCall(crl::guard(this, [=] {
|
||||||
|
_waitingAllChatListEntryRefreshesForTags = false;
|
||||||
|
if (_shownList->updateHeights(_narrowRatio)) {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}, _handleChatListEntryTagRefreshesLifetime);
|
||||||
|
|
||||||
|
session().data().chatsFilters().tagColorChanged(
|
||||||
|
) | rpl::start_with_next([=](FilterId filterId) {
|
||||||
|
const auto it = _chatsFilterTags.find(filterId);
|
||||||
|
if (it != _chatsFilterTags.end()) {
|
||||||
|
_chatsFilterTags.erase(it);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}, _handleChatListEntryTagRefreshesLifetime);
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
session().settings().archiveInMainMenuChanges(
|
session().settings().archiveInMainMenuChanges(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -2260,27 +2301,6 @@ void InnerWidget::handleChatListEntryRefreshes() {
|
||||||
std::abs(from - to) + event.moved.height);
|
std::abs(from - to) + event.moved.height);
|
||||||
}
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
session().data().chatListEntryRefreshes(
|
|
||||||
) | rpl::filter([=](const Event &event) {
|
|
||||||
if (_waitingAllChatListEntryRefreshesForTags) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (event.existenceChanged) {
|
|
||||||
if (event.key.entry()->inChatList(_filterId)) {
|
|
||||||
_waitingAllChatListEntryRefreshesForTags = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}) | rpl::start_with_next([=](const Event &event) {
|
|
||||||
Ui::PostponeCall(crl::guard(this, [=] {
|
|
||||||
_waitingAllChatListEntryRefreshesForTags = false;
|
|
||||||
if (_shownList->updateHeights(_narrowRatio)) {
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}, lifetime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerWidget::repaintCollapsedFolderRow(not_null<Data::Folder*> folder) {
|
void InnerWidget::repaintCollapsedFolderRow(not_null<Data::Folder*> folder) {
|
||||||
|
|
|
@ -558,6 +558,7 @@ private:
|
||||||
|
|
||||||
std::unordered_map<FilterId, QImage> _chatsFilterTags;
|
std::unordered_map<FilterId, QImage> _chatsFilterTags;
|
||||||
bool _waitingAllChatListEntryRefreshesForTags = false;
|
bool _waitingAllChatListEntryRefreshesForTags = false;
|
||||||
|
rpl::lifetime _handleChatListEntryTagRefreshesLifetime;
|
||||||
|
|
||||||
Fn<void()> _loadMoreCallback;
|
Fn<void()> _loadMoreCallback;
|
||||||
Fn<void()> _loadMoreFilteredCallback;
|
Fn<void()> _loadMoreFilteredCallback;
|
||||||
|
|
Loading…
Add table
Reference in a new issue