2020-06-08 17:24:36 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/sender.h"
|
|
|
|
#include "data/stickers/data_stickers_set.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
class HistoryItem;
|
|
|
|
class DocumentData;
|
|
|
|
|
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2022-05-09 13:09:46 +00:00
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
|
|
|
|
2023-05-02 09:33:19 +00:00
|
|
|
namespace ChatHelpers {
|
|
|
|
class Show;
|
|
|
|
} // namespace ChatHelpers
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
class Session;
|
|
|
|
class DocumentMedia;
|
|
|
|
|
2022-07-08 17:04:31 +00:00
|
|
|
enum class StickersType : uchar {
|
|
|
|
Stickers,
|
|
|
|
Masks,
|
|
|
|
Emoji,
|
|
|
|
};
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
class Stickers final {
|
|
|
|
public:
|
|
|
|
explicit Stickers(not_null<Session*> owner);
|
|
|
|
|
|
|
|
[[nodiscard]] Session &owner() const;
|
|
|
|
[[nodiscard]] Main::Session &session() const;
|
|
|
|
|
|
|
|
// for backward compatibility
|
|
|
|
static constexpr auto DefaultSetId = 0;
|
|
|
|
static constexpr auto CustomSetId = 0xFFFFFFFFFFFFFFFFULL;
|
|
|
|
|
|
|
|
// For stickers panel, should not appear in Sets.
|
|
|
|
static constexpr auto RecentSetId = 0xFFFFFFFFFFFFFFFEULL;
|
|
|
|
static constexpr auto NoneSetId = 0xFFFFFFFFFFFFFFFDULL;
|
|
|
|
static constexpr auto FeaturedSetId = 0xFFFFFFFFFFFFFFFBULL;
|
2023-01-24 14:46:16 +00:00
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
// For cloud-stored recent stickers.
|
|
|
|
static constexpr auto CloudRecentSetId = 0xFFFFFFFFFFFFFFFCULL;
|
2021-03-25 11:05:33 +00:00
|
|
|
static constexpr auto CloudRecentAttachedSetId = 0xFFFFFFFFFFFFFFF9ULL;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
// For cloud-stored faved stickers.
|
|
|
|
static constexpr auto FavedSetId = 0xFFFFFFFFFFFFFFFAULL;
|
|
|
|
|
|
|
|
// For setting up megagroup sticker set.
|
|
|
|
static constexpr auto MegagroupSetId = 0xFFFFFFFFFFFFFFEFULL;
|
|
|
|
|
2022-07-26 14:45:41 +00:00
|
|
|
void notifyUpdated(StickersType type);
|
|
|
|
[[nodiscard]] rpl::producer<StickersType> updated() const;
|
|
|
|
[[nodiscard]] rpl::producer<> updated(StickersType type) const;
|
|
|
|
void notifyRecentUpdated(StickersType type);
|
|
|
|
[[nodiscard]] rpl::producer<StickersType> recentUpdated() const;
|
|
|
|
[[nodiscard]] rpl::producer<> recentUpdated(StickersType type) const;
|
2020-06-08 17:24:36 +00:00
|
|
|
void notifySavedGifsUpdated();
|
|
|
|
[[nodiscard]] rpl::producer<> savedGifsUpdated() const;
|
2021-03-29 22:28:19 +00:00
|
|
|
void notifyStickerSetInstalled(uint64 setId);
|
|
|
|
[[nodiscard]] rpl::producer<uint64> stickerSetInstalled() const;
|
2022-07-08 18:07:14 +00:00
|
|
|
void notifyEmojiSetInstalled(uint64 setId);
|
|
|
|
[[nodiscard]] rpl::producer<uint64> emojiSetInstalled() const;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
void incrementSticker(not_null<DocumentData*> document);
|
|
|
|
|
2020-06-08 17:24:36 +00:00
|
|
|
bool updateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastUpdate(crl::time update) {
|
|
|
|
_lastUpdate = update;
|
|
|
|
}
|
|
|
|
bool recentUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastRecentUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastRecentUpdate(crl::time update) {
|
|
|
|
if (update) {
|
2022-07-26 14:45:41 +00:00
|
|
|
notifyRecentUpdated(StickersType::Stickers);
|
2020-06-08 17:24:36 +00:00
|
|
|
}
|
|
|
|
_lastRecentUpdate = update;
|
|
|
|
}
|
2021-03-25 11:05:33 +00:00
|
|
|
bool masksUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastMasksUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastMasksUpdate(crl::time update) {
|
|
|
|
_lastMasksUpdate = update;
|
|
|
|
}
|
2022-07-08 17:04:31 +00:00
|
|
|
bool emojiUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastEmojiUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastEmojiUpdate(crl::time update) {
|
|
|
|
_lastEmojiUpdate = update;
|
|
|
|
}
|
2021-03-25 11:05:33 +00:00
|
|
|
bool recentAttachedUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastRecentAttachedUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastRecentAttachedUpdate(crl::time update) {
|
|
|
|
if (update) {
|
2022-07-26 14:45:41 +00:00
|
|
|
notifyRecentUpdated(StickersType::Masks);
|
2021-03-25 11:05:33 +00:00
|
|
|
}
|
|
|
|
_lastRecentAttachedUpdate = update;
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
bool favedUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastFavedUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastFavedUpdate(crl::time update) {
|
|
|
|
_lastFavedUpdate = update;
|
|
|
|
}
|
|
|
|
bool featuredUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastFeaturedUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastFeaturedUpdate(crl::time update) {
|
|
|
|
_lastFeaturedUpdate = update;
|
|
|
|
}
|
2022-07-22 13:08:10 +00:00
|
|
|
bool featuredEmojiUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastFeaturedEmojiUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastFeaturedEmojiUpdate(crl::time update) {
|
|
|
|
_lastFeaturedEmojiUpdate = update;
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
bool savedGifsUpdateNeeded(crl::time now) const {
|
|
|
|
return updateNeeded(_lastSavedGifsUpdate, now);
|
|
|
|
}
|
|
|
|
void setLastSavedGifsUpdate(crl::time update) {
|
|
|
|
_lastSavedGifsUpdate = update;
|
|
|
|
}
|
|
|
|
int featuredSetsUnreadCount() const {
|
|
|
|
return _featuredSetsUnreadCount.current();
|
|
|
|
}
|
|
|
|
void setFeaturedSetsUnreadCount(int count) {
|
|
|
|
_featuredSetsUnreadCount = count;
|
|
|
|
}
|
|
|
|
[[nodiscard]] rpl::producer<int> featuredSetsUnreadCountValue() const {
|
|
|
|
return _featuredSetsUnreadCount.value();
|
|
|
|
}
|
|
|
|
const StickersSets &sets() const {
|
|
|
|
return _sets;
|
|
|
|
}
|
|
|
|
StickersSets &setsRef() {
|
|
|
|
return _sets;
|
|
|
|
}
|
|
|
|
const StickersSetsOrder &setsOrder() const {
|
|
|
|
return _setsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &setsOrderRef() {
|
|
|
|
return _setsOrder;
|
|
|
|
}
|
2021-03-25 11:05:33 +00:00
|
|
|
const StickersSetsOrder &maskSetsOrder() const {
|
|
|
|
return _maskSetsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &maskSetsOrderRef() {
|
|
|
|
return _maskSetsOrder;
|
|
|
|
}
|
2022-07-08 17:04:31 +00:00
|
|
|
const StickersSetsOrder &emojiSetsOrder() const {
|
|
|
|
return _emojiSetsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &emojiSetsOrderRef() {
|
|
|
|
return _emojiSetsOrder;
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
const StickersSetsOrder &featuredSetsOrder() const {
|
|
|
|
return _featuredSetsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &featuredSetsOrderRef() {
|
|
|
|
return _featuredSetsOrder;
|
|
|
|
}
|
2022-07-22 13:08:10 +00:00
|
|
|
const StickersSetsOrder &featuredEmojiSetsOrder() const {
|
|
|
|
return _featuredEmojiSetsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &featuredEmojiSetsOrderRef() {
|
|
|
|
return _featuredEmojiSetsOrder;
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
const StickersSetsOrder &archivedSetsOrder() const {
|
|
|
|
return _archivedSetsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &archivedSetsOrderRef() {
|
|
|
|
return _archivedSetsOrder;
|
|
|
|
}
|
2021-03-30 15:51:45 +00:00
|
|
|
const StickersSetsOrder &archivedMaskSetsOrder() const {
|
|
|
|
return _archivedMaskSetsOrder;
|
|
|
|
}
|
|
|
|
StickersSetsOrder &archivedMaskSetsOrderRef() {
|
|
|
|
return _archivedMaskSetsOrder;
|
|
|
|
}
|
2020-06-08 17:24:36 +00:00
|
|
|
const SavedGifs &savedGifs() const {
|
|
|
|
return _savedGifs;
|
|
|
|
}
|
|
|
|
SavedGifs &savedGifsRef() {
|
|
|
|
return _savedGifs;
|
|
|
|
}
|
2020-08-19 14:04:05 +00:00
|
|
|
void removeFromRecentSet(not_null<DocumentData*> document);
|
2020-06-08 17:24:36 +00:00
|
|
|
|
2022-05-09 13:09:46 +00:00
|
|
|
void addSavedGif(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
2022-05-09 13:09:46 +00:00
|
|
|
not_null<DocumentData*> document);
|
2020-06-08 17:24:36 +00:00
|
|
|
void checkSavedGif(not_null<HistoryItem*> item);
|
|
|
|
|
|
|
|
void applyArchivedResult(
|
|
|
|
const MTPDmessages_stickerSetInstallResultArchive &d);
|
|
|
|
void installLocally(uint64 setId);
|
|
|
|
void undoInstallLocally(uint64 setId);
|
|
|
|
bool isFaved(not_null<const DocumentData*> document);
|
2022-05-09 13:09:46 +00:00
|
|
|
void setFaved(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
2022-05-09 13:09:46 +00:00
|
|
|
not_null<DocumentData*> document,
|
|
|
|
bool faved);
|
2020-06-08 17:24:36 +00:00
|
|
|
|
2021-08-25 08:15:05 +00:00
|
|
|
void setsReceived(const QVector<MTPStickerSet> &data, uint64 hash);
|
|
|
|
void masksReceived(const QVector<MTPStickerSet> &data, uint64 hash);
|
2022-07-08 17:04:31 +00:00
|
|
|
void emojiReceived(const QVector<MTPStickerSet> &data, uint64 hash);
|
2020-06-08 17:24:36 +00:00
|
|
|
void specialSetReceived(
|
|
|
|
uint64 setId,
|
|
|
|
const QString &setTitle,
|
|
|
|
const QVector<MTPDocument> &items,
|
2021-08-25 08:15:05 +00:00
|
|
|
uint64 hash,
|
2020-06-08 17:24:36 +00:00
|
|
|
const QVector<MTPStickerPack> &packs = QVector<MTPStickerPack>(),
|
|
|
|
const QVector<MTPint> &usageDates = QVector<MTPint>());
|
2022-07-22 13:08:10 +00:00
|
|
|
void featuredSetsReceived(const MTPmessages_FeaturedStickers &result);
|
|
|
|
void featuredEmojiSetsReceived(
|
|
|
|
const MTPmessages_FeaturedStickers &result);
|
2021-08-25 08:15:05 +00:00
|
|
|
void gifsReceived(const QVector<MTPDocument> &items, uint64 hash);
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
std::vector<not_null<DocumentData*>> getListByEmoji(
|
2023-01-24 14:46:16 +00:00
|
|
|
std::vector<EmojiPtr> emoji,
|
|
|
|
uint64 seed,
|
|
|
|
bool forceAllResults = false);
|
2020-06-08 17:24:36 +00:00
|
|
|
std::optional<std::vector<not_null<EmojiPtr>>> getEmojiListFromSet(
|
|
|
|
not_null<DocumentData*> document);
|
|
|
|
|
2022-07-19 09:31:12 +00:00
|
|
|
not_null<StickersSet*> feedSet(const MTPStickerSet &data);
|
2022-08-15 08:33:24 +00:00
|
|
|
not_null<StickersSet*> feedSet(const MTPStickerSetCovered &data);
|
2022-07-19 09:31:12 +00:00
|
|
|
not_null<StickersSet*> feedSetFull(const MTPDmessages_stickerSet &data);
|
|
|
|
void feedSetStickers(
|
|
|
|
not_null<StickersSet*> set,
|
|
|
|
const QVector<MTPDocument> &documents,
|
|
|
|
const QVector<MTPStickerPack> &packs);
|
|
|
|
void feedSetCovers(
|
|
|
|
not_null<StickersSet*> set,
|
|
|
|
const QVector<MTPDocument> &documents);
|
2021-11-19 19:04:40 +00:00
|
|
|
void newSetReceived(const MTPDmessages_stickerSet &set);
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
QString getSetTitle(const MTPDstickerSet &s);
|
|
|
|
|
2020-06-09 16:57:05 +00:00
|
|
|
RecentStickerPack &getRecentPack() const;
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool updateNeeded(crl::time lastUpdate, crl::time now) const {
|
|
|
|
constexpr auto kUpdateTimeout = crl::time(3600'000);
|
|
|
|
return (lastUpdate == 0)
|
|
|
|
|| (now >= lastUpdate + kUpdateTimeout);
|
|
|
|
}
|
2022-05-09 13:09:46 +00:00
|
|
|
void checkFavedLimit(
|
|
|
|
StickersSet &set,
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show);
|
2020-06-08 17:24:36 +00:00
|
|
|
void setIsFaved(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
2020-06-08 17:24:36 +00:00
|
|
|
not_null<DocumentData*> document,
|
|
|
|
std::optional<std::vector<not_null<EmojiPtr>>> emojiList
|
|
|
|
= std::nullopt);
|
|
|
|
void setIsNotFaved(not_null<DocumentData*> document);
|
|
|
|
void pushFavedToFront(
|
|
|
|
StickersSet &set,
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
2020-06-08 17:24:36 +00:00
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const std::vector<not_null<EmojiPtr>> &emojiList);
|
|
|
|
void moveFavedToFront(StickersSet &set, int index);
|
2022-05-09 13:09:46 +00:00
|
|
|
void requestSetToPushFaved(
|
2023-05-02 09:33:19 +00:00
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
2022-05-09 13:09:46 +00:00
|
|
|
not_null<DocumentData*> document);
|
2020-06-08 17:24:36 +00:00
|
|
|
void setPackAndEmoji(
|
|
|
|
StickersSet &set,
|
|
|
|
StickersPack &&pack,
|
|
|
|
const std::vector<TimeId> &&dates,
|
|
|
|
const QVector<MTPStickerPack> &packs);
|
2022-07-08 18:07:14 +00:00
|
|
|
void somethingReceived(
|
2022-07-19 09:31:12 +00:00
|
|
|
const QVector<MTPStickerSet> &list,
|
2021-08-25 08:15:05 +00:00
|
|
|
uint64 hash,
|
2022-07-08 17:04:31 +00:00
|
|
|
StickersType type);
|
2022-07-22 13:08:10 +00:00
|
|
|
void featuredReceived(
|
|
|
|
const MTPDmessages_featuredStickers &data,
|
|
|
|
StickersType type);
|
2020-06-08 17:24:36 +00:00
|
|
|
|
|
|
|
const not_null<Session*> _owner;
|
2022-07-26 14:45:41 +00:00
|
|
|
rpl::event_stream<StickersType> _updated;
|
|
|
|
rpl::event_stream<StickersType> _recentUpdated;
|
2020-06-08 17:24:36 +00:00
|
|
|
rpl::event_stream<> _savedGifsUpdated;
|
2021-03-29 22:28:19 +00:00
|
|
|
rpl::event_stream<uint64> _stickerSetInstalled;
|
2022-07-08 18:07:14 +00:00
|
|
|
rpl::event_stream<uint64> _emojiSetInstalled;
|
2020-06-08 17:24:36 +00:00
|
|
|
crl::time _lastUpdate = 0;
|
|
|
|
crl::time _lastRecentUpdate = 0;
|
|
|
|
crl::time _lastFavedUpdate = 0;
|
|
|
|
crl::time _lastFeaturedUpdate = 0;
|
|
|
|
crl::time _lastSavedGifsUpdate = 0;
|
2021-03-25 11:05:33 +00:00
|
|
|
crl::time _lastMasksUpdate = 0;
|
2022-07-08 17:04:31 +00:00
|
|
|
crl::time _lastEmojiUpdate = 0;
|
2022-07-22 13:08:10 +00:00
|
|
|
crl::time _lastFeaturedEmojiUpdate = 0;
|
2021-03-25 11:05:33 +00:00
|
|
|
crl::time _lastRecentAttachedUpdate = 0;
|
2020-06-08 17:24:36 +00:00
|
|
|
rpl::variable<int> _featuredSetsUnreadCount = 0;
|
|
|
|
StickersSets _sets;
|
|
|
|
StickersSetsOrder _setsOrder;
|
2021-03-25 11:05:33 +00:00
|
|
|
StickersSetsOrder _maskSetsOrder;
|
2022-07-08 17:04:31 +00:00
|
|
|
StickersSetsOrder _emojiSetsOrder;
|
2020-06-08 17:24:36 +00:00
|
|
|
StickersSetsOrder _featuredSetsOrder;
|
2022-07-22 13:08:10 +00:00
|
|
|
StickersSetsOrder _featuredEmojiSetsOrder;
|
2020-06-08 17:24:36 +00:00
|
|
|
StickersSetsOrder _archivedSetsOrder;
|
2021-03-30 15:51:45 +00:00
|
|
|
StickersSetsOrder _archivedMaskSetsOrder;
|
2020-06-08 17:24:36 +00:00
|
|
|
SavedGifs _savedGifs;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Data
|