mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 09:41:41 -05:00
Reload poll data each 30 seconds without update.
This commit is contained in:
parent
b6a3bb4080
commit
6f176803d4
6 changed files with 40 additions and 0 deletions
|
@ -5437,6 +5437,24 @@ void ApiWrap::closePoll(FullMsgId itemId) {
|
|||
_pollCloseRequestIds.emplace(itemId, requestId);
|
||||
}
|
||||
|
||||
void ApiWrap::reloadPollResults(not_null<HistoryItem*> item) {
|
||||
const auto itemId = item->fullId();
|
||||
if (!IsServerMsgId(item->id)
|
||||
|| _pollReloadRequestIds.contains(itemId)) {
|
||||
return;
|
||||
}
|
||||
const auto requestId = request(MTPmessages_GetPollResults(
|
||||
item->history()->peer->input,
|
||||
MTP_int(item->id)
|
||||
)).done([=](const MTPUpdates &result) {
|
||||
_pollReloadRequestIds.erase(itemId);
|
||||
applyUpdates(result);
|
||||
}).fail([=](const RPCError &error) {
|
||||
_pollReloadRequestIds.erase(itemId);
|
||||
}).send();
|
||||
_pollReloadRequestIds.emplace(itemId, requestId);
|
||||
}
|
||||
|
||||
void ApiWrap::readServerHistory(not_null<History*> history) {
|
||||
if (history->unreadCount()) {
|
||||
readServerHistoryForce(history);
|
||||
|
|
|
@ -386,6 +386,7 @@ public:
|
|||
FullMsgId itemId,
|
||||
const std::vector<QByteArray> &options);
|
||||
void closePoll(FullMsgId itemId);
|
||||
void reloadPollResults(not_null<HistoryItem*> item);
|
||||
|
||||
~ApiWrap();
|
||||
|
||||
|
@ -751,5 +752,6 @@ private:
|
|||
|
||||
base::flat_map<FullMsgId, mtpRequestId> _pollVotesRequestIds;
|
||||
base::flat_map<FullMsgId, mtpRequestId> _pollCloseRequestIds;
|
||||
base::flat_map<FullMsgId, mtpRequestId> _pollReloadRequestIds;
|
||||
|
||||
};
|
||||
|
|
|
@ -7,8 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "data/data_poll.h"
|
||||
|
||||
#include "apiwrap.h"
|
||||
#include "auth_session.h"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr auto kShortPollTimeout = 30 * TimeMs(1000);
|
||||
|
||||
const PollAnswer *AnswerByOption(
|
||||
const std::vector<PollAnswer> &list,
|
||||
const QByteArray &option) {
|
||||
|
@ -85,10 +90,21 @@ bool PollData::applyResults(const MTPPollResults &results) {
|
|||
}
|
||||
}
|
||||
totalVoters = newTotalVoters;
|
||||
lastResultsUpdate = getms();
|
||||
return changed;
|
||||
});
|
||||
}
|
||||
|
||||
void PollData::checkResultsReload(not_null<HistoryItem*> item, TimeMs now) {
|
||||
if (lastResultsUpdate && lastResultsUpdate + kShortPollTimeout > now) {
|
||||
return;
|
||||
} else if (closed) {
|
||||
return;
|
||||
}
|
||||
lastResultsUpdate = now;
|
||||
Auth().api().reloadPollResults(item);
|
||||
}
|
||||
|
||||
PollAnswer *PollData::answerByOption(const QByteArray &option) {
|
||||
return AnswerByOption(answers, option);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ struct PollData {
|
|||
|
||||
bool applyChanges(const MTPDpoll &poll);
|
||||
bool applyResults(const MTPPollResults &results);
|
||||
void checkResultsReload(not_null<HistoryItem*> item, TimeMs now);
|
||||
|
||||
PollAnswer *answerByOption(const QByteArray &option);
|
||||
const PollAnswer *answerByOption(const QByteArray &option) const;
|
||||
|
@ -40,6 +41,7 @@ struct PollData {
|
|||
int totalVoters = 0;
|
||||
bool closed = false;
|
||||
QByteArray sendingVote;
|
||||
TimeMs lastResultsUpdate = 0;
|
||||
|
||||
int version = 0;
|
||||
|
||||
|
|
|
@ -401,6 +401,7 @@ void HistoryPoll::draw(Painter &p, const QRect &r, TextSelection selection, Time
|
|||
auto paintx = 0, painty = 0, paintw = width(), painth = height();
|
||||
|
||||
updateVotesCheckAnimations();
|
||||
_poll->checkResultsReload(_parent->data(), ms);
|
||||
|
||||
const auto outbg = _parent->hasOutLayout();
|
||||
const auto selected = (selection == FullSelection);
|
||||
|
|
|
@ -111,6 +111,7 @@ private:
|
|||
void resetAnswersAnimation() const;
|
||||
void step_radial(TimeMs ms, bool timer);
|
||||
|
||||
void checkPollResultsReload(TimeMs ms) const;
|
||||
void toggleRipple(Answer &answer, bool pressed);
|
||||
|
||||
not_null<PollData*> _poll;
|
||||
|
|
Loading…
Add table
Reference in a new issue