mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fixed display of unread state in chats filters strip after reorder.
This commit is contained in:
parent
683c3c4f36
commit
a6030d708d
1 changed files with 31 additions and 24 deletions
|
@ -42,6 +42,7 @@ struct State final {
|
||||||
Ui::Animations::Simple animation;
|
Ui::Animations::Simple animation;
|
||||||
std::optional<FilterId> lastFilterId = std::nullopt;
|
std::optional<FilterId> lastFilterId = std::nullopt;
|
||||||
rpl::lifetime rebuildLifetime;
|
rpl::lifetime rebuildLifetime;
|
||||||
|
rpl::lifetime reorderLifetime;
|
||||||
base::unique_qptr<Ui::PopupMenu> menu;
|
base::unique_qptr<Ui::PopupMenu> menu;
|
||||||
|
|
||||||
Api::RemoveComplexChatFilter removeApi;
|
Api::RemoveComplexChatFilter removeApi;
|
||||||
|
@ -199,6 +200,33 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
|
||||||
? st::dialogsSearchTabs
|
? st::dialogsSearchTabs
|
||||||
: st::chatsFiltersTabs));
|
: st::chatsFiltersTabs));
|
||||||
const auto state = wrap->lifetime().make_state<State>();
|
const auto state = wrap->lifetime().make_state<State>();
|
||||||
|
const auto reassignUnreadValue = [=] {
|
||||||
|
const auto &list = session->data().chatsFilters().list();
|
||||||
|
auto includeMuted = Data::IncludeMutedCounterFoldersValue();
|
||||||
|
for (auto i = 0; i < list.size(); i++) {
|
||||||
|
rpl::combine(
|
||||||
|
Data::UnreadStateValue(session, list[i].id()),
|
||||||
|
rpl::duplicate(includeMuted)
|
||||||
|
) | rpl::start_with_next([=](
|
||||||
|
const Dialogs::UnreadState &state,
|
||||||
|
bool includeMuted) {
|
||||||
|
const auto chats = state.chatsTopic
|
||||||
|
? (state.chats - state.chatsTopic + state.forums)
|
||||||
|
: state.chats;
|
||||||
|
const auto chatsMuted = state.chatsTopicMuted
|
||||||
|
? (state.chatsMuted
|
||||||
|
- state.chatsTopicMuted
|
||||||
|
+ state.forumsMuted)
|
||||||
|
: state.chatsMuted;
|
||||||
|
const auto muted = (chatsMuted + state.marksMuted);
|
||||||
|
const auto count = (chats + state.marks)
|
||||||
|
- (includeMuted ? 0 : muted);
|
||||||
|
const auto isMuted = includeMuted && (count == muted);
|
||||||
|
slider->setUnreadCount(i, count, isMuted);
|
||||||
|
slider->fitWidthToSections();
|
||||||
|
}, state->reorderLifetime);
|
||||||
|
}
|
||||||
|
};
|
||||||
if (trackActiveFilterAndUnreadAndReorder) {
|
if (trackActiveFilterAndUnreadAndReorder) {
|
||||||
using Reorder = Ui::ChatsFiltersTabsReorder;
|
using Reorder = Ui::ChatsFiltersTabsReorder;
|
||||||
state->reorder = std::make_unique<Reorder>(slider, scroll);
|
state->reorder = std::make_unique<Reorder>(slider, scroll);
|
||||||
|
@ -241,6 +269,8 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
|
||||||
});
|
});
|
||||||
if (data.state == Reorder::State::Applied) {
|
if (data.state == Reorder::State::Applied) {
|
||||||
applyReorder(data.oldPosition, data.newPosition);
|
applyReorder(data.oldPosition, data.newPosition);
|
||||||
|
state->reorderLifetime.destroy();
|
||||||
|
reassignUnreadValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, slider->lifetime());
|
}, slider->lifetime());
|
||||||
|
@ -329,30 +359,7 @@ not_null<Ui::RpWidget*> AddChatFiltersTabsStrip(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trackActiveFilterAndUnreadAndReorder) {
|
if (trackActiveFilterAndUnreadAndReorder) {
|
||||||
auto includeMuted = Data::IncludeMutedCounterFoldersValue();
|
reassignUnreadValue();
|
||||||
for (auto i = 0; i < list.size(); i++) {
|
|
||||||
rpl::combine(
|
|
||||||
Data::UnreadStateValue(session, list[i].id()),
|
|
||||||
rpl::duplicate(includeMuted)
|
|
||||||
) | rpl::start_with_next([=](
|
|
||||||
const Dialogs::UnreadState &state,
|
|
||||||
bool includeMuted) {
|
|
||||||
const auto chats = state.chatsTopic
|
|
||||||
? (state.chats - state.chatsTopic + state.forums)
|
|
||||||
: state.chats;
|
|
||||||
const auto chatsMuted = state.chatsTopicMuted
|
|
||||||
? (state.chatsMuted
|
|
||||||
- state.chatsTopicMuted
|
|
||||||
+ state.forumsMuted)
|
|
||||||
: state.chatsMuted;
|
|
||||||
const auto muted = (chatsMuted + state.marksMuted);
|
|
||||||
const auto count = (chats + state.marks)
|
|
||||||
- (includeMuted ? 0 : muted);
|
|
||||||
const auto isMuted = includeMuted && (count == muted);
|
|
||||||
slider->setUnreadCount(i, count, isMuted);
|
|
||||||
slider->fitWidthToSections();
|
|
||||||
}, state->rebuildLifetime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
[&] {
|
[&] {
|
||||||
const auto lookingId = state->lastFilterId.value_or(list[0].id());
|
const auto lookingId = state->lastFilterId.value_or(list[0].id());
|
||||||
|
|
Loading…
Add table
Reference in a new issue