init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
119
Telegram/SourceFiles/data/data_forum_icons.cpp
Normal file
119
Telegram/SourceFiles/data/data_forum_icons.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "data/data_forum_icons.h"
|
||||
|
||||
#include "main/main_session.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_forum.h"
|
||||
#include "data/data_forum_topic.h"
|
||||
#include "apiwrap.h"
|
||||
|
||||
namespace Data {
|
||||
|
||||
ForumIcons::ForumIcons(not_null<Session*> owner)
|
||||
: _owner(owner)
|
||||
, _resetUserpicsTimer([=] { resetUserpics(); }) {
|
||||
}
|
||||
|
||||
ForumIcons::~ForumIcons() = default;
|
||||
|
||||
Main::Session &ForumIcons::session() const {
|
||||
return _owner->session();
|
||||
}
|
||||
|
||||
void ForumIcons::requestDefaultIfUnknown() {
|
||||
if (_default.empty()) {
|
||||
requestDefault();
|
||||
}
|
||||
}
|
||||
|
||||
void ForumIcons::refreshDefault() {
|
||||
requestDefault();
|
||||
}
|
||||
|
||||
const std::vector<DocumentId> &ForumIcons::list() const {
|
||||
return _default;
|
||||
}
|
||||
|
||||
rpl::producer<> ForumIcons::defaultUpdates() const {
|
||||
return _defaultUpdated.events();
|
||||
}
|
||||
|
||||
void ForumIcons::requestDefault() {
|
||||
if (_defaultRequestId) {
|
||||
return;
|
||||
}
|
||||
auto &api = _owner->session().api();
|
||||
_defaultRequestId = api.request(MTPmessages_GetStickerSet(
|
||||
MTP_inputStickerSetEmojiDefaultTopicIcons(),
|
||||
MTP_int(0) // hash
|
||||
)).done([=](const MTPmessages_StickerSet &result) {
|
||||
_defaultRequestId = 0;
|
||||
result.match([&](const MTPDmessages_stickerSet &data) {
|
||||
updateDefault(data);
|
||||
}, [](const MTPDmessages_stickerSetNotModified &) {
|
||||
LOG(("API Error: Unexpected messages.stickerSetNotModified."));
|
||||
});
|
||||
}).fail([=] {
|
||||
_defaultRequestId = 0;
|
||||
}).send();
|
||||
}
|
||||
|
||||
void ForumIcons::updateDefault(const MTPDmessages_stickerSet &data) {
|
||||
const auto &list = data.vdocuments().v;
|
||||
_default.clear();
|
||||
_default.reserve(list.size());
|
||||
for (const auto &sticker : list) {
|
||||
_default.push_back(_owner->processDocument(sticker)->id);
|
||||
}
|
||||
_defaultUpdated.fire({});
|
||||
}
|
||||
|
||||
void ForumIcons::scheduleUserpicsReset(not_null<Forum*> forum) {
|
||||
const auto duration = crl::time(st::slideDuration);
|
||||
_resetUserpicsWhen[forum] = crl::now() + duration;
|
||||
if (!_resetUserpicsTimer.isActive()) {
|
||||
_resetUserpicsTimer.callOnce(duration);
|
||||
}
|
||||
}
|
||||
|
||||
void ForumIcons::clearUserpicsReset(not_null<Forum*> forum) {
|
||||
_resetUserpicsWhen.remove(forum);
|
||||
}
|
||||
|
||||
void ForumIcons::resetUserpics() {
|
||||
auto nearest = crl::time();
|
||||
auto now = crl::now();
|
||||
for (auto i = begin(_resetUserpicsWhen); i != end(_resetUserpicsWhen);) {
|
||||
if (i->second > now) {
|
||||
if (!nearest || nearest > i->second) {
|
||||
nearest = i->second;
|
||||
}
|
||||
++i;
|
||||
} else {
|
||||
const auto forum = i->first;
|
||||
i = _resetUserpicsWhen.erase(i);
|
||||
resetUserpicsFor(forum);
|
||||
}
|
||||
}
|
||||
if (nearest) {
|
||||
_resetUserpicsTimer.callOnce(
|
||||
std::min(nearest - now, 86400 * crl::time(1000)));
|
||||
} else {
|
||||
_resetUserpicsTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void ForumIcons::resetUserpicsFor(not_null<Forum*> forum) {
|
||||
forum->enumerateTopics([](not_null<ForumTopic*> topic) {
|
||||
topic->clearUserpicLoops();
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Data
|
||||
Reference in New Issue
Block a user