mirror of https://github.com/procxx/kepka.git
Make stickers FeaturedReader an MTP::Sender.
This commit is contained in:
parent
8d4be19952
commit
5cb66c99bd
|
@ -34,7 +34,7 @@ namespace Stickers {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr int kReadFeaturedSetsTimeoutMs = 1000;
|
constexpr int kReadFeaturedSetsTimeoutMs = 1000;
|
||||||
internal::FeaturedReader *FeaturedReaderInstance = nullptr;
|
QPointer<internal::FeaturedReader> FeaturedReaderInstance;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ void undoInstallLocally(uint64 setId) {
|
||||||
void markFeaturedAsRead(uint64 setId) {
|
void markFeaturedAsRead(uint64 setId) {
|
||||||
if (!FeaturedReaderInstance) {
|
if (!FeaturedReaderInstance) {
|
||||||
if (auto main = App::main()) {
|
if (auto main = App::main()) {
|
||||||
FeaturedReaderInstance = new internal::FeaturedReader(main);
|
FeaturedReaderInstance = object_ptr<internal::FeaturedReader>(main);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -185,17 +185,9 @@ void markFeaturedAsRead(uint64 setId) {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
void readFeaturedDone() {
|
|
||||||
Local::writeFeaturedStickers();
|
|
||||||
if (App::main()) {
|
|
||||||
emit App::main()->stickersUpdated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FeaturedReader::FeaturedReader(QObject *parent) : QObject(parent)
|
FeaturedReader::FeaturedReader(QObject *parent) : QObject(parent)
|
||||||
, _timer(new QTimer(this)) {
|
, _timer(this) {
|
||||||
_timer->setSingleShot(true);
|
_timer->setTimeoutHandler([this] { readSets(); });
|
||||||
connect(_timer, SIGNAL(timeout()), this, SLOT(onReadSets()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeaturedReader::scheduleRead(uint64 setId) {
|
void FeaturedReader::scheduleRead(uint64 setId) {
|
||||||
|
@ -205,7 +197,7 @@ void FeaturedReader::scheduleRead(uint64 setId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeaturedReader::onReadSets() {
|
void FeaturedReader::readSets() {
|
||||||
auto &sets = Global::RefStickerSets();
|
auto &sets = Global::RefStickerSets();
|
||||||
auto count = Global::FeaturedStickerSetsUnreadCount();
|
auto count = Global::FeaturedStickerSetsUnreadCount();
|
||||||
QVector<MTPlong> wrappedIds;
|
QVector<MTPlong> wrappedIds;
|
||||||
|
@ -223,7 +215,13 @@ void FeaturedReader::onReadSets() {
|
||||||
_setIds.clear();
|
_setIds.clear();
|
||||||
|
|
||||||
if (!wrappedIds.empty()) {
|
if (!wrappedIds.empty()) {
|
||||||
MTP::send(MTPmessages_ReadFeaturedStickers(MTP_vector<MTPlong>(wrappedIds)), rpcDone(&readFeaturedDone));
|
request(MTPmessages_ReadFeaturedStickers(MTP_vector<MTPlong>(wrappedIds))).done([](const MTPBool &result) {
|
||||||
|
Local::writeFeaturedStickers();
|
||||||
|
if (auto main = App::main()) {
|
||||||
|
emit main->stickersUpdated();
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
|
||||||
if (Global::FeaturedStickerSetsUnreadCount() != count) {
|
if (Global::FeaturedStickerSetsUnreadCount() != count) {
|
||||||
Global::SetFeaturedStickerSetsUnreadCount(count);
|
Global::SetFeaturedStickerSetsUnreadCount(count);
|
||||||
Global::RefFeaturedStickerSetsUnreadCountChanged().notify();
|
Global::RefFeaturedStickerSetsUnreadCountChanged().notify();
|
||||||
|
|
|
@ -20,6 +20,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "mtproto/sender.h"
|
||||||
|
|
||||||
namespace Stickers {
|
namespace Stickers {
|
||||||
|
|
||||||
void applyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d);
|
void applyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d);
|
||||||
|
@ -30,18 +32,15 @@ void markFeaturedAsRead(uint64 setId);
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
class FeaturedReader : public QObject {
|
class FeaturedReader : public QObject, private MTP::Sender {
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FeaturedReader(QObject *parent);
|
FeaturedReader(QObject *parent);
|
||||||
void scheduleRead(uint64 setId);
|
void scheduleRead(uint64 setId);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onReadSets();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *_timer;
|
void readSets();
|
||||||
|
|
||||||
|
object_ptr<SingleTimer> _timer;
|
||||||
OrderedSet<uint64> _setIds;
|
OrderedSet<uint64> _setIds;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue