mirror of https://github.com/procxx/kepka.git
Add unread counter from feed to common counter.
This commit is contained in:
parent
17a4d19beb
commit
336e691dbc
|
@ -359,17 +359,43 @@ void Feed::applyDialog(const MTPDdialogFeed &data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Feed::changedInChatListHook(Dialogs::Mode list, bool added) {
|
||||||
|
if (list == Dialogs::Mode::All && unreadCount()) {
|
||||||
|
const auto mutedCount = _unreadMutedCount;
|
||||||
|
const auto nonMutedCount = unreadCount() - mutedCount;
|
||||||
|
const auto mutedDelta = added ? mutedCount : -mutedCount;
|
||||||
|
const auto nonMutedDelta = added ? nonMutedCount : -nonMutedCount;
|
||||||
|
App::histories().unreadIncrement(nonMutedDelta, false);
|
||||||
|
App::histories().unreadIncrement(mutedDelta, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Feed::setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount) {
|
void Feed::setUnreadCounts(int unreadNonMutedCount, int unreadMutedCount) {
|
||||||
if (unreadCountKnown()
|
if (unreadCountKnown()
|
||||||
&& (*_unreadCount == unreadNonMutedCount + unreadMutedCount)
|
&& (*_unreadCount == unreadNonMutedCount + unreadMutedCount)
|
||||||
&& (_unreadMutedCount == unreadMutedCount)) {
|
&& (_unreadMutedCount == unreadMutedCount)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const auto unreadNonMutedCountDelta = _unreadCount | [&](int count) {
|
||||||
|
return unreadNonMutedCount - (count - _unreadMutedCount);
|
||||||
|
};
|
||||||
|
const auto unreadMutedCountDelta = _unreadCount | [&](int count) {
|
||||||
|
return unreadMutedCount - _unreadMutedCount;
|
||||||
|
};
|
||||||
_unreadCount = unreadNonMutedCount + unreadMutedCount;
|
_unreadCount = unreadNonMutedCount + unreadMutedCount;
|
||||||
_unreadMutedCount = unreadMutedCount;
|
_unreadMutedCount = unreadMutedCount;
|
||||||
|
|
||||||
_unreadCountChanges.fire(unreadCount());
|
_unreadCountChanges.fire(unreadCount());
|
||||||
updateChatListEntry();
|
updateChatListEntry();
|
||||||
|
|
||||||
|
if (inChatList(Dialogs::Mode::All)) {
|
||||||
|
App::histories().unreadIncrement(
|
||||||
|
unreadNonMutedCountDelta ? *unreadNonMutedCountDelta : unreadNonMutedCount,
|
||||||
|
false);
|
||||||
|
App::histories().unreadIncrement(
|
||||||
|
unreadMutedCountDelta ? *unreadMutedCountDelta : unreadMutedCount,
|
||||||
|
true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Feed::setUnreadPosition(const MessagePosition &position) {
|
void Feed::setUnreadPosition(const MessagePosition &position) {
|
||||||
|
@ -384,14 +410,24 @@ void Feed::unreadCountChanged(
|
||||||
if (!unreadCountKnown()) {
|
if (!unreadCountKnown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*_unreadCount = std::max(*_unreadCount + unreadCountDelta, 0);
|
accumulate_max(unreadCountDelta, -*_unreadCount);
|
||||||
_unreadMutedCount = snap(
|
*_unreadCount += unreadCountDelta;
|
||||||
_unreadMutedCount + mutedCountDelta,
|
|
||||||
0,
|
mutedCountDelta = snap(
|
||||||
*_unreadCount);
|
mutedCountDelta,
|
||||||
|
-_unreadMutedCount,
|
||||||
|
*_unreadCount - _unreadMutedCount);
|
||||||
|
_unreadMutedCount += mutedCountDelta;
|
||||||
|
|
||||||
_unreadCountChanges.fire(unreadCount());
|
_unreadCountChanges.fire(unreadCount());
|
||||||
updateChatListEntry();
|
updateChatListEntry();
|
||||||
|
|
||||||
|
if (inChatList(Dialogs::Mode::All)) {
|
||||||
|
App::histories().unreadIncrement(
|
||||||
|
unreadCountDelta,
|
||||||
|
false);
|
||||||
|
App::histories().unreadMuteChanged(mutedCountDelta, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePosition Feed::unreadPosition() const {
|
MessagePosition Feed::unreadPosition() const {
|
||||||
|
|
|
@ -67,6 +67,7 @@ public:
|
||||||
const QString &chatsListName() const override;
|
const QString &chatsListName() const override;
|
||||||
const base::flat_set<QString> &chatsListNameWords() const override;
|
const base::flat_set<QString> &chatsListNameWords() const override;
|
||||||
const base::flat_set<QChar> &chatsListFirstLetters() const override;
|
const base::flat_set<QChar> &chatsListFirstLetters() const override;
|
||||||
|
void changedInChatListHook(Dialogs::Mode list, bool added) override;
|
||||||
|
|
||||||
void loadUserpic() override;
|
void loadUserpic() override;
|
||||||
void paintUserpic(
|
void paintUserpic(
|
||||||
|
|
|
@ -162,6 +162,29 @@ int Histories::unreadBadge() const {
|
||||||
return _unreadFull - (Global::IncludeMuted() ? 0 : _unreadMuted);
|
return _unreadFull - (Global::IncludeMuted() ? 0 : _unreadMuted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Histories::unreadMutedCount() const {
|
||||||
|
return _unreadMuted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Histories::unreadIncrement(int count, bool muted) {
|
||||||
|
_unreadFull += count;
|
||||||
|
if (muted) {
|
||||||
|
_unreadMuted += count;
|
||||||
|
}
|
||||||
|
if (!muted || Global::IncludeMuted()) {
|
||||||
|
Notify::unreadCounterUpdated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Histories::unreadMuteChanged(int count, bool muted) {
|
||||||
|
if (muted) {
|
||||||
|
_unreadMuted += count;
|
||||||
|
} else {
|
||||||
|
_unreadMuted -= count;
|
||||||
|
}
|
||||||
|
Notify::unreadCounterUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
bool Histories::unreadOnlyMuted() const {
|
bool Histories::unreadOnlyMuted() const {
|
||||||
return Global::IncludeMuted() ? (_unreadMuted >= _unreadFull) : false;
|
return Global::IncludeMuted() ? (_unreadMuted >= _unreadFull) : false;
|
||||||
}
|
}
|
||||||
|
@ -1642,9 +1665,6 @@ void History::setUnreadCount(int newUnreadCount) {
|
||||||
App::histories().unreadIncrement(
|
App::histories().unreadIncrement(
|
||||||
unreadCountDelta ? *unreadCountDelta : newUnreadCount,
|
unreadCountDelta ? *unreadCountDelta : newUnreadCount,
|
||||||
mute());
|
mute());
|
||||||
if (!mute() || Global::IncludeMuted()) {
|
|
||||||
Notify::unreadCounterUpdated();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (const auto main = App::main()) {
|
if (const auto main = App::main()) {
|
||||||
main->unreadCountChanged(this);
|
main->unreadCountChanged(this);
|
||||||
|
@ -2580,7 +2600,6 @@ void History::changedInChatListHook(Dialogs::Mode list, bool added) {
|
||||||
if (list == Dialogs::Mode::All && unreadCount()) {
|
if (list == Dialogs::Mode::All && unreadCount()) {
|
||||||
const auto delta = added ? unreadCount() : -unreadCount();
|
const auto delta = added ? unreadCount() : -unreadCount();
|
||||||
App::histories().unreadIncrement(delta, mute());
|
App::histories().unreadIncrement(delta, mute());
|
||||||
Notify::unreadCounterUpdated();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,23 +72,10 @@ public:
|
||||||
BasicAnimation _a_typings;
|
BasicAnimation _a_typings;
|
||||||
|
|
||||||
int unreadBadge() const;
|
int unreadBadge() const;
|
||||||
int unreadMutedCount() const {
|
int unreadMutedCount() const;
|
||||||
return _unreadMuted;
|
|
||||||
}
|
|
||||||
bool unreadOnlyMuted() const;
|
bool unreadOnlyMuted() const;
|
||||||
void unreadIncrement(int32 count, bool muted) {
|
void unreadIncrement(int count, bool muted);
|
||||||
_unreadFull += count;
|
void unreadMuteChanged(int count, bool muted);
|
||||||
if (muted) {
|
|
||||||
_unreadMuted += count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void unreadMuteChanged(int32 count, bool muted) {
|
|
||||||
if (muted) {
|
|
||||||
_unreadMuted += count;
|
|
||||||
} else {
|
|
||||||
_unreadMuted -= count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SendActionAnimationUpdate {
|
struct SendActionAnimationUpdate {
|
||||||
History *history;
|
History *history;
|
||||||
|
|
|
@ -160,9 +160,11 @@ std::unique_ptr<PeerListState> ChannelsController::saveState() const {
|
||||||
auto result = PeerListController::saveState();
|
auto result = PeerListController::saveState();
|
||||||
auto my = std::make_unique<SavedState>();
|
auto my = std::make_unique<SavedState>();
|
||||||
using Flag = Data::FeedUpdateFlag;
|
using Flag = Data::FeedUpdateFlag;
|
||||||
|
|
||||||
|
// Must not capture `this` here, because it dies before my->lifetime.
|
||||||
Auth().data().feedUpdated(
|
Auth().data().feedUpdated(
|
||||||
) | rpl::filter([=](const Data::FeedUpdate &update) {
|
) | rpl::filter([feed = _feed](const Data::FeedUpdate &update) {
|
||||||
return (update.feed == _feed) && (update.flag == Flag::Channels);
|
return (update.feed == feed) && (update.flag == Flag::Channels);
|
||||||
}) | rpl::start_with_next([state = result.get()] {
|
}) | rpl::start_with_next([state = result.get()] {
|
||||||
state->controllerState = nullptr;
|
state->controllerState = nullptr;
|
||||||
}, my->lifetime);
|
}, my->lifetime);
|
||||||
|
|
Loading…
Reference in New Issue