Skip image context actions for not-loaded photos.

This commit is contained in:
John Preston 2021-02-04 19:26:49 +04:00
parent a2187a1d2b
commit 11b965e82e
2 changed files with 18 additions and 12 deletions

View file

@ -1088,12 +1088,15 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
if (lnkPhoto) { if (lnkPhoto) {
const auto photo = lnkPhoto->photo(); const auto photo = lnkPhoto->photo();
_menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { const auto media = photo->activeMediaView();
savePhotoToFile(photo); if (!photo->isNull() && media && media->loaded()) {
})); _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
_menu->addAction(tr::lng_context_copy_image(tr::now), [=] { savePhotoToFile(photo);
copyContextImage(photo); }));
}); _menu->addAction(tr::lng_context_copy_image(tr::now), [=] {
copyContextImage(photo);
});
}
if (photo->hasAttachedStickers()) { if (photo->hasAttachedStickers()) {
const auto controller = _controller; const auto controller = _controller;
auto callback = [=] { auto callback = [=] {

View file

@ -1579,12 +1579,15 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
} }
}; };
const auto addPhotoActions = [&](not_null<PhotoData*> photo) { const auto addPhotoActions = [&](not_null<PhotoData*> photo) {
_menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { const auto media = photo->activeMediaView();
savePhotoToFile(photo); if (!photo->isNull() && media && media->loaded()) {
})); _menu->addAction(tr::lng_context_save_image(tr::now), App::LambdaDelayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] {
_menu->addAction(tr::lng_context_copy_image(tr::now), [=] { savePhotoToFile(photo);
copyContextImage(photo); }));
}); _menu->addAction(tr::lng_context_copy_image(tr::now), [=] {
copyContextImage(photo);
});
}
if (photo->hasAttachedStickers()) { if (photo->hasAttachedStickers()) {
_menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] {
session->api().attachedStickers().requestAttachedStickerSets( session->api().attachedStickers().requestAttachedStickerSets(