diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index faf3626c84..76fe0b972a 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "base/qt_signal_producer.h" #include "base/unixtime.h" +#include "boxes/edit_caption_box.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "chat_helpers/message_field.h" #include "menu/menu_send.h" @@ -29,8 +30,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_chat.h" #include "data/data_channel.h" +#include "data/data_file_origin.h" #include "data/data_forum_topic.h" #include "data/data_peer_values.h" +#include "data/data_photo_media.h" #include "data/stickers/data_stickers.h" #include "data/stickers/data_custom_emoji.h" #include "data/data_web_page.h" @@ -1939,6 +1942,12 @@ void ComposeControls::applyDraft(FieldHistoryAction fieldHistoryAction) { _header->editMessage({ _history->peer->id, draft->msgId }); _header->replyToMessage({}); } else { + _canReplaceMedia = false; + _photoEditMedia = nullptr; + if (updateReplaceMediaButton(FullMsgId())) { + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + } _header->replyToMessage({ _history->peer->id, draft->msgId }); if (_header->replyingToMessage()) { cancelForward(); @@ -2250,7 +2259,7 @@ void ComposeControls::finishAnimating() { } void ComposeControls::updateControlsGeometry(QSize size) { - // _attachToggle (_sendAs) -- _inlineResults ------ _tabbedPanel -- _fieldBarCancel + // (_attachToggle|_replaceMedia) (_sendAs) -- _inlineResults ------ _tabbedPanel -- _fieldBarCancel // (_attachDocument|_attachPhoto) _field (_ttlInfo) (_silent|_botCommandStart) _tabbedSelectorToggle _send const auto fieldWidth = size.width() @@ -2275,6 +2284,9 @@ void ComposeControls::updateControlsGeometry(QSize size) { const auto buttonsTop = size.height() - _attachToggle->height(); auto left = st::historySendRight; + if (_replaceMedia) { + _replaceMedia->moveToLeft(left, buttonsTop); + } _attachToggle->moveToLeft(left, buttonsTop); left += _attachToggle->width(); if (_sendAs) { @@ -2321,6 +2333,12 @@ void ComposeControls::updateControlsVisibility() { if (_sendAs) { _sendAs->show(); } + if (_replaceMedia) { + _replaceMedia->show(); + _attachToggle->hide(); + } else { + _attachToggle->show(); + } } bool ComposeControls::updateBotCommandShown() { @@ -2556,11 +2574,47 @@ void ComposeControls::editMessage(not_null item) { previewState)); applyDraft(); + const auto media = item->media(); + _canReplaceMedia = media && media->allowsEditMedia(); + _photoEditMedia = (_canReplaceMedia + && media->photo() + && !media->photo()->isNull()) + ? media->photo()->createMediaView() + : nullptr; + if (_photoEditMedia) { + _photoEditMedia->wanted(Data::PhotoSize::Large, item->fullId()); + } + if (updateReplaceMediaButton(item->fullId())) { + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + } + if (_autocomplete) { InvokeQueued(_autocomplete.get(), [=] { checkAutocomplete(); }); } } +bool ComposeControls::updateReplaceMediaButton(FullMsgId id) { + if (!_canReplaceMedia) { + const auto result = (_replaceMedia != nullptr); + _replaceMedia = nullptr; + return result; + } else if (_replaceMedia) { + return false; + } + _replaceMedia = std::make_unique( + _wrap.get(), + st::historyReplaceMedia); + _replaceMedia->setClickedCallback([=] { + EditCaptionBox::StartMediaReplace( + _window, + id, + _field->getTextWithTags(), + crl::guard(_wrap.get(), [=] { cancelEditMessage(); })); + }); + return true; +} + void ComposeControls::cancelEditMessage() { Expects(_history != nullptr); Expects(draftKeyCurrent() != Data::DraftKey::None()); diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index 25a92acfa4..54596dd982 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -36,6 +36,7 @@ struct MessagePosition; struct Draft; class DraftKey; enum class PreviewState : char; +class PhotoMedia; } // namespace Data namespace InlineBots { @@ -227,6 +228,7 @@ private: void updateWrappingVisibility(); void updateControlsVisibility(); void updateControlsGeometry(QSize size); + bool updateReplaceMediaButton(FullMsgId id); void updateOuterGeometry(QRect rect); void paintBackground(QRect clip); @@ -307,6 +309,7 @@ private: const std::shared_ptr _send; const not_null _attachToggle; + std::unique_ptr _replaceMedia; const not_null _tabbedSelectorToggle; const not_null _field; const not_null _botCommandStart; @@ -355,6 +358,9 @@ private: bool _isInlineBot = false; bool _botCommandShown = false; + std::shared_ptr _photoEditMedia; + bool _canReplaceMedia = false; + std::unique_ptr _preview; rpl::lifetime _uploaderSubscriptions; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 40b8913352..7bcbbd19d3 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -321,11 +321,7 @@ RepliesWidget::RepliesWidget( }) | rpl::start_with_next([=](auto fullId) { if (const auto item = session().data().message(fullId)) { const auto media = item->media(); - if (media && !media->webpage()) { - if (media->allowsEditCaption()) { - controller->show(Box(controller, item)); - } - } else { + if (!media || media->webpage() || media->allowsEditCaption()) { _composeControls->editMessage(fullId); } } @@ -1228,7 +1224,10 @@ void RepliesWidget::edit( TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) }; TextUtilities::PrepareForSending(left, prepareFlags); - if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) { + if (!TextUtilities::CutPart(sending, left, MaxMessageSize) + && (!item + || !item->media() + || !item->media()->allowsEditCaption())) { if (item) { controller()->show(Box(item, false)); } else { diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 33710b7119..bc8930e417 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -174,11 +174,7 @@ ScheduledWidget::ScheduledWidget( ) | rpl::start_with_next([=](auto fullId) { if (const auto item = session().data().message(fullId)) { const auto media = item->media(); - if (media && !media->webpage()) { - if (media->allowsEditCaption()) { - controller->show(Box(controller, item)); - } - } else { + if (!media || media->webpage() || media->allowsEditCaption()) { _composeControls->editMessage(fullId); } } @@ -664,7 +660,10 @@ void ScheduledWidget::edit( TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) }; TextUtilities::PrepareForSending(left, prepareFlags); - if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) { + if (!TextUtilities::CutPart(sending, left, MaxMessageSize) + && (!item + || !item->media() + || !item->media()->allowsEditCaption())) { if (item) { controller()->show(Box(item, false)); } else {