Removed display of stale sponsored messages.
This commit is contained in:
parent
5565da5308
commit
55eb381bd2
|
@ -19,7 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Data {
|
namespace Data {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr auto kRequestTimeLimit = 5 * 60 * crl::time(1000);
|
constexpr auto kRequestTimeLimit = 10 * 60 * crl::time(1000);
|
||||||
|
|
||||||
[[nodiscard]] bool TooEarlyForRequest(crl::time received) {
|
[[nodiscard]] bool TooEarlyForRequest(crl::time received) {
|
||||||
return (received > 0) && (received + kRequestTimeLimit > crl::now());
|
return (received > 0) && (received + kRequestTimeLimit > crl::now());
|
||||||
|
@ -59,7 +59,7 @@ bool SponsoredMessages::append(not_null<History*> history) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto &list = it->second;
|
auto &list = it->second;
|
||||||
if (list.showedAll) {
|
if (list.showedAll || !TooEarlyForRequest(list.received)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +104,19 @@ void SponsoredMessages::request(not_null<History*> history) {
|
||||||
if (request.requestId || TooEarlyForRequest(request.lastReceived)) {
|
if (request.requestId || TooEarlyForRequest(request.lastReceived)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const auto it = _data.find(history);
|
||||||
|
if (it != end(_data)) {
|
||||||
|
auto &list = it->second;
|
||||||
|
// Don't rebuild currently displayed messages.
|
||||||
|
const auto proj = [](const Entry &e) {
|
||||||
|
return e.item != nullptr;
|
||||||
|
};
|
||||||
|
if (ranges::any_of(list.entries, proj)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const auto channel = history->peer->asChannel();
|
const auto channel = history->peer->asChannel();
|
||||||
Assert(channel != nullptr);
|
Assert(channel != nullptr);
|
||||||
request.requestId = _session->api().request(
|
request.requestId = _session->api().request(
|
||||||
|
@ -131,11 +144,9 @@ void SponsoredMessages::parse(
|
||||||
_session->data().processChats(data.vchats());
|
_session->data().processChats(data.vchats());
|
||||||
|
|
||||||
const auto &messages = data.vmessages().v;
|
const auto &messages = data.vmessages().v;
|
||||||
if (messages.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto &list = _data.emplace(history, List()).first->second;
|
auto &list = _data.emplace(history, List()).first->second;
|
||||||
list.entries.clear();
|
list.entries.clear();
|
||||||
|
list.received = crl::now();
|
||||||
for (const auto &message : messages) {
|
for (const auto &message : messages) {
|
||||||
append(history, list, message);
|
append(history, list, message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ private:
|
||||||
struct List {
|
struct List {
|
||||||
std::vector<Entry> entries;
|
std::vector<Entry> entries;
|
||||||
bool showedAll = false;
|
bool showedAll = false;
|
||||||
|
crl::time received = 0;
|
||||||
};
|
};
|
||||||
struct Request {
|
struct Request {
|
||||||
mtpRequestId requestId = 0;
|
mtpRequestId requestId = 0;
|
||||||
|
|
|
@ -3010,6 +3010,7 @@ void HistoryWidget::loadMessagesDown() {
|
||||||
auto loadMigrated = _migrated && !(_migrated->isEmpty() || _migrated->loadedAtBottom() || (!_history->isEmpty() && !_history->loadedAtTop()));
|
auto loadMigrated = _migrated && !(_migrated->isEmpty() || _migrated->loadedAtBottom() || (!_history->isEmpty() && !_history->loadedAtTop()));
|
||||||
auto from = loadMigrated ? _migrated : _history;
|
auto from = loadMigrated ? _migrated : _history;
|
||||||
if (from->loadedAtBottom()) {
|
if (from->loadedAtBottom()) {
|
||||||
|
session().data().sponsoredMessages().request(_history);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue