mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Move stickers state variables to AuthSessionData.
Also allow to click on the selected set when choosing megagroup sticker set and allow to paste a t.me link to the set there.
This commit is contained in:
@@ -651,14 +651,14 @@ void EmojiListWidget::refreshRecent() {
|
||||
updateSize();
|
||||
}
|
||||
|
||||
bool EmojiListWidget::event(QEvent *e) {
|
||||
bool EmojiListWidget::eventHook(QEvent *e) {
|
||||
if (e->type() == QEvent::ParentChange) {
|
||||
if (_picker->parentWidget() != parentWidget()) {
|
||||
_picker->setParent(parentWidget());
|
||||
}
|
||||
_picker->raise();
|
||||
}
|
||||
return Inner::event(e);
|
||||
return Inner::eventHook(e);
|
||||
}
|
||||
|
||||
void EmojiListWidget::updateSelected() {
|
||||
|
@@ -122,7 +122,7 @@ protected:
|
||||
void leaveEventHook(QEvent *e) override;
|
||||
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
||||
void enterFromChildEvent(QEvent *e, QWidget *child) override;
|
||||
bool event(QEvent *e) override;
|
||||
bool eventHook(QEvent *e) override;
|
||||
|
||||
TabbedSelector::InnerFooter *getFooter() const override;
|
||||
void processHideFinished() override;
|
||||
|
@@ -113,7 +113,7 @@ void FieldAutocomplete::showStickers(EmojiPtr emoji) {
|
||||
_emoji = emoji;
|
||||
_type = Type::Stickers;
|
||||
if (!emoji) {
|
||||
rowsUpdated(_mrows, _hrows, _brows, StickerPack(), false);
|
||||
rowsUpdated(_mrows, _hrows, _brows, Stickers::Pack(), false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
internal::MentionRows mrows;
|
||||
internal::HashtagRows hrows;
|
||||
internal::BotCommandRows brows;
|
||||
StickerPack srows;
|
||||
Stickers::Pack srows;
|
||||
if (_emoji) {
|
||||
srows = Stickers::GetListByEmoji(_emoji);
|
||||
} else if (_type == Type::Mentions) {
|
||||
@@ -330,7 +330,7 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
||||
_inner->setRecentInlineBotsInRows(recentInlineBots);
|
||||
}
|
||||
|
||||
void FieldAutocomplete::rowsUpdated(const internal::MentionRows &mrows, const internal::HashtagRows &hrows, const internal::BotCommandRows &brows, const StickerPack &srows, bool resetScroll) {
|
||||
void FieldAutocomplete::rowsUpdated(const internal::MentionRows &mrows, const internal::HashtagRows &hrows, const internal::BotCommandRows &brows, const Stickers::Pack &srows, bool resetScroll) {
|
||||
if (mrows.isEmpty() && hrows.isEmpty() && brows.isEmpty() && srows.isEmpty()) {
|
||||
if (!isHidden()) {
|
||||
hideAnimated();
|
||||
@@ -508,7 +508,7 @@ FieldAutocomplete::~FieldAutocomplete() {
|
||||
|
||||
namespace internal {
|
||||
|
||||
FieldAutocompleteInner::FieldAutocompleteInner(FieldAutocomplete *parent, MentionRows *mrows, HashtagRows *hrows, BotCommandRows *brows, StickerPack *srows)
|
||||
FieldAutocompleteInner::FieldAutocompleteInner(FieldAutocomplete *parent, MentionRows *mrows, HashtagRows *hrows, BotCommandRows *brows, Stickers::Pack *srows)
|
||||
: _parent(parent)
|
||||
, _mrows(mrows)
|
||||
, _hrows(hrows)
|
||||
|
@@ -21,6 +21,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#pragma once
|
||||
|
||||
#include "ui/twidget.h"
|
||||
#include "chat_helpers/stickers.h"
|
||||
|
||||
namespace Ui {
|
||||
class ScrollArea;
|
||||
@@ -104,9 +105,9 @@ private:
|
||||
internal::MentionRows _mrows;
|
||||
internal::HashtagRows _hrows;
|
||||
internal::BotCommandRows _brows;
|
||||
StickerPack _srows;
|
||||
Stickers::Pack _srows;
|
||||
|
||||
void rowsUpdated(const internal::MentionRows &mrows, const internal::HashtagRows &hrows, const internal::BotCommandRows &brows, const StickerPack &srows, bool resetScroll);
|
||||
void rowsUpdated(const internal::MentionRows &mrows, const internal::HashtagRows &hrows, const internal::BotCommandRows &brows, const Stickers::Pack &srows, bool resetScroll);
|
||||
|
||||
object_ptr<Ui::ScrollArea> _scroll;
|
||||
QPointer<internal::FieldAutocompleteInner> _inner;
|
||||
@@ -141,7 +142,7 @@ class FieldAutocompleteInner final : public TWidget, private base::Subscriber {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FieldAutocompleteInner(FieldAutocomplete *parent, MentionRows *mrows, HashtagRows *hrows, BotCommandRows *brows, StickerPack *srows);
|
||||
FieldAutocompleteInner(FieldAutocomplete *parent, MentionRows *mrows, HashtagRows *hrows, BotCommandRows *brows, Stickers::Pack *srows);
|
||||
|
||||
void clearSel(bool hidden = false);
|
||||
bool moveSel(int key);
|
||||
@@ -179,7 +180,7 @@ private:
|
||||
MentionRows *_mrows;
|
||||
HashtagRows *_hrows;
|
||||
BotCommandRows *_brows;
|
||||
StickerPack *_srows;
|
||||
Stickers::Pack *_srows;
|
||||
int32 _stickersPerRow, _recentInlineBotsInRows;
|
||||
int32 _sel, _down;
|
||||
bool _mouseSel;
|
||||
|
@@ -122,7 +122,10 @@ void GifsListWidget::Footer::processPanelHideFinished() {
|
||||
//_field->setText(QString());
|
||||
}
|
||||
|
||||
GifsListWidget::GifsListWidget(QWidget *parent, not_null<Window::Controller*> controller) : Inner(parent, controller)
|
||||
GifsListWidget::GifsListWidget(
|
||||
QWidget *parent,
|
||||
not_null<Window::Controller*> controller)
|
||||
: Inner(parent, controller)
|
||||
, _section(Section::Gifs) {
|
||||
updateSize();
|
||||
|
||||
@@ -138,9 +141,10 @@ GifsListWidget::GifsListWidget(QWidget *parent, not_null<Window::Controller*> co
|
||||
_inlineRequestTimer.setSingleShot(true);
|
||||
connect(&_inlineRequestTimer, &QTimer::timeout, this, [this] { sendInlineRequest(); });
|
||||
|
||||
subscribe(Auth().data().savedGifsUpdated(), [this] {
|
||||
refreshSavedGifs();
|
||||
});
|
||||
Auth().data().savedGifsUpdated()
|
||||
| rpl::start_with_next([this] {
|
||||
refreshSavedGifs();
|
||||
}, lifetime());
|
||||
subscribe(Auth().downloaderTaskFinished(), [this] {
|
||||
update();
|
||||
});
|
||||
@@ -459,7 +463,7 @@ void GifsListWidget::refreshSavedGifs() {
|
||||
if (_section == Section::Gifs) {
|
||||
clearInlineRows(false);
|
||||
|
||||
auto &saved = cSavedGifs();
|
||||
auto &saved = Auth().data().savedGifs();
|
||||
if (!saved.isEmpty()) {
|
||||
_rows.reserve(saved.size());
|
||||
auto row = Row();
|
||||
|
@@ -40,7 +40,11 @@ class Controller;
|
||||
|
||||
namespace ChatHelpers {
|
||||
|
||||
class GifsListWidget : public TabbedSelector::Inner, public InlineBots::Layout::Context, private base::Subscriber, private MTP::Sender {
|
||||
class GifsListWidget
|
||||
: public TabbedSelector::Inner
|
||||
, public InlineBots::Layout::Context
|
||||
, private base::Subscriber
|
||||
, private MTP::Sender {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@@ -32,16 +32,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "styles/style_chat_helpers.h"
|
||||
|
||||
namespace Stickers {
|
||||
namespace {
|
||||
|
||||
constexpr int kReadFeaturedSetsTimeoutMs = 1000;
|
||||
QPointer<internal::FeaturedReader> FeaturedReaderInstance;
|
||||
|
||||
} // namespace
|
||||
|
||||
void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
|
||||
auto &v = d.vsets.v;
|
||||
auto &order = Global::RefStickerSetsOrder();
|
||||
auto &order = Auth().data().stickerSetsOrderRef();
|
||||
Order archived;
|
||||
archived.reserve(v.size());
|
||||
QMap<uint64, uint64> setsToRequest;
|
||||
@@ -89,13 +83,13 @@ void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
|
||||
Ui::Toast::Show(toast);
|
||||
// Ui::show(Box<StickersBox>(archived), LayerOption::KeepOther);
|
||||
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
}
|
||||
|
||||
// For testing: Just apply random subset or your sticker sets as archived.
|
||||
bool ApplyArchivedResultFake() {
|
||||
auto sets = QVector<MTPStickerSetCovered>();
|
||||
for (auto &set : Global::RefStickerSets()) {
|
||||
for (auto &set : Auth().data().stickerSetsRef()) {
|
||||
if ((set.flags & MTPDstickerSet::Flag::f_installed) && !(set.flags & MTPDstickerSet_ClientFlag::f_special)) {
|
||||
if (rand_value<uint32>() % 128 < 64) {
|
||||
auto data = MTP_stickerSet(MTP_flags(set.flags | MTPDstickerSet::Flag::f_archived), MTP_long(set.id), MTP_long(set.access), MTP_string(set.title), MTP_string(set.shortName), MTP_int(set.count), MTP_int(set.hash));
|
||||
@@ -110,7 +104,7 @@ bool ApplyArchivedResultFake() {
|
||||
}
|
||||
|
||||
void InstallLocally(uint64 setId) {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(setId);
|
||||
if (it == sets.end()) {
|
||||
return;
|
||||
@@ -121,7 +115,7 @@ void InstallLocally(uint64 setId) {
|
||||
it->flags |= MTPDstickerSet::Flag::f_installed;
|
||||
auto changedFlags = flags ^ it->flags;
|
||||
|
||||
auto &order = Global::RefStickerSetsOrder();
|
||||
auto &order = Auth().data().stickerSetsOrderRef();
|
||||
int insertAtIndex = 0, currentIndex = order.indexOf(setId);
|
||||
if (currentIndex != insertAtIndex) {
|
||||
if (currentIndex > 0) {
|
||||
@@ -143,17 +137,17 @@ void InstallLocally(uint64 setId) {
|
||||
Local::writeInstalledStickers();
|
||||
if (changedFlags & MTPDstickerSet_ClientFlag::f_unread) Local::writeFeaturedStickers();
|
||||
if (changedFlags & MTPDstickerSet::Flag::f_archived) {
|
||||
auto index = Global::RefArchivedStickerSetsOrder().indexOf(setId);
|
||||
auto index = Auth().data().archivedStickerSetsOrderRef().indexOf(setId);
|
||||
if (index >= 0) {
|
||||
Global::RefArchivedStickerSetsOrder().removeAt(index);
|
||||
Auth().data().archivedStickerSetsOrderRef().removeAt(index);
|
||||
Local::writeArchivedStickers();
|
||||
}
|
||||
}
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
}
|
||||
|
||||
void UndoInstallLocally(uint64 setId) {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(setId);
|
||||
if (it == sets.end()) {
|
||||
return;
|
||||
@@ -161,34 +155,23 @@ void UndoInstallLocally(uint64 setId) {
|
||||
|
||||
it->flags &= ~MTPDstickerSet::Flag::f_installed;
|
||||
|
||||
auto &order = Global::RefStickerSetsOrder();
|
||||
auto &order = Auth().data().stickerSetsOrderRef();
|
||||
int currentIndex = order.indexOf(setId);
|
||||
if (currentIndex >= 0) {
|
||||
order.removeAt(currentIndex);
|
||||
}
|
||||
|
||||
Local::writeInstalledStickers();
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
|
||||
Ui::show(
|
||||
Box<InformBox>(lang(lng_stickers_not_found)),
|
||||
LayerOption::KeepOther);
|
||||
}
|
||||
|
||||
void MarkFeaturedAsRead(uint64 setId) {
|
||||
if (!FeaturedReaderInstance) {
|
||||
if (auto main = App::main()) {
|
||||
FeaturedReaderInstance = object_ptr<internal::FeaturedReader>(main);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
FeaturedReaderInstance->scheduleRead(setId);
|
||||
}
|
||||
|
||||
bool IsFaved(not_null<DocumentData*> document) {
|
||||
auto it = Global::StickerSets().constFind(FavedSetId);
|
||||
return (it != Global::StickerSets().cend()) && it->stickers.contains(document);
|
||||
auto it = Auth().data().stickerSets().constFind(FavedSetId);
|
||||
return (it != Auth().data().stickerSets().cend()) && it->stickers.contains(document);
|
||||
}
|
||||
|
||||
void CheckFavedLimit(Set &set) {
|
||||
@@ -242,7 +225,7 @@ void MoveFavedToFront(Set &set, int index) {
|
||||
void RequestSetToPushFaved(not_null<DocumentData*> document);
|
||||
|
||||
void SetIsFaved(not_null<DocumentData*> document, base::optional<std::vector<not_null<EmojiPtr>>> emojiList = base::none) {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(FavedSetId);
|
||||
if (it == sets.end()) {
|
||||
it = sets.insert(FavedSetId, Set(FavedSetId, 0, Lang::Hard::FavedSetTitle(), QString(), 0, 0, MTPDstickerSet_ClientFlag::f_special | 0));
|
||||
@@ -262,7 +245,7 @@ void SetIsFaved(not_null<DocumentData*> document, base::optional<std::vector<not
|
||||
return;
|
||||
}
|
||||
Local::writeFavedStickers();
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
Auth().api().stickerSetInstalled(FavedSetId);
|
||||
}
|
||||
|
||||
@@ -305,7 +288,7 @@ void RequestSetToPushFaved(not_null<DocumentData*> document) {
|
||||
}
|
||||
|
||||
void SetIsNotFaved(not_null<DocumentData*> document) {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(FavedSetId);
|
||||
if (it == sets.end()) {
|
||||
return;
|
||||
@@ -330,7 +313,7 @@ void SetIsNotFaved(not_null<DocumentData*> document) {
|
||||
sets.erase(it);
|
||||
}
|
||||
Local::writeFavedStickers();
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
}
|
||||
|
||||
void SetFaved(not_null<DocumentData*> document, bool faved) {
|
||||
@@ -342,10 +325,10 @@ void SetFaved(not_null<DocumentData*> document, bool faved) {
|
||||
}
|
||||
|
||||
void SetsReceived(const QVector<MTPStickerSet> &data, int32 hash) {
|
||||
auto &setsOrder = Global::RefStickerSetsOrder();
|
||||
auto &setsOrder = Auth().data().stickerSetsOrderRef();
|
||||
setsOrder.clear();
|
||||
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
QMap<uint64, uint64> setsToRequest;
|
||||
for (auto &set : sets) {
|
||||
if (!(set.flags & MTPDstickerSet::Flag::f_archived)) {
|
||||
@@ -402,10 +385,10 @@ void SetsReceived(const QVector<MTPStickerSet> &data, int32 hash) {
|
||||
LOG(("API Error: received stickers hash %1 while counted hash is %2").arg(hash).arg(Local::countStickersHash()));
|
||||
}
|
||||
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
}
|
||||
|
||||
void SetPackAndEmoji(Set &set, StickerPack &&pack, const QVector<MTPStickerPack> &packs) {
|
||||
void SetPackAndEmoji(Set &set, Pack &&pack, const QVector<MTPStickerPack> &packs) {
|
||||
set.stickers = std::move(pack);
|
||||
set.emoji.clear();
|
||||
for_const (auto &mtpPack, packs) {
|
||||
@@ -415,7 +398,7 @@ void SetPackAndEmoji(Set &set, StickerPack &&pack, const QVector<MTPStickerPack>
|
||||
emoji = emoji->original();
|
||||
auto &stickers = pack.vdocuments.v;
|
||||
|
||||
auto p = StickerPack();
|
||||
auto p = Pack();
|
||||
p.reserve(stickers.size());
|
||||
for (auto j = 0, c = stickers.size(); j != c; ++j) {
|
||||
auto document = App::document(stickers[j].v);
|
||||
@@ -429,7 +412,7 @@ void SetPackAndEmoji(Set &set, StickerPack &&pack, const QVector<MTPStickerPack>
|
||||
}
|
||||
|
||||
void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVector<MTPDocument> &items, int32 hash, const QVector<MTPStickerPack> &packs) {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(setId);
|
||||
|
||||
auto &d_docs = items;
|
||||
@@ -446,7 +429,7 @@ void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVector<MTP
|
||||
it->hash = hash;
|
||||
|
||||
auto custom = sets.find(CustomSetId);
|
||||
auto pack = StickerPack();
|
||||
auto pack = Pack();
|
||||
pack.reserve(d_docs.size());
|
||||
for_const (auto &mtpDocument, d_docs) {
|
||||
auto document = App::feedDocument(mtpDocument);
|
||||
@@ -503,7 +486,7 @@ void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVector<MTP
|
||||
default: Unexpected("setId in SpecialSetReceived()");
|
||||
}
|
||||
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
}
|
||||
|
||||
void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVector<MTPlong> &unread, int32 hash) {
|
||||
@@ -512,10 +495,10 @@ void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVect
|
||||
unreadMap.insert(unreadSetId.v);
|
||||
}
|
||||
|
||||
auto &setsOrder = Global::RefFeaturedStickerSetsOrder();
|
||||
auto &setsOrder = Auth().data().featuredStickerSetsOrderRef();
|
||||
setsOrder.clear();
|
||||
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
QMap<uint64, uint64> setsToRequest;
|
||||
for (auto &set : sets) {
|
||||
set.flags &= ~MTPDstickerSet_ClientFlag::f_featured; // mark for removing
|
||||
@@ -587,10 +570,7 @@ void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVect
|
||||
it = sets.erase(it);
|
||||
}
|
||||
}
|
||||
if (Global::FeaturedStickerSetsUnreadCount() != unreadCount) {
|
||||
Global::SetFeaturedStickerSetsUnreadCount(unreadCount);
|
||||
Global::RefFeaturedStickerSetsUnreadCountChanged().notify();
|
||||
}
|
||||
Auth().data().setFeaturedStickerSetsUnreadCount(unreadCount);
|
||||
|
||||
if (Local::countFeaturedStickersHash() != hash) {
|
||||
LOG(("API Error: received featured stickers hash %1 while counted hash is %2").arg(hash).arg(Local::countFeaturedStickersHash()));
|
||||
@@ -606,11 +586,11 @@ void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVect
|
||||
|
||||
Local::writeFeaturedStickers();
|
||||
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
}
|
||||
|
||||
void GifsReceived(const QVector<MTPDocument> &items, int32 hash) {
|
||||
auto &saved = cRefSavedGifs();
|
||||
auto &saved = Auth().data().savedGifsRef();
|
||||
saved.clear();
|
||||
|
||||
saved.reserve(items.size());
|
||||
@@ -629,16 +609,16 @@ void GifsReceived(const QVector<MTPDocument> &items, int32 hash) {
|
||||
|
||||
Local::writeSavedGifs();
|
||||
|
||||
Auth().data().savedGifsUpdated().notify();
|
||||
Auth().data().markSavedGifsUpdated();
|
||||
}
|
||||
|
||||
StickerPack GetListByEmoji(not_null<EmojiPtr> emoji) {
|
||||
Pack GetListByEmoji(not_null<EmojiPtr> emoji) {
|
||||
auto original = emoji->original();
|
||||
auto result = StickerPack();
|
||||
auto result = Pack();
|
||||
auto setsToRequest = QMap<uint64, uint64>();
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
|
||||
auto faved = StickerPack();
|
||||
auto faved = Pack();
|
||||
auto favedIt = sets.find(Stickers::FavedSetId);
|
||||
if (favedIt != sets.cend()) {
|
||||
auto i = favedIt->emoji.constFind(original);
|
||||
@@ -647,7 +627,7 @@ StickerPack GetListByEmoji(not_null<EmojiPtr> emoji) {
|
||||
result = faved;
|
||||
}
|
||||
}
|
||||
auto &order = Global::StickerSetsOrder();
|
||||
auto &order = Auth().data().stickerSetsOrder();
|
||||
for (auto i = 0, l = order.size(); i != l; ++i) {
|
||||
auto it = sets.find(order[i]);
|
||||
if (it != sets.cend()) {
|
||||
@@ -683,7 +663,7 @@ base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
|
||||
if (inputSet.type() != mtpc_inputStickerSetID) {
|
||||
return base::none;
|
||||
}
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(inputSet.c_inputStickerSetID().vid.v);
|
||||
if (it == sets.cend()) {
|
||||
return base::none;
|
||||
@@ -703,7 +683,7 @@ base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
|
||||
}
|
||||
|
||||
Set *FeedSet(const MTPDstickerSet &set) {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(set.vid.v);
|
||||
auto title = GetSetTitle(set);
|
||||
auto flags = MTPDstickerSet::Flags(0);
|
||||
@@ -724,13 +704,13 @@ Set *FeedSet(const MTPDstickerSet &set) {
|
||||
}
|
||||
auto changedFlags = (flags ^ it->flags);
|
||||
if (changedFlags & MTPDstickerSet::Flag::f_archived) {
|
||||
auto index = Global::ArchivedStickerSetsOrder().indexOf(it->id);
|
||||
auto index = Auth().data().archivedStickerSetsOrder().indexOf(it->id);
|
||||
if (it->flags & MTPDstickerSet::Flag::f_archived) {
|
||||
if (index < 0) {
|
||||
Global::RefArchivedStickerSetsOrder().push_front(it->id);
|
||||
Auth().data().archivedStickerSetsOrderRef().push_front(it->id);
|
||||
}
|
||||
} else if (index >= 0) {
|
||||
Global::RefArchivedStickerSetsOrder().removeAt(index);
|
||||
Auth().data().archivedStickerSetsOrderRef().removeAt(index);
|
||||
}
|
||||
}
|
||||
return &it.value();
|
||||
@@ -744,11 +724,11 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
|
||||
|
||||
set->flags &= ~MTPDstickerSet_ClientFlag::f_not_loaded;
|
||||
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto &d_docs = d.vdocuments.v;
|
||||
auto custom = sets.find(Stickers::CustomSetId);
|
||||
|
||||
auto pack = StickerPack();
|
||||
auto pack = Pack();
|
||||
pack.reserve(d_docs.size());
|
||||
for (auto i = 0, l = d_docs.size(); i != l; ++i) {
|
||||
auto doc = App::feedDocument(d_docs.at(i));
|
||||
@@ -779,8 +759,8 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
|
||||
}
|
||||
|
||||
if (pack.isEmpty()) {
|
||||
int removeIndex = Global::StickerSetsOrder().indexOf(set->id);
|
||||
if (removeIndex >= 0) Global::RefStickerSetsOrder().removeAt(removeIndex);
|
||||
int removeIndex = Auth().data().stickerSetsOrder().indexOf(set->id);
|
||||
if (removeIndex >= 0) Auth().data().stickerSetsOrderRef().removeAt(removeIndex);
|
||||
sets.remove(set->id);
|
||||
set = nullptr;
|
||||
} else {
|
||||
@@ -795,7 +775,7 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
|
||||
emoji = emoji->original();
|
||||
auto &stickers = pack.vdocuments.v;
|
||||
|
||||
StickerPack p;
|
||||
Pack p;
|
||||
p.reserve(stickers.size());
|
||||
for (auto j = 0, c = stickers.size(); j != c; ++j) {
|
||||
auto doc = App::document(stickers[j].v);
|
||||
@@ -823,7 +803,7 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data) {
|
||||
}
|
||||
}
|
||||
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
Auth().data().markStickersUpdated();
|
||||
|
||||
return set;
|
||||
}
|
||||
@@ -836,51 +816,4 @@ QString GetSetTitle(const MTPDstickerSet &s) {
|
||||
return title;
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
FeaturedReader::FeaturedReader(QObject *parent) : QObject(parent)
|
||||
, _timer(this) {
|
||||
_timer->setTimeoutHandler([this] { readSets(); });
|
||||
}
|
||||
|
||||
void FeaturedReader::scheduleRead(uint64 setId) {
|
||||
if (!_setIds.contains(setId)) {
|
||||
_setIds.insert(setId);
|
||||
_timer->start(kReadFeaturedSetsTimeoutMs);
|
||||
}
|
||||
}
|
||||
|
||||
void FeaturedReader::readSets() {
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto count = Global::FeaturedStickerSetsUnreadCount();
|
||||
QVector<MTPlong> wrappedIds;
|
||||
wrappedIds.reserve(_setIds.size());
|
||||
for_const (auto setId, _setIds) {
|
||||
auto it = sets.find(setId);
|
||||
if (it != sets.cend()) {
|
||||
it->flags &= ~MTPDstickerSet_ClientFlag::f_unread;
|
||||
wrappedIds.append(MTP_long(setId));
|
||||
if (count) {
|
||||
--count;
|
||||
}
|
||||
}
|
||||
}
|
||||
_setIds.clear();
|
||||
|
||||
if (!wrappedIds.empty()) {
|
||||
request(MTPmessages_ReadFeaturedStickers(MTP_vector<MTPlong>(wrappedIds))).done([](const MTPBool &result) {
|
||||
Local::writeFeaturedStickers();
|
||||
if (AuthSession::Exists()) {
|
||||
Auth().data().stickersUpdated().notify(true);
|
||||
}
|
||||
}).send();
|
||||
|
||||
if (Global::FeaturedStickerSetsUnreadCount() != count) {
|
||||
Global::SetFeaturedStickerSetsUnreadCount(count);
|
||||
Global::RefFeaturedStickerSetsUnreadCountChanged().notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace Stickers
|
||||
|
@@ -24,13 +24,52 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
|
||||
namespace Stickers {
|
||||
|
||||
constexpr auto DefaultSetId = 0; // for backward compatibility
|
||||
constexpr auto CustomSetId = 0xFFFFFFFFFFFFFFFFULL;
|
||||
constexpr auto RecentSetId = 0xFFFFFFFFFFFFFFFEULL; // for emoji/stickers panel, should not appear in Sets
|
||||
constexpr auto NoneSetId = 0xFFFFFFFFFFFFFFFDULL; // for emoji/stickers panel, should not appear in Sets
|
||||
constexpr auto CloudRecentSetId = 0xFFFFFFFFFFFFFFFCULL; // for cloud-stored recent stickers
|
||||
constexpr auto FeaturedSetId = 0xFFFFFFFFFFFFFFFBULL; // for emoji/stickers panel, should not appear in Sets
|
||||
constexpr auto FavedSetId = 0xFFFFFFFFFFFFFFFAULL; // for cloud-stored faved stickers
|
||||
constexpr auto MegagroupSetId = 0xFFFFFFFFFFFFFFEFULL; // for setting up megagroup sticker set
|
||||
|
||||
using Order = QList<uint64>;
|
||||
using SavedGifs = QVector<DocumentData*>;
|
||||
using Pack = QVector<DocumentData*>;
|
||||
using ByEmojiMap = QMap<EmojiPtr, Pack>;
|
||||
|
||||
struct Set {
|
||||
Set(uint64 id, uint64 access, const QString &title, const QString &shortName, int32 count, int32 hash, MTPDstickerSet::Flags flags)
|
||||
: id(id)
|
||||
, access(access)
|
||||
, title(title)
|
||||
, shortName(shortName)
|
||||
, count(count)
|
||||
, hash(hash)
|
||||
, flags(flags) {
|
||||
}
|
||||
uint64 id, access;
|
||||
QString title, shortName;
|
||||
int32 count, hash;
|
||||
MTPDstickerSet::Flags flags;
|
||||
Pack stickers;
|
||||
ByEmojiMap emoji;
|
||||
};
|
||||
using Sets = QMap<uint64, Set>;
|
||||
|
||||
inline MTPInputStickerSet inputSetId(const Set &set) {
|
||||
if (set.id && set.access) {
|
||||
return MTP_inputStickerSetID(MTP_long(set.id), MTP_long(set.access));
|
||||
}
|
||||
return MTP_inputStickerSetShortName(MTP_string(set.shortName));
|
||||
}
|
||||
|
||||
constexpr auto kPanelPerRow = 5;
|
||||
|
||||
void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d);
|
||||
bool ApplyArchivedResultFake(); // For testing.
|
||||
void InstallLocally(uint64 setId);
|
||||
void UndoInstallLocally(uint64 setId);
|
||||
void MarkFeaturedAsRead(uint64 setId);
|
||||
bool IsFaved(not_null<DocumentData*> document);
|
||||
void SetFaved(not_null<DocumentData*> document, bool faved);
|
||||
|
||||
@@ -39,7 +78,7 @@ void SpecialSetReceived(uint64 setId, const QString &setTitle, const QVector<MTP
|
||||
void FeaturedSetsReceived(const QVector<MTPStickerSetCovered> &data, const QVector<MTPlong> &unread, int32 hash);
|
||||
void GifsReceived(const QVector<MTPDocument> &items, int32 hash);
|
||||
|
||||
StickerPack GetListByEmoji(not_null<EmojiPtr> emoji);
|
||||
Pack GetListByEmoji(not_null<EmojiPtr> emoji);
|
||||
base::optional<std::vector<not_null<EmojiPtr>>> GetEmojiListFromSet(
|
||||
not_null<DocumentData*> document);
|
||||
|
||||
@@ -48,20 +87,4 @@ Set *FeedSetFull(const MTPmessages_StickerSet &data);
|
||||
|
||||
QString GetSetTitle(const MTPDstickerSet &s);
|
||||
|
||||
namespace internal {
|
||||
|
||||
class FeaturedReader : public QObject, private MTP::Sender {
|
||||
public:
|
||||
FeaturedReader(QObject *parent);
|
||||
void scheduleRead(uint64 setId);
|
||||
|
||||
private:
|
||||
void readSets();
|
||||
|
||||
object_ptr<SingleTimer> _timer;
|
||||
OrderedSet<uint64> _setIds;
|
||||
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace Stickers
|
||||
|
@@ -398,7 +398,7 @@ void StickersListWidget::Footer::paintStickerSettingsIcon(Painter &p) const {
|
||||
}
|
||||
|
||||
void StickersListWidget::Footer::paintFeaturedStickerSetsBadge(Painter &p, int iconLeft) const {
|
||||
if (auto unread = Global::FeaturedStickerSetsUnreadCount()) {
|
||||
if (auto unread = Auth().data().featuredStickerSetsUnreadCount()) {
|
||||
Dialogs::Layout::UnreadBadgeStyle unreadSt;
|
||||
unreadSt.sizeId = Dialogs::Layout::UnreadBadgeInStickersPanel;
|
||||
unreadSt.size = st::stickersSettingsUnreadSize;
|
||||
@@ -502,7 +502,7 @@ void StickersListWidget::readVisibleSets() {
|
||||
}
|
||||
}
|
||||
if (loaded == count) {
|
||||
Stickers::MarkFeaturedAsRead(set.id);
|
||||
Auth().api().readFeaturedSetDelayed(set.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1049,7 +1049,7 @@ void StickersListWidget::removeRecentSticker(int section, int index) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(Stickers::CustomSetId);
|
||||
if (it != sets.cend()) {
|
||||
for (int i = 0, l = it->stickers.size(); i < l; ++i) {
|
||||
@@ -1135,20 +1135,20 @@ void StickersListWidget::refreshStickers() {
|
||||
|
||||
_mySets.clear();
|
||||
_favedStickersMap.clear();
|
||||
_mySets.reserve(Global::StickerSetsOrder().size() + 3);
|
||||
_mySets.reserve(Auth().data().stickerSetsOrder().size() + 3);
|
||||
|
||||
refreshFavedStickers();
|
||||
refreshRecentStickers(false);
|
||||
refreshMegagroupStickers(GroupStickersPlace::Visible);
|
||||
for_const (auto setId, Global::StickerSetsOrder()) {
|
||||
for_const (auto setId, Auth().data().stickerSetsOrder()) {
|
||||
appendSet(_mySets, setId, AppendSkip::Archived);
|
||||
}
|
||||
refreshMegagroupStickers(GroupStickersPlace::Hidden);
|
||||
|
||||
_featuredSets.clear();
|
||||
_featuredSets.reserve(Global::FeaturedStickerSetsOrder().size());
|
||||
_featuredSets.reserve(Auth().data().featuredStickerSetsOrder().size());
|
||||
|
||||
for_const (auto setId, Global::FeaturedStickerSetsOrder()) {
|
||||
for_const (auto setId, Auth().data().featuredStickerSetsOrder()) {
|
||||
appendSet(_featuredSets, setId, AppendSkip::Installed);
|
||||
}
|
||||
|
||||
@@ -1203,7 +1203,7 @@ uint64 StickersListWidget::currentSet(int yOffset) const {
|
||||
}
|
||||
|
||||
void StickersListWidget::appendSet(Sets &to, uint64 setId, AppendSkip skip) {
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(setId);
|
||||
if (it == sets.cend() || it->stickers.isEmpty()) return;
|
||||
if ((skip == AppendSkip::Archived) && (it->flags & MTPDstickerSet::Flag::f_archived)) return;
|
||||
@@ -1228,12 +1228,12 @@ void StickersListWidget::refreshRecent() {
|
||||
void StickersListWidget::refreshRecentStickers(bool performResize) {
|
||||
_custom.clear();
|
||||
clearSelection();
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto &recent = cGetRecentStickers();
|
||||
auto customIt = sets.constFind(Stickers::CustomSetId);
|
||||
auto cloudIt = sets.constFind(Stickers::CloudRecentSetId);
|
||||
|
||||
StickerPack recentPack;
|
||||
Stickers::Pack recentPack;
|
||||
int customCnt = (customIt == sets.cend()) ? 0 : customIt->stickers.size();
|
||||
int cloudCnt = (cloudIt == sets.cend()) ? 0 : cloudIt->stickers.size();
|
||||
recentPack.reserve(cloudCnt + recent.size() + customCnt);
|
||||
@@ -1285,7 +1285,7 @@ void StickersListWidget::refreshRecentStickers(bool performResize) {
|
||||
|
||||
void StickersListWidget::refreshFavedStickers() {
|
||||
clearSelection();
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(Stickers::FavedSetId);
|
||||
if (it == sets.cend() || it->stickers.isEmpty()) {
|
||||
return;
|
||||
@@ -1324,7 +1324,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
|
||||
}
|
||||
if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) {
|
||||
auto &set = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID();
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(set.vid.v);
|
||||
if (it != sets.cend()) {
|
||||
auto isInstalled = (it->flags & MTPDstickerSet::Flag::f_installed)
|
||||
@@ -1350,7 +1350,7 @@ void StickersListWidget::refreshMegagroupStickers(GroupStickersPlace place) {
|
||||
void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
|
||||
icons.clear();
|
||||
icons.reserve(_mySets.size() + 1);
|
||||
if (Global::FeaturedStickerSetsUnreadCount() && !_featuredSets.isEmpty()) {
|
||||
if (Auth().data().featuredStickerSetsUnreadCount() && !_featuredSets.isEmpty()) {
|
||||
icons.push_back(StickerIcon(Stickers::FeaturedSetId));
|
||||
}
|
||||
|
||||
@@ -1384,7 +1384,7 @@ void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
|
||||
icons.push_back(StickerIcon(_mySets[i].id, s, pixw, pixh));
|
||||
}
|
||||
|
||||
if (!Global::FeaturedStickerSetsUnreadCount() && !_featuredSets.isEmpty()) {
|
||||
if (!Auth().data().featuredStickerSetsUnreadCount() && !_featuredSets.isEmpty()) {
|
||||
icons.push_back(StickerIcon(Stickers::FeaturedSetId));
|
||||
}
|
||||
}
|
||||
@@ -1623,7 +1623,7 @@ void StickersListWidget::displaySet(uint64 setId) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(setId);
|
||||
if (it != sets.cend()) {
|
||||
_displayingSetId = setId;
|
||||
@@ -1638,7 +1638,7 @@ void StickersListWidget::displaySet(uint64 setId) {
|
||||
}
|
||||
|
||||
void StickersListWidget::installSet(uint64 setId) {
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(setId);
|
||||
if (it != sets.cend()) {
|
||||
request(MTPmessages_InstallStickerSet(Stickers::inputSetId(*it), MTP_bool(false))).done([this](const MTPmessages_StickerSetInstallResult &result) {
|
||||
@@ -1678,14 +1678,14 @@ void StickersListWidget::removeMegagroupSet(bool locally) {
|
||||
}
|
||||
|
||||
void StickersListWidget::removeSet(uint64 setId) {
|
||||
auto &sets = Global::StickerSets();
|
||||
auto &sets = Auth().data().stickerSets();
|
||||
auto it = sets.constFind(setId);
|
||||
if (it != sets.cend()) {
|
||||
_removingSetId = it->id;
|
||||
auto text = lng_stickers_remove_pack(lt_sticker_pack, it->title);
|
||||
Ui::show(Box<ConfirmBox>(text, lang(lng_box_remove), base::lambda_guarded(this, [this] {
|
||||
Ui::hideLayer();
|
||||
auto &sets = Global::RefStickerSets();
|
||||
auto &sets = Auth().data().stickerSetsRef();
|
||||
auto it = sets.find(_removingSetId);
|
||||
if (it != sets.cend()) {
|
||||
if (it->id && it->access) {
|
||||
@@ -1707,8 +1707,8 @@ void StickersListWidget::removeSet(uint64 setId) {
|
||||
if (!(it->flags & MTPDstickerSet_ClientFlag::f_featured) && !(it->flags & MTPDstickerSet_ClientFlag::f_special)) {
|
||||
sets.erase(it);
|
||||
}
|
||||
int removeIndex = Global::StickerSetsOrder().indexOf(_removingSetId);
|
||||
if (removeIndex >= 0) Global::RefStickerSetsOrder().removeAt(removeIndex);
|
||||
int removeIndex = Auth().data().stickerSetsOrder().indexOf(_removingSetId);
|
||||
if (removeIndex >= 0) Auth().data().stickerSetsOrderRef().removeAt(removeIndex);
|
||||
refreshStickers();
|
||||
Local::writeInstalledStickers();
|
||||
if (writeRecent) Local::writeUserSettings();
|
||||
|
@@ -35,7 +35,10 @@ namespace ChatHelpers {
|
||||
|
||||
struct StickerIcon;
|
||||
|
||||
class StickersListWidget : public TabbedSelector::Inner, private base::Subscriber, private MTP::Sender {
|
||||
class StickersListWidget
|
||||
: public TabbedSelector::Inner
|
||||
, private base::Subscriber
|
||||
, private MTP::Sender {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@@ -135,12 +138,12 @@ private:
|
||||
};
|
||||
|
||||
struct Set {
|
||||
Set(uint64 id, MTPDstickerSet::Flags flags, const QString &title, int32 hoversSize, const StickerPack &pack = StickerPack()) : id(id), flags(flags), title(title), pack(pack) {
|
||||
Set(uint64 id, MTPDstickerSet::Flags flags, const QString &title, int32 hoversSize, const Stickers::Pack &pack = Stickers::Pack()) : id(id), flags(flags), title(title), pack(pack) {
|
||||
}
|
||||
uint64 id;
|
||||
MTPDstickerSet::Flags flags;
|
||||
QString title;
|
||||
StickerPack pack;
|
||||
Stickers::Pack pack;
|
||||
QSharedPointer<Ui::RippleAnimation> ripple;
|
||||
};
|
||||
using Sets = QList<Set>;
|
||||
|
@@ -698,7 +698,10 @@ void TabbedSelector::scrollToY(int y) {
|
||||
_topShadow->update();
|
||||
}
|
||||
|
||||
TabbedSelector::Inner::Inner(QWidget *parent, not_null<Window::Controller*> controller) : TWidget(parent)
|
||||
TabbedSelector::Inner::Inner(
|
||||
QWidget *parent,
|
||||
not_null<Window::Controller*> controller)
|
||||
: RpWidget(parent)
|
||||
, _controller(controller) {
|
||||
}
|
||||
|
||||
|
@@ -206,7 +206,7 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class TabbedSelector::Inner : public TWidget {
|
||||
class TabbedSelector::Inner : public Ui::RpWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user