mirror of https://github.com/procxx/kepka.git
Reload poll data each 30 seconds without update.
This commit is contained in:
parent
b6a3bb4080
commit
6f176803d4
|
@ -5437,6 +5437,24 @@ void ApiWrap::closePoll(FullMsgId itemId) {
|
||||||
_pollCloseRequestIds.emplace(itemId, requestId);
|
_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) {
|
void ApiWrap::readServerHistory(not_null<History*> history) {
|
||||||
if (history->unreadCount()) {
|
if (history->unreadCount()) {
|
||||||
readServerHistoryForce(history);
|
readServerHistoryForce(history);
|
||||||
|
|
|
@ -386,6 +386,7 @@ public:
|
||||||
FullMsgId itemId,
|
FullMsgId itemId,
|
||||||
const std::vector<QByteArray> &options);
|
const std::vector<QByteArray> &options);
|
||||||
void closePoll(FullMsgId itemId);
|
void closePoll(FullMsgId itemId);
|
||||||
|
void reloadPollResults(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
~ApiWrap();
|
~ApiWrap();
|
||||||
|
|
||||||
|
@ -751,5 +752,6 @@ private:
|
||||||
|
|
||||||
base::flat_map<FullMsgId, mtpRequestId> _pollVotesRequestIds;
|
base::flat_map<FullMsgId, mtpRequestId> _pollVotesRequestIds;
|
||||||
base::flat_map<FullMsgId, mtpRequestId> _pollCloseRequestIds;
|
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 "data/data_poll.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
|
#include "auth_session.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kShortPollTimeout = 30 * TimeMs(1000);
|
||||||
|
|
||||||
const PollAnswer *AnswerByOption(
|
const PollAnswer *AnswerByOption(
|
||||||
const std::vector<PollAnswer> &list,
|
const std::vector<PollAnswer> &list,
|
||||||
const QByteArray &option) {
|
const QByteArray &option) {
|
||||||
|
@ -85,10 +90,21 @@ bool PollData::applyResults(const MTPPollResults &results) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalVoters = newTotalVoters;
|
totalVoters = newTotalVoters;
|
||||||
|
lastResultsUpdate = getms();
|
||||||
return changed;
|
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) {
|
PollAnswer *PollData::answerByOption(const QByteArray &option) {
|
||||||
return AnswerByOption(answers, option);
|
return AnswerByOption(answers, option);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct PollData {
|
||||||
|
|
||||||
bool applyChanges(const MTPDpoll &poll);
|
bool applyChanges(const MTPDpoll &poll);
|
||||||
bool applyResults(const MTPPollResults &results);
|
bool applyResults(const MTPPollResults &results);
|
||||||
|
void checkResultsReload(not_null<HistoryItem*> item, TimeMs now);
|
||||||
|
|
||||||
PollAnswer *answerByOption(const QByteArray &option);
|
PollAnswer *answerByOption(const QByteArray &option);
|
||||||
const PollAnswer *answerByOption(const QByteArray &option) const;
|
const PollAnswer *answerByOption(const QByteArray &option) const;
|
||||||
|
@ -40,6 +41,7 @@ struct PollData {
|
||||||
int totalVoters = 0;
|
int totalVoters = 0;
|
||||||
bool closed = false;
|
bool closed = false;
|
||||||
QByteArray sendingVote;
|
QByteArray sendingVote;
|
||||||
|
TimeMs lastResultsUpdate = 0;
|
||||||
|
|
||||||
int version = 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();
|
auto paintx = 0, painty = 0, paintw = width(), painth = height();
|
||||||
|
|
||||||
updateVotesCheckAnimations();
|
updateVotesCheckAnimations();
|
||||||
|
_poll->checkResultsReload(_parent->data(), ms);
|
||||||
|
|
||||||
const auto outbg = _parent->hasOutLayout();
|
const auto outbg = _parent->hasOutLayout();
|
||||||
const auto selected = (selection == FullSelection);
|
const auto selected = (selection == FullSelection);
|
||||||
|
|
|
@ -111,6 +111,7 @@ private:
|
||||||
void resetAnswersAnimation() const;
|
void resetAnswersAnimation() const;
|
||||||
void step_radial(TimeMs ms, bool timer);
|
void step_radial(TimeMs ms, bool timer);
|
||||||
|
|
||||||
|
void checkPollResultsReload(TimeMs ms) const;
|
||||||
void toggleRipple(Answer &answer, bool pressed);
|
void toggleRipple(Answer &answer, bool pressed);
|
||||||
|
|
||||||
not_null<PollData*> _poll;
|
not_null<PollData*> _poll;
|
||||||
|
|
Loading…
Reference in New Issue