diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 89211b5e01..71e56d6269 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4197,6 +4197,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_pin_msg" = "Pin"; "lng_context_unpin_msg" = "Unpin"; "lng_context_cancel_upload" = "Cancel Upload"; +"lng_context_upload_edit_caption" = "Edit Caption"; +"lng_context_upload_edit_caption_error" = "Sorry, the file is already uploaded."; "lng_context_copy_selected" = "Copy Selected Text"; "lng_context_copy_selected_items" = "Copy Selected as Text"; "lng_context_forward_selected" = "Forward Selected"; diff --git a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp index 310f8fbd8e..88dc350c11 100644 --- a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp @@ -24,7 +24,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/stickers/data_custom_emoji.h" #include "data/stickers/data_stickers.h" +#include "history/history.h" +#include "history/history_item.h" #include "history/view/controls/history_view_characters_limit.h" +#include "history/view/history_view_message.h" #include "lang/lang_keys.h" #include "main/main_session.h" #include "media/clip/media_clip_reader.h" @@ -32,10 +35,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/controls/emoji_button.h" #include "ui/controls/emoji_button_factory.h" #include "ui/layers/generic_box.h" -#include "ui/widgets/fields/input_field.h" #include "ui/rect.h" +#include "ui/text/text_entity.h" #include "ui/ui_utility.h" #include "ui/vertical_list.h" +#include "ui/widgets/fields/input_field.h" #include "window/window_controller.h" #include "window/window_session_controller.h" #include "styles/style_boxes.h" @@ -224,10 +228,9 @@ namespace { return input; } -} // namespace - void CaptionBox( not_null box, + rpl::producer confirmText, not_null peer, const SendMenu::Details &details, Fn done) { @@ -310,7 +313,7 @@ void CaptionBox( done(std::move(options), input->getTextWithTags()); }; const auto confirm = box->addButton( - tr::lng_send_button(), + std::move(confirmText), [=] { send({}); }); SendMenu::SetupMenuAndShortcuts( confirm, @@ -331,6 +334,8 @@ void CaptionBox( ) | rpl::start_with_next([=] { send({}); }, input->lifetime()); } +} // namespace + void SendGifWithCaptionBox( not_null box, not_null document, @@ -343,7 +348,37 @@ void SendGifWithCaptionBox( document, st::boxWidth); Ui::AddSkip(box->verticalLayout()); - CaptionBox(box, peer, details, std::move(done)); + CaptionBox(box, tr::lng_send_button(), peer, details, std::move(done)); +} + +void EditCaptionBox( + not_null box, + not_null view) { + const auto window = Core::App().findWindow(box); + Assert(window != nullptr); + const auto controller = window->sessionController(); + Assert(controller != nullptr); + box->setTitle(tr::lng_context_upload_edit_caption()); + + const auto item = view->data(); + const auto peer = item->history()->peer; + + auto done = [=](Api::SendOptions, TextWithTags textWithTags) { + if (item->isUploading()) { + item->setText({ + base::take(textWithTags.text), + TextUtilities::ConvertTextTagsToEntities( + base::take(textWithTags.tags)), + }); + peer->owner().requestViewResize(view); + box->closeBox(); + } else { + controller->showToast( + tr::lng_context_upload_edit_caption_error(tr::now)); + } + }; + + CaptionBox(box, tr::lng_settings_save(), peer, {}, std::move(done)); } } // namespace Ui diff --git a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.h b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.h index 74f6594b59..1730c86714 100644 --- a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.h +++ b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.h @@ -18,15 +18,17 @@ namespace SendMenu { struct Details; } // namespace SendMenu +namespace HistoryView { +class Element; +} // namespace HistoryView + namespace Ui { class GenericBox; -void CaptionBox( +void EditCaptionBox( not_null box, - not_null peer, - const SendMenu::Details &details, - Fn done); + not_null view); void SendGifWithCaptionBox( not_null box, diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 1edd5850c0..4946e4929e 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_helpers.h" #include "history/view/controls/history_view_forward_panel.h" #include "history/view/controls/history_view_draft_options.h" -#include "boxes/moderate_messages_box.h" #include "history/view/media/history_view_sticker.h" #include "history/view/media/history_view_web_page.h" #include "history/view/reactions/history_view_reactions.h" @@ -54,7 +53,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/statistics/info_statistics_widget.h" #include "boxes/about_sponsored_box.h" #include "boxes/delete_messages_box.h" +#include "boxes/moderate_messages_box.h" #include "boxes/report_messages_box.h" +#include "boxes/send_gif_with_caption_box.h" #include "boxes/star_gift_box.h" // ShowStarGiftBox #include "boxes/sticker_set_box.h" #include "boxes/translate_box.h" @@ -2718,6 +2719,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (item->canDelete()) { const auto callback = [=] { deleteItem(itemId); }; if (item->isUploading()) { + _menu->addAction( + tr::lng_context_upload_edit_caption(tr::now), + [=] { + if (const auto view = viewByItem(item)) { + controller->uiShow()->show(Box( + Ui::EditCaptionBox, + view)); + } + }, + &st::menuIconEdit); _menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel); } else { _menu->addAction(Ui::DeleteMessageContextAction( @@ -2962,6 +2973,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { deleteAsGroup(itemId); }; if (item->isUploading()) { + _menu->addAction( + tr::lng_context_upload_edit_caption(tr::now), + [=] { + if (const auto view = viewByItem(item)) { + controller->uiShow()->show(Box( + Ui::EditCaptionBox, + view)); + } + }, + &st::menuIconEdit); _menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel); } else { _menu->addAction(Ui::DeleteMessageContextAction(