Show premium stickers fake-set in the panel.

This commit is contained in:
John Preston 2022-04-28 11:44:52 +04:00
parent a079139c3b
commit af9a252b64
5 changed files with 65 additions and 0 deletions

View file

@ -1592,6 +1592,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_group_stickers" = "Group stickers"; "lng_group_stickers" = "Group stickers";
"lng_group_stickers_description" = "You can choose a sticker set which will be available for every member while in the group chat."; "lng_group_stickers_description" = "You can choose a sticker set which will be available for every member while in the group chat.";
"lng_group_stickers_add" = "Choose sticker set"; "lng_group_stickers_add" = "Choose sticker set";
"lng_premium_stickers" = "Premium stickers";
"lng_premium_unlock_button" = "Unlock Premium Stickers";
"lng_premium_unlock_about" = "Unlock this sticker and more by subscribing to Telegram Premium.";
"lng_group_about_header" = "You have created a group."; "lng_group_about_header" = "You have created a group.";
"lng_group_about_text" = "Groups can have:"; "lng_group_about_text" = "Groups can have:";

View file

@ -96,6 +96,7 @@ stickersTrendingUnread: icon {
}; };
stickersRecent: icon {{ "emoji/stickers_recent", emojiIconFg }}; stickersRecent: icon {{ "emoji/stickers_recent", emojiIconFg }};
stickersSearch: icon {{ "emoji/stickers_search", emojiIconFg }}; stickersSearch: icon {{ "emoji/stickers_search", emojiIconFg }};
stickersPremium: icon {{ "emoji/stickers_search", emojiIconFg }};
stickersSettingsUnreadSize: 6px; stickersSettingsUnreadSize: 6px;
stickersSettingsUnreadPosition: point(6px, 10px); stickersSettingsUnreadPosition: point(6px, 10px);

View file

@ -1044,6 +1044,8 @@ void StickersListWidget::Footer::paintSetIcon(
return session->data().stickers().featuredSetsUnreadCount() return session->data().stickers().featuredSetsUnreadCount()
? &st::stickersTrendingUnread ? &st::stickersTrendingUnread
: &st::stickersTrending; : &st::stickersTrending;
} else if (icon.setId == Data::Stickers::PremiumSetId) {
return &st::stickersPremium;
//} else if (setId == Stickers::FavedSetId) { //} else if (setId == Stickers::FavedSetId) {
// return &st::stickersFaved; // return &st::stickersFaved;
} }
@ -2318,6 +2320,15 @@ void StickersListWidget::paintSticker(
st::stickerPanDeleteIconFg.paint(p, xPos, width()); st::stickerPanDeleteIconFg.paint(p, xPos, width());
p.setOpacity(1.); p.setOpacity(1.);
} }
if (document->isPremiumSticker()) {
const auto point = pos
+ QPoint(
_singleSize.width() - st::stickerPanDeleteIconBg.width(),
_singleSize.height() - st::stickerPanDeleteIconBg.height());
st::stickerPanDeleteIconBg.paint(p, point, width());
st::stickerPanDeleteIconFg.paint(p, point, width());
}
} }
int StickersListWidget::stickersRight() const { int StickersListWidget::stickersRight() const {
@ -2786,13 +2797,28 @@ void StickersListWidget::refreshMySets() {
_favedStickersMap.clear(); _favedStickersMap.clear();
_mySets.reserve(defaultSetsOrder().size() + 3); _mySets.reserve(defaultSetsOrder().size() + 3);
refreshPremiumStickers();
refreshFavedStickers(); refreshFavedStickers();
refreshRecentStickers(false); refreshRecentStickers(false);
refreshMegagroupStickers(GroupStickersPlace::Visible); refreshMegagroupStickers(GroupStickersPlace::Visible);
_premiumsIndex = -1;
for (auto i = 0, count = int(_mySets.size()); i != count; ++i) {
if (_mySets[i].id == Data::Stickers::PremiumSetId) {
_premiumsIndex = i;
}
}
for (const auto setId : defaultSetsOrder()) { for (const auto setId : defaultSetsOrder()) {
const auto externalLayout = false; const auto externalLayout = false;
appendSet(_mySets, setId, externalLayout, AppendSkip::Archived); appendSet(_mySets, setId, externalLayout, AppendSkip::Archived);
} }
if (_premiumsIndex >= 0 && _mySets[_premiumsIndex].stickers.empty()) {
_mySets.erase(_mySets.begin() + _premiumsIndex);
_premiumsIndex = -1;
}
refreshMegagroupStickers(GroupStickersPlace::Hidden); refreshMegagroupStickers(GroupStickersPlace::Hidden);
takeHeavyData(_mySets, wasSets); takeHeavyData(_mySets, wasSets);
@ -2925,6 +2951,15 @@ bool StickersListWidget::appendSet(
PrepareStickers((set->stickers.empty() && externalLayout) PrepareStickers((set->stickers.empty() && externalLayout)
? set->covers ? set->covers
: set->stickers)); : set->stickers));
if (!externalLayout && _premiumsIndex >= 0) {
for (const auto &sticker : to.back().stickers) {
const auto document = sticker.document;
if (document->isPremiumSticker()) {
to[_premiumsIndex].stickers.push_back(Sticker{ document });
}
++to[_premiumsIndex].count;
}
}
return true; return true;
} }
@ -3034,6 +3069,25 @@ void StickersListWidget::refreshRecentStickers(bool performResize) {
} }
} }
void StickersListWidget::refreshPremiumStickers() {
if (_isMasks) {
return;
}
clearSelection();
const auto externalLayout = false;
const auto shortName = QString();
const auto count = 0;
_mySets.insert(_mySets.begin(), Set{
Data::Stickers::PremiumSetId,
nullptr,
(SetFlag::Official | SetFlag::Special),
tr::lng_premium_stickers(tr::now),
shortName,
count,
externalLayout
});
}
void StickersListWidget::refreshFavedStickers() { void StickersListWidget::refreshFavedStickers() {
if (_isMasks) { if (_isMasks) {
return; return;
@ -3169,6 +3223,10 @@ std::vector<StickerIcon> StickersListWidget::fillIcons() {
result.emplace_back(Data::Stickers::RecentSetId); result.emplace_back(Data::Stickers::RecentSetId);
} }
} }
if (i != _mySets.size() && _mySets[i].id == Data::Stickers::PremiumSetId) {
++i;
result.emplace_back(Data::Stickers::PremiumSetId);
}
for (auto l = _mySets.size(); i != l; ++i) { for (auto l = _mySets.size(); i != l; ++i) {
if (_mySets[i].id == Data::Stickers::MegagroupSetId) { if (_mySets[i].id == Data::Stickers::MegagroupSetId) {
result.emplace_back(Data::Stickers::MegagroupSetId); result.emplace_back(Data::Stickers::MegagroupSetId);

View file

@ -220,6 +220,7 @@ private:
bool stickerHasDeleteButton(const Set &set, int index) const; bool stickerHasDeleteButton(const Set &set, int index) const;
std::vector<Sticker> collectRecentStickers(); std::vector<Sticker> collectRecentStickers();
void refreshRecentStickers(bool resize = true); void refreshRecentStickers(bool resize = true);
void refreshPremiumStickers();
void refreshFavedStickers(); void refreshFavedStickers();
enum class GroupStickersPlace { enum class GroupStickersPlace {
Visible, Visible,
@ -341,6 +342,7 @@ private:
std::vector<Set> _mySets; std::vector<Set> _mySets;
std::vector<Set> _officialSets; std::vector<Set> _officialSets;
std::vector<Set> _searchSets; std::vector<Set> _searchSets;
int _premiumsIndex = -1;
int _featuredSetsCount = 0; int _featuredSetsCount = 0;
base::flat_set<uint64> _installedLocallySets; base::flat_set<uint64> _installedLocallySets;
std::vector<bool> _custom; std::vector<bool> _custom;

View file

@ -38,6 +38,7 @@ public:
static constexpr auto RecentSetId = 0xFFFFFFFFFFFFFFFEULL; static constexpr auto RecentSetId = 0xFFFFFFFFFFFFFFFEULL;
static constexpr auto NoneSetId = 0xFFFFFFFFFFFFFFFDULL; static constexpr auto NoneSetId = 0xFFFFFFFFFFFFFFFDULL;
static constexpr auto FeaturedSetId = 0xFFFFFFFFFFFFFFFBULL; static constexpr auto FeaturedSetId = 0xFFFFFFFFFFFFFFFBULL;
static constexpr auto PremiumSetId = 0xFFFFFFFFFFFFFFF8ULL;
// For cloud-stored recent stickers. // For cloud-stored recent stickers.
static constexpr auto CloudRecentSetId = 0xFFFFFFFFFFFFFFFCULL; static constexpr auto CloudRecentSetId = 0xFFFFFFFFFFFFFFFCULL;