Fix crash in attached emoji preview.

This commit is contained in:
John Preston 2022-07-27 12:26:22 +03:00
parent 4f39e723f9
commit e64190fb64
9 changed files with 53 additions and 15 deletions

View File

@ -2373,7 +2373,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
////// Cloud saved GIFs ////// Cloud saved GIFs
case mtpc_updateSavedGifs: { case mtpc_updateSavedGifs: {
session().data().stickers().setLastSavedGifsUpdate(0); session().data().stickers().setLastSavedGifsUpdate(0);
session().api().updateStickers(); session().api().updateSavedGifs();
} break; } break;
////// Cloud drafts ////// Cloud drafts

View File

@ -2526,7 +2526,10 @@ void ApiWrap::updateStickers() {
requestRecentStickers(now); requestRecentStickers(now);
requestFavedStickers(now); requestFavedStickers(now);
requestFeaturedStickers(now); requestFeaturedStickers(now);
requestFeaturedEmoji(now); }
void ApiWrap::updateSavedGifs() {
const auto now = crl::now();
requestSavedGifs(now); requestSavedGifs(now);
} }
@ -2539,6 +2542,7 @@ void ApiWrap::updateMasks() {
void ApiWrap::updateCustomEmoji() { void ApiWrap::updateCustomEmoji() {
const auto now = crl::now(); const auto now = crl::now();
requestCustomEmoji(now); requestCustomEmoji(now);
requestFeaturedEmoji(now);
} }
void ApiWrap::requestRecentStickersForce(bool attached) { void ApiWrap::requestRecentStickersForce(bool attached) {

View File

@ -232,6 +232,7 @@ public:
const Data::StickersSetsOrder &localRemoved, const Data::StickersSetsOrder &localRemoved,
Data::StickersType type); Data::StickersType type);
void updateStickers(); void updateStickers();
void updateSavedGifs();
void updateMasks(); void updateMasks();
void updateCustomEmoji(); void updateCustomEmoji();
void requestRecentStickersForce(bool attached = false); void requestRecentStickersForce(bool attached = false);

View File

@ -388,6 +388,7 @@ StickersBox::StickersBox(
controller->session().data().stickers().featuredSetsUnreadCountValue()) controller->session().data().stickers().featuredSetsUnreadCountValue())
, _section(section) , _section(section)
, _isMasks(masks) , _isMasks(masks)
, _isEmoji(false)
, _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed)) , _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed))
, _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab()) , _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab())
, _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured)) , _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured))
@ -403,6 +404,7 @@ StickersBox::StickersBox(
, _api(&controller->session().mtp()) , _api(&controller->session().mtp())
, _section(Section::Installed) , _section(Section::Installed)
, _isMasks(false) , _isMasks(false)
, _isEmoji(false)
, _installed(0, this, controller, megagroup) , _installed(0, this, controller, megagroup)
, _megagroupSet(megagroup) { , _megagroupSet(megagroup) {
_installed.widget()->scrollsToY( _installed.widget()->scrollsToY(
@ -419,6 +421,7 @@ StickersBox::StickersBox(
, _api(&controller->session().mtp()) , _api(&controller->session().mtp())
, _section(Section::Attached) , _section(Section::Attached)
, _isMasks(false) , _isMasks(false)
, _isEmoji(false)
, _attached(0, this, controller, Section::Attached) , _attached(0, this, controller, Section::Attached)
, _attachedType(Data::StickersType::Stickers) , _attachedType(Data::StickersType::Stickers)
, _attachedSets(attachedSets) { , _attachedSets(attachedSets) {
@ -432,6 +435,7 @@ StickersBox::StickersBox(
, _api(&controller->session().mtp()) , _api(&controller->session().mtp())
, _section(Section::Attached) , _section(Section::Attached)
, _isMasks(false) , _isMasks(false)
, _isEmoji(true)
, _attached(0, this, controller, Section::Attached) , _attached(0, this, controller, Section::Attached)
, _attachedType(Data::StickersType::Emoji) , _attachedType(Data::StickersType::Emoji)
, _emojiSets(emojiSets) { , _emojiSets(emojiSets) {
@ -618,13 +622,22 @@ void StickersBox::prepare() {
setInnerWidget(_tab->takeWidget(), getTopSkip()); setInnerWidget(_tab->takeWidget(), getTopSkip());
setDimensions(st::boxWideWidth, st::boxMaxListHeight); setDimensions(st::boxWideWidth, st::boxMaxListHeight);
session().data().stickers().updated( session().data().stickers().updated(_isEmoji
_isMasks ? Data::StickersType::Masks : Data::StickersType::Stickers ? Data::StickersType::Emoji
: _isMasks
? Data::StickersType::Masks
: Data::StickersType::Stickers
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
handleStickersUpdated(); handleStickersUpdated();
}, lifetime()); }, lifetime());
session().api().updateStickers();
session().api().updateMasks(); if (_isEmoji) {
session().api().updateCustomEmoji();
} else if (_isMasks) {
session().api().updateMasks();
} else {
session().api().updateStickers();
}
for (const auto &widget : { _installed.widget(), _masks.widget() }) { for (const auto &widget : { _installed.widget(), _masks.widget() }) {
if (widget) { if (widget) {
@ -1053,9 +1066,23 @@ StickersBox::Inner::Row::Row(
, removed(removed) , removed(removed)
, pixw(pixw) , pixw(pixw)
, pixh(pixh) { , pixh(pixh) {
++set->locked;
} }
StickersBox::Inner::Row::~Row() = default; StickersBox::Inner::Row::~Row() {
if (!--set->locked) {
const auto installed = !!(set->flags & SetFlag::Installed);
const auto featured = !!(set->flags & SetFlag::Featured);
const auto special = !!(set->flags & SetFlag::Special);
const auto archived = !!(set->flags & SetFlag::Archived);
if (!installed && !featured && !special && !archived) {
auto &sets = set->owner().stickers().setsRef();
if (const auto i = sets.find(set->id); i != end(sets)) {
sets.erase(i);
}
}
}
}
bool StickersBox::Inner::Row::isRecentSet() const { bool StickersBox::Inner::Row::isRecentSet() const {
return (set->id == Data::Stickers::CloudRecentSetId) return (set->id == Data::Stickers::CloudRecentSetId)

View File

@ -154,6 +154,7 @@ private:
Section _section; Section _section;
const bool _isMasks; const bool _isMasks;
const bool _isEmoji;
Tab _installed; Tab _installed;
Tab _masks; Tab _masks;

View File

@ -151,7 +151,6 @@ StickersListWidget::Set &StickersListWidget::Set::operator=(
Set &&other) = default; Set &&other) = default;
StickersListWidget::Set::~Set() = default; StickersListWidget::Set::~Set() = default;
void StickersListWidget::Sticker::ensureMediaCreated() { void StickersListWidget::Sticker::ensureMediaCreated() {
if (documentMedia) { if (documentMedia) {
return; return;

View File

@ -801,6 +801,9 @@ void TabbedSelector::showStarted() {
if (hasEmojiTab()) { if (hasEmojiTab()) {
session().api().updateCustomEmoji(); session().api().updateCustomEmoji();
} }
if (hasGifsTab()) {
session().api().updateSavedGifs();
}
currentTab()->widget()->refreshRecent(); currentTab()->widget()->refreshRecent();
currentTab()->widget()->preloadImages(); currentTab()->widget()->preloadImages();
_a_slide.stop(); _a_slide.stop();

View File

@ -334,7 +334,7 @@ void Stickers::addSavedGif(
notifySavedGifsUpdated(); notifySavedGifsUpdated();
setLastSavedGifsUpdate(0); setLastSavedGifsUpdate(0);
session->api().updateStickers(); session->api().updateSavedGifs();
} }
void Stickers::checkSavedGif(not_null<HistoryItem*> item) { void Stickers::checkSavedGif(not_null<HistoryItem*> item) {
@ -734,6 +734,7 @@ void Stickers::somethingReceived(
const auto featured = !!(set->flags & SetFlag::Featured); const auto featured = !!(set->flags & SetFlag::Featured);
const auto special = !!(set->flags & SetFlag::Special); const auto special = !!(set->flags & SetFlag::Special);
const auto archived = !!(set->flags & SetFlag::Archived); const auto archived = !!(set->flags & SetFlag::Archived);
const auto locked = (set->locked > 0);
if (!installed) { // remove not mine sets from recent stickers if (!installed) { // remove not mine sets from recent stickers
for (auto i = recent.begin(); i != recent.cend();) { for (auto i = recent.begin(); i != recent.cend();) {
if (set->stickers.indexOf(i->first) >= 0) { if (set->stickers.indexOf(i->first) >= 0) {
@ -744,7 +745,7 @@ void Stickers::somethingReceived(
} }
} }
} }
if (installed || featured || special || archived) { if (installed || featured || special || archived || locked) {
++it; ++it;
} else { } else {
it = sets.erase(it); it = sets.erase(it);
@ -1055,11 +1056,12 @@ void Stickers::featuredReceived(
auto unreadCount = 0; auto unreadCount = 0;
for (auto it = sets.begin(); it != sets.end();) { for (auto it = sets.begin(); it != sets.end();) {
const auto set = it->second.get(); const auto set = it->second.get();
bool installed = (set->flags & SetFlag::Installed); const auto installed = (set->flags & SetFlag::Installed);
bool featured = (set->flags & SetFlag::Featured); const auto featured = (set->flags & SetFlag::Featured);
bool special = (set->flags & SetFlag::Special); const auto special = (set->flags & SetFlag::Special);
bool archived = (set->flags & SetFlag::Archived); const auto archived = (set->flags & SetFlag::Archived);
if (installed || featured || special || archived) { const auto locked = (set->locked > 0);
if (installed || featured || special || archived || locked) {
if (featured && (set->flags & SetFlag::Unread)) { if (featured && (set->flags & SetFlag::Unread)) {
if (!(set->flags & SetFlag::Emoji)) { if (!(set->flags & SetFlag::Emoji)) {
++unreadCount; ++unreadCount;

View File

@ -105,6 +105,7 @@ public:
DocumentId thumbnailDocumentId = 0; DocumentId thumbnailDocumentId = 0;
QString title, shortName; QString title, shortName;
int count = 0; int count = 0;
int locked = 0;
StickersSetFlags flags; StickersSetFlags flags;
TimeId installDate = 0; TimeId installDate = 0;
StickersPack covers; StickersPack covers;