From 3dc73417e94179f05dfdcebfe36c614b9aaeb868 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 20 Jul 2021 18:42:05 +0300 Subject: [PATCH] Fixed some bugs in EditCaptionBox. Fixed checkbox display in some cases. Fixed editing of album items. Regression was introduced in 7e83088a84. --- .../SourceFiles/boxes/edit_caption_box.cpp | 28 +++++++++++++------ Telegram/SourceFiles/boxes/edit_caption_box.h | 7 +++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 9d8f90517..3b198bb4c 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -101,6 +101,11 @@ Ui::AlbumType ComputeAlbumType(not_null item) { return Ui::AlbumType(); } +bool CanBeCompressed(Ui::AlbumType type) { + return (type == Ui::AlbumType::None) + || (type == Ui::AlbumType::PhotoVideo); +} + } // namespace EditCaptionBox::EditCaptionBox( @@ -170,7 +175,7 @@ void EditCaptionBox::rebuildPreview() { const auto photo = media->photo(); const auto document = media->document(); if (photo || document->isVideoFile() || document->isAnimation()) { - _isPhoto = true; + _isPhoto = (photo != nullptr); const auto media = Ui::CreateChild( this, gifPaused, @@ -230,6 +235,8 @@ void EditCaptionBox::rebuildPreview() { _scroll->setOwnedWidget( object_ptr::fromRaw(_content.get())); + _previewRebuilds.fire({}); + captionResized(); } @@ -302,10 +309,11 @@ void EditCaptionBox::setupShadows() { } void EditCaptionBox::setupControls() { - auto hintLabelToggleOn = _isPhoto.value( - ) | rpl::map([=](bool value) { + auto hintLabelToggleOn = _previewRebuilds.events_starting_with( + rpl::empty_value() + ) | rpl::map([=] { return _controller->session().settings().photoEditorHintShown() - ? value + ? _isPhoto : false; }); @@ -327,9 +335,12 @@ void EditCaptionBox::setupControls() { st::defaultBoxCheckbox), st::editMediaCheckboxMargins) )->toggleOn( - _isPhoto.value( - ) | rpl::map([=](bool value) { - return value && (_albumType == Ui::AlbumType::None); + _previewRebuilds.events_starting_with( + rpl::empty_value() + ) | rpl::map([=] { + return _isPhoto + && CanBeCompressed(_albumType) + && !_preparedList.files.empty(); }), anim::type::instant )->entity()->checkedChanges( @@ -610,6 +621,7 @@ void EditCaptionBox::resizeEvent(QResizeEvent *e) { _emojiToggle->update(); if (!_controls->isHidden()) { + _controls->resizeToWidth(width()); _controls->moveToLeft( st::boxPhotoPadding.left(), bottom - _controls->heightNoMargins()); @@ -661,7 +673,7 @@ void EditCaptionBox::save() { _controller->session().api().editMedia( std::move(_preparedList), - (!_asFile && _isPhoto.current()) + (!_asFile && _isPhoto && CanBeCompressed(_albumType)) ? SendMediaType::Photo : SendMediaType::File, _field->getTextWithAppliedMarkdown(), diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.h b/Telegram/SourceFiles/boxes/edit_caption_box.h index c145f285c..02b364881 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.h +++ b/Telegram/SourceFiles/boxes/edit_caption_box.h @@ -74,14 +74,14 @@ private: const not_null _controller; const not_null _historyItem; - const bool _isAllowedEditMedia = false; + const bool _isAllowedEditMedia; const Ui::AlbumType _albumType; const base::unique_qptr _controls; const base::unique_qptr _scroll; const base::unique_qptr _field; const base::unique_qptr _emojiToggle; - const base::unique_qptr _topShadow,_bottomShadow; + const base::unique_qptr _topShadow, _bottomShadow; base::unique_qptr _content; base::unique_qptr _emojiPanel; @@ -93,15 +93,16 @@ private: mtpRequestId _saveRequestId = 0; + bool _isPhoto = false; bool _asFile = false; QString _error; - rpl::variable _isPhoto = false; rpl::variable _footerHeight = 0; rpl::event_stream<> _editMediaClicks; rpl::event_stream<> _photoEditorOpens; + rpl::event_stream<> _previewRebuilds; rpl::event_stream _contentHeight; };