mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Improve unread reactions list consistency.
This commit is contained in:
parent
63bf564757
commit
b7a70a2f28
9 changed files with 65 additions and 33 deletions
|
@ -101,7 +101,7 @@ void UnreadThings::requestMentions(not_null<History*> history, int loaded) {
|
||||||
MTP_int(minId)
|
MTP_int(minId)
|
||||||
)).done([=](const MTPmessages_Messages &result) {
|
)).done([=](const MTPmessages_Messages &result) {
|
||||||
_mentionsRequests.remove(history);
|
_mentionsRequests.remove(history);
|
||||||
history->unreadMentions().addSlice(result);
|
history->unreadMentions().addSlice(result, loaded);
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
_mentionsRequests.remove(history);
|
_mentionsRequests.remove(history);
|
||||||
}).send();
|
}).send();
|
||||||
|
@ -112,9 +112,9 @@ void UnreadThings::requestReactions(not_null<History*> history, int loaded) {
|
||||||
if (_reactionsRequests.contains(history)) {
|
if (_reactionsRequests.contains(history)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto offsetId = std::max(
|
const auto offsetId = loaded
|
||||||
history->unreadMentions().maxLoaded(),
|
? std::max(history->unreadReactions().maxLoaded(), MsgId(1))
|
||||||
MsgId(1));
|
: MsgId(1);
|
||||||
const auto limit = loaded ? kNextRequestLimit : kFirstRequestLimit;
|
const auto limit = loaded ? kNextRequestLimit : kFirstRequestLimit;
|
||||||
const auto addOffset = loaded ? -(limit + 1) : -limit;
|
const auto addOffset = loaded ? -(limit + 1) : -limit;
|
||||||
const auto maxId = 0;
|
const auto maxId = 0;
|
||||||
|
@ -128,8 +128,8 @@ void UnreadThings::requestReactions(not_null<History*> history, int loaded) {
|
||||||
MTP_int(minId)
|
MTP_int(minId)
|
||||||
)).done([=](const MTPmessages_Messages &result) {
|
)).done([=](const MTPmessages_Messages &result) {
|
||||||
_reactionsRequests.remove(history);
|
_reactionsRequests.remove(history);
|
||||||
history->unreadReactions().addSlice(result);
|
history->unreadReactions().addSlice(result, loaded);
|
||||||
}).fail([this, history] {
|
}).fail([=] {
|
||||||
_reactionsRequests.remove(history);
|
_reactionsRequests.remove(history);
|
||||||
}).send();
|
}).send();
|
||||||
_reactionsRequests.emplace(history, requestId);
|
_reactionsRequests.emplace(history, requestId);
|
||||||
|
|
|
@ -1638,6 +1638,9 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
||||||
// The unread reactions count could change.
|
// The unread reactions count could change.
|
||||||
history->owner().histories().requestDialogEntry(history);
|
history->owner().histories().requestDialogEntry(history);
|
||||||
}
|
}
|
||||||
|
if (hasUnreadReaction) {
|
||||||
|
history->unreadReactions().checkAdd(d.vmsg_id().v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
|
@ -679,14 +679,13 @@ bool MessageReactions::empty() const {
|
||||||
return _list.empty();
|
return _list.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessageReactions::findUnread() const {
|
bool MessageReactions::hasUnread() const {
|
||||||
for (auto &[emoji, list] : _recent) {
|
for (auto &[emoji, list] : _recent) {
|
||||||
const auto i = ranges::find(list, true, &RecentReaction::unread);
|
if (ranges::contains(list, true, &RecentReaction::unread)) {
|
||||||
if (i != end(list)) {
|
return true;
|
||||||
return emoji;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QString();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageReactions::markRead() {
|
void MessageReactions::markRead() {
|
||||||
|
|
|
@ -163,7 +163,7 @@ public:
|
||||||
[[nodiscard]] QString chosen() const;
|
[[nodiscard]] QString chosen() const;
|
||||||
[[nodiscard]] bool empty() const;
|
[[nodiscard]] bool empty() const;
|
||||||
|
|
||||||
[[nodiscard]] QString findUnread() const;
|
[[nodiscard]] bool hasUnread() const;
|
||||||
void markRead();
|
void markRead();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -200,6 +200,7 @@ using OnStackUsers = std::array<UserData*, kMaxUnreadReactions>;
|
||||||
void CheckReactionNotificationSchedule(
|
void CheckReactionNotificationSchedule(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
const OnStackUsers &wasUsers) {
|
const OnStackUsers &wasUsers) {
|
||||||
|
// Call to addToUnreadThings may have read the reaction already.
|
||||||
if (!item->hasUnreadReaction()) {
|
if (!item->hasUnreadReaction()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -897,6 +898,14 @@ void HistoryItem::toggleReaction(const QString &reaction) {
|
||||||
history()->owner().notifyItemDataChange(this);
|
history()->owner().notifyItemDataChange(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryItem::setReactions(const MTPMessageReactions *reactions) {
|
||||||
|
Expects(!_reactions);
|
||||||
|
|
||||||
|
if (changeReactions(reactions) && _reactions->hasUnread()) {
|
||||||
|
_flags |= MessageFlag::HasUnreadReaction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryItem::updateReactions(const MTPMessageReactions *reactions) {
|
void HistoryItem::updateReactions(const MTPMessageReactions *reactions) {
|
||||||
const auto wasRecentUsers = LookupRecentReactedUsers(this);
|
const auto wasRecentUsers = LookupRecentReactedUsers(this);
|
||||||
const auto hadUnread = hasUnreadReaction();
|
const auto hadUnread = hasUnreadReaction();
|
||||||
|
@ -904,15 +913,11 @@ void HistoryItem::updateReactions(const MTPMessageReactions *reactions) {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto hasUnread = _reactions && !_reactions->findUnread().isEmpty();
|
const auto hasUnread = _reactions && _reactions->hasUnread();
|
||||||
if (hasUnread && !hadUnread) {
|
if (hasUnread && !hadUnread) {
|
||||||
_flags |= MessageFlag::HasUnreadReaction;
|
_flags |= MessageFlag::HasUnreadReaction;
|
||||||
|
|
||||||
addToUnreadThings(HistoryUnreadThings::AddType::New);
|
addToUnreadThings(HistoryUnreadThings::AddType::New);
|
||||||
|
|
||||||
// Call to addToUnreadThings may have read the reaction already.
|
|
||||||
if (hasUnreadReaction()) {
|
|
||||||
}
|
|
||||||
} else if (!hasUnread && hadUnread) {
|
} else if (!hasUnread && hadUnread) {
|
||||||
markReactionsRead();
|
markReactionsRead();
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,7 +454,8 @@ protected:
|
||||||
void finishEdition(int oldKeyboardTop);
|
void finishEdition(int oldKeyboardTop);
|
||||||
void finishEditionToEmpty();
|
void finishEditionToEmpty();
|
||||||
|
|
||||||
bool changeReactions(const MTPMessageReactions *reactions);
|
void setReactions(const MTPMessageReactions *reactions);
|
||||||
|
[[nodiscard]] bool changeReactions(const MTPMessageReactions *reactions);
|
||||||
|
|
||||||
const not_null<History*> _history;
|
const not_null<History*> _history;
|
||||||
const not_null<PeerData*> _from;
|
const not_null<PeerData*> _from;
|
||||||
|
|
|
@ -512,10 +512,7 @@ HistoryMessage::HistoryMessage(
|
||||||
setGroupId(
|
setGroupId(
|
||||||
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
MessageGroupId::FromRaw(history->peer->id, groupedId->v));
|
||||||
}
|
}
|
||||||
if (const auto reactions = data.vreactions()) {
|
setReactions(data.vreactions());
|
||||||
changeReactions(reactions);
|
|
||||||
}
|
|
||||||
|
|
||||||
applyTTL(data);
|
applyTTL(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_item.h"
|
#include "history/history_item.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
#include "apiwrap.h"
|
||||||
|
|
||||||
namespace HistoryUnreadThings {
|
namespace HistoryUnreadThings {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -78,7 +79,7 @@ bool Proxy::add(MsgId msgId, AddType type) {
|
||||||
const auto loaded = list.loadedCount();
|
const auto loaded = list.loadedCount();
|
||||||
const auto allLoaded = (count >= 0) && (loaded >= count);
|
const auto allLoaded = (count >= 0) && (loaded >= count);
|
||||||
if (allLoaded) {
|
if (allLoaded) {
|
||||||
if (type == AddType::New) {
|
if (type == AddType::New || !list.contains(msgId)) {
|
||||||
list.insert(msgId);
|
list.insert(msgId);
|
||||||
setCount(count + 1);
|
setCount(count + 1);
|
||||||
return true;
|
return true;
|
||||||
|
@ -117,7 +118,10 @@ void Proxy::clear() {
|
||||||
UpdateFlag(_type));
|
UpdateFlag(_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Proxy::addSlice(const MTPmessages_Messages &slice) {
|
void Proxy::addSlice(const MTPmessages_Messages &slice, int alreadyLoaded) {
|
||||||
|
if (!alreadyLoaded && _data) {
|
||||||
|
resolveList().clear();
|
||||||
|
}
|
||||||
auto fullCount = slice.match([&](
|
auto fullCount = slice.match([&](
|
||||||
const MTPDmessages_messagesNotModified &) {
|
const MTPDmessages_messagesNotModified &) {
|
||||||
LOG(("API Error: received messages.messagesNotModified! "
|
LOG(("API Error: received messages.messagesNotModified! "
|
||||||
|
@ -148,15 +152,11 @@ void Proxy::addSlice(const MTPmessages_Messages &slice) {
|
||||||
owner.processChats(data.vchats());
|
owner.processChats(data.vchats());
|
||||||
return data.vmessages().v;
|
return data.vmessages().v;
|
||||||
});
|
});
|
||||||
if (messages.isEmpty()) {
|
if (!messages.isEmpty() && !_data) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_data) {
|
|
||||||
createData();
|
createData();
|
||||||
}
|
}
|
||||||
auto added = false;
|
auto added = false;
|
||||||
auto &list = resolveList();
|
const auto list = _data ? &resolveList() : nullptr;
|
||||||
const auto localFlags = MessageFlags();
|
const auto localFlags = MessageFlags();
|
||||||
const auto type = NewMessageType::Existing;
|
const auto type = NewMessageType::Existing;
|
||||||
for (const auto &message : messages) {
|
for (const auto &message : messages) {
|
||||||
|
@ -173,12 +173,12 @@ void Proxy::addSlice(const MTPmessages_Messages &slice) {
|
||||||
Unexpected("Type in Proxy::addSlice.");
|
Unexpected("Type in Proxy::addSlice.");
|
||||||
}();
|
}();
|
||||||
if (is) {
|
if (is) {
|
||||||
list.insert(item->id);
|
list->insert(item->id);
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!added) {
|
if (!added) {
|
||||||
fullCount = list.loadedCount();
|
fullCount = loadedCount();
|
||||||
}
|
}
|
||||||
setCount(fullCount);
|
setCount(fullCount);
|
||||||
_history->session().changes().historyUpdated(
|
_history->session().changes().historyUpdated(
|
||||||
|
@ -186,6 +186,28 @@ void Proxy::addSlice(const MTPmessages_Messages &slice) {
|
||||||
UpdateFlag(_type));
|
UpdateFlag(_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Proxy::checkAdd(MsgId msgId, bool resolved) {
|
||||||
|
Expects(_type == Type::Reactions);
|
||||||
|
|
||||||
|
if (!_data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto &list = resolveList();
|
||||||
|
if (!list.loadedCount() || list.maxLoaded() <= msgId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto history = _history;
|
||||||
|
const auto peer = history->peer;
|
||||||
|
const auto item = peer->owner().message(peer, msgId);
|
||||||
|
if (item && item->hasUnreadReaction()) {
|
||||||
|
item->addToUnreadThings(AddType::Existing);
|
||||||
|
} else if (!item && !resolved) {
|
||||||
|
peer->session().api().requestMessageData(peer, msgId, [=] {
|
||||||
|
history->unreadReactions().checkAdd(msgId, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Proxy::createData() {
|
void Proxy::createData() {
|
||||||
_data = std::make_unique<All>();
|
_data = std::make_unique<All>();
|
||||||
if (_known) {
|
if (_known) {
|
||||||
|
|
|
@ -38,6 +38,9 @@ public:
|
||||||
[[nodiscard]] bool has() const {
|
[[nodiscard]] bool has() const {
|
||||||
return (count() > 0);
|
return (count() > 0);
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] bool contains(MsgId msgId) const {
|
||||||
|
return _messages.contains(msgId);
|
||||||
|
}
|
||||||
void setCount(int count) {
|
void setCount(int count) {
|
||||||
_count = count;
|
_count = count;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +123,9 @@ public:
|
||||||
void erase(MsgId msgId);
|
void erase(MsgId msgId);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void addSlice(const MTPmessages_Messages &slice);
|
void addSlice(const MTPmessages_Messages &slice, int alreadyLoaded);
|
||||||
|
|
||||||
|
void checkAdd(MsgId msgId, bool resolved = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createData();
|
void createData();
|
||||||
|
|
Loading…
Add table
Reference in a new issue