mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-29 00:39:55 +00:00
Added support of unread poll votes to corner button from history widget.
This commit is contained in:
@@ -42,6 +42,13 @@ bool UnreadThings::trackReactions(Data::Thread *thread) const {
|
||||
return peer && (peer->isUser() || peer->isChat() || peer->isMegagroup());
|
||||
}
|
||||
|
||||
bool UnreadThings::trackPollVotes(Data::Thread *thread) const {
|
||||
const auto peer = thread ? thread->peer().get() : nullptr;
|
||||
return peer
|
||||
&& (peer->isChat() || peer->isMegagroup())
|
||||
&& !peer->isMonoforum();
|
||||
}
|
||||
|
||||
void UnreadThings::preloadEnough(Data::Thread *thread) {
|
||||
if (trackMentions(thread)) {
|
||||
preloadEnoughMentions(thread);
|
||||
@@ -49,6 +56,9 @@ void UnreadThings::preloadEnough(Data::Thread *thread) {
|
||||
if (trackReactions(thread)) {
|
||||
preloadEnoughReactions(thread);
|
||||
}
|
||||
if (trackPollVotes(thread)) {
|
||||
preloadEnoughPollVotes(thread);
|
||||
}
|
||||
}
|
||||
|
||||
void UnreadThings::mediaAndMentionsRead(
|
||||
@@ -84,6 +94,15 @@ void UnreadThings::preloadEnoughReactions(not_null<Data::Thread*> thread) {
|
||||
}
|
||||
}
|
||||
|
||||
void UnreadThings::preloadEnoughPollVotes(not_null<Data::Thread*> thread) {
|
||||
const auto fullCount = thread->unreadPollVotes().count();
|
||||
const auto loadedCount = thread->unreadPollVotes().loadedCount();
|
||||
const auto allLoaded = (fullCount >= 0) && (loadedCount >= fullCount);
|
||||
if (fullCount >= 0 && loadedCount < kPreloadIfLess && !allLoaded) {
|
||||
requestPollVotes(thread, loadedCount);
|
||||
}
|
||||
}
|
||||
|
||||
void UnreadThings::cancelRequests(not_null<Data::Thread*> thread) {
|
||||
if (const auto requestId = _mentionsRequests.take(thread)) {
|
||||
_api->request(*requestId).cancel();
|
||||
@@ -91,6 +110,9 @@ void UnreadThings::cancelRequests(not_null<Data::Thread*> thread) {
|
||||
if (const auto requestId = _reactionsRequests.take(thread)) {
|
||||
_api->request(*requestId).cancel();
|
||||
}
|
||||
if (const auto requestId = _pollVotesRequests.take(thread)) {
|
||||
_api->request(*requestId).cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void UnreadThings::requestMentions(
|
||||
@@ -164,4 +186,38 @@ void UnreadThings::requestReactions(
|
||||
_reactionsRequests.emplace(thread, requestId);
|
||||
}
|
||||
|
||||
void UnreadThings::requestPollVotes(
|
||||
not_null<Data::Thread*> thread,
|
||||
int loaded) {
|
||||
if (_pollVotesRequests.contains(thread) || thread->asSublist()) {
|
||||
return;
|
||||
}
|
||||
const auto offsetId = loaded
|
||||
? std::max(thread->unreadPollVotes().maxLoaded(), MsgId(1))
|
||||
: MsgId(1);
|
||||
const auto limit = loaded ? kNextRequestLimit : kFirstRequestLimit;
|
||||
const auto addOffset = loaded ? -(limit + 1) : -limit;
|
||||
const auto maxId = 0;
|
||||
const auto minId = 0;
|
||||
const auto history = thread->owningHistory();
|
||||
const auto topic = thread->asTopic();
|
||||
using Flag = MTPmessages_GetUnreadPollVotes::Flag;
|
||||
const auto requestId = _api->request(MTPmessages_GetUnreadPollVotes(
|
||||
MTP_flags(topic ? Flag::f_top_msg_id : Flag()),
|
||||
history->peer->input(),
|
||||
MTP_int(topic ? topic->rootId() : 0),
|
||||
MTP_int(offsetId),
|
||||
MTP_int(addOffset),
|
||||
MTP_int(limit),
|
||||
MTP_int(maxId),
|
||||
MTP_int(minId)
|
||||
)).done([=](const MTPmessages_Messages &result) {
|
||||
_pollVotesRequests.remove(thread);
|
||||
thread->unreadPollVotes().addSlice(result, loaded);
|
||||
}).fail([=] {
|
||||
_pollVotesRequests.remove(thread);
|
||||
}).send();
|
||||
_pollVotesRequests.emplace(thread, requestId);
|
||||
}
|
||||
|
||||
} // namespace UnreadThings
|
||||
|
||||
Reference in New Issue
Block a user