mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Correctly clear unread reactions.
This commit is contained in:
parent
18919a6b4a
commit
07beb3e86b
6 changed files with 28 additions and 36 deletions
|
@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "lang/lang_cloud_manager.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_unread_things.h"
|
||||
#include "core/application.h"
|
||||
#include "storage/storage_account.h"
|
||||
#include "storage/storage_facade.h"
|
||||
|
@ -1630,8 +1631,13 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
d.vmsg_id().v);
|
||||
if (item) {
|
||||
item->updateReactions(&d.vreactions());
|
||||
} else if (Data::Reactions::HasUnread(d.vreactions())) {
|
||||
history->owner().histories().requestDialogEntry(history);
|
||||
} else {
|
||||
const auto hasUnreadReaction = Data::Reactions::HasUnread(
|
||||
d.vreactions());
|
||||
if (hasUnreadReaction || history->unreadReactions().has()) {
|
||||
// The unread reactions count could change.
|
||||
history->owner().histories().requestDialogEntry(history);
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
|
|
@ -601,14 +601,14 @@ bool MessageReactions::checkIfChanged(
|
|||
});
|
||||
}
|
||||
|
||||
void MessageReactions::set(
|
||||
bool MessageReactions::change(
|
||||
const QVector<MTPReactionCount> &list,
|
||||
const QVector<MTPMessagePeerReaction> &recent,
|
||||
bool ignoreChosen) {
|
||||
auto &owner = _item->history()->owner();
|
||||
if (owner.reactions().sending(_item)) {
|
||||
// We'll apply non-stale data from the request response.
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
auto changed = false;
|
||||
auto existing = base::flat_set<QString>();
|
||||
|
@ -663,10 +663,7 @@ void MessageReactions::set(
|
|||
_recent = std::move(parsed);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
owner.notifyItemDataChange(_item);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
const base::flat_map<QString, int> &MessageReactions::list() const {
|
||||
|
|
|
@ -150,7 +150,7 @@ public:
|
|||
|
||||
void add(const QString &reaction);
|
||||
void remove();
|
||||
void set(
|
||||
bool change(
|
||||
const QVector<MTPReactionCount> &list,
|
||||
const QVector<MTPMessagePeerReaction> &recent,
|
||||
bool ignoreChosen);
|
||||
|
|
|
@ -847,9 +847,14 @@ void HistoryItem::toggleReaction(const QString &reaction) {
|
|||
|
||||
void HistoryItem::updateReactions(const MTPMessageReactions *reactions) {
|
||||
const auto hadUnread = hasUnreadReaction();
|
||||
setReactions(reactions);
|
||||
const auto hasUnread = hasUnreadReaction();
|
||||
const auto changed = changeReactions(reactions);
|
||||
if (!changed) {
|
||||
return;
|
||||
}
|
||||
const auto hasUnread = _reactions && !_reactions->findUnread().isEmpty();
|
||||
if (hasUnread && !hadUnread) {
|
||||
_flags |= MessageFlag::HasUnreadReaction;
|
||||
|
||||
addToUnreadThings(HistoryUnreadThings::AddType::New);
|
||||
|
||||
// Call to addToUnreadThings may have read the reaction already.
|
||||
|
@ -864,38 +869,25 @@ void HistoryItem::updateReactions(const MTPMessageReactions *reactions) {
|
|||
} else if (!hasUnread && hadUnread) {
|
||||
markReactionsRead();
|
||||
}
|
||||
history()->owner().notifyItemDataChange(this);
|
||||
}
|
||||
|
||||
void HistoryItem::setReactions(const MTPMessageReactions *reactions) {
|
||||
bool HistoryItem::changeReactions(const MTPMessageReactions *reactions) {
|
||||
if (reactions || _reactionsLastRefreshed) {
|
||||
_reactionsLastRefreshed = crl::now();
|
||||
}
|
||||
if (!reactions) {
|
||||
_flags &= ~MessageFlag::CanViewReactions;
|
||||
if (_reactions) {
|
||||
_reactions = nullptr;
|
||||
if (hasUnreadReaction()) {
|
||||
markReactionsRead();
|
||||
}
|
||||
history()->owner().notifyItemDataChange(this);
|
||||
}
|
||||
return;
|
||||
return (base::take(_reactions) != nullptr);
|
||||
}
|
||||
reactions->match([&](const MTPDmessageReactions &data) {
|
||||
return reactions->match([&](const MTPDmessageReactions &data) {
|
||||
if (data.is_can_see_list()) {
|
||||
_flags |= MessageFlag::CanViewReactions;
|
||||
} else {
|
||||
_flags &= ~MessageFlag::CanViewReactions;
|
||||
}
|
||||
if (data.vresults().v.isEmpty()) {
|
||||
if (_reactions) {
|
||||
_reactions = nullptr;
|
||||
if (hasUnreadReaction()) {
|
||||
markReactionsRead();
|
||||
}
|
||||
history()->owner().notifyItemDataChange(this);
|
||||
}
|
||||
return;
|
||||
return (base::take(_reactions) != nullptr);
|
||||
} else if (!_reactions) {
|
||||
_reactions = std::make_unique<Data::MessageReactions>(this);
|
||||
}
|
||||
|
@ -907,12 +899,9 @@ void HistoryItem::setReactions(const MTPMessageReactions *reactions) {
|
|||
if (_reactions->checkIfChanged(list, recent)) {
|
||||
updateReactionsUnknown();
|
||||
}
|
||||
} else {
|
||||
_reactions->set(list, recent, min);
|
||||
if (!_reactions->findUnread().isEmpty()) {
|
||||
_flags |= MessageFlag::HasUnreadReaction;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return _reactions->change(list, recent, min);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -462,7 +462,7 @@ protected:
|
|||
void finishEdition(int oldKeyboardTop);
|
||||
void finishEditionToEmpty();
|
||||
|
||||
void setReactions(const MTPMessageReactions *reactions);
|
||||
bool changeReactions(const MTPMessageReactions *reactions);
|
||||
|
||||
const not_null<History*> _history;
|
||||
const not_null<PeerData*> _from;
|
||||
|
|
|
@ -513,7 +513,7 @@ HistoryMessage::HistoryMessage(
|
|||
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
||||
}
|
||||
if (const auto reactions = data.vreactions()) {
|
||||
setReactions(reactions);
|
||||
changeReactions(reactions);
|
||||
}
|
||||
|
||||
applyTTL(data);
|
||||
|
|
Loading…
Add table
Reference in a new issue