From adc1ee71a9b1bc9549deb2c6aa6252ea149591ce Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 22 May 2025 17:25:32 +0300 Subject: [PATCH] Slightly improved box to edit caption of grouped file. --- .../boxes/send_gif_with_caption_box.cpp | 26 +++++++++++++++---- Telegram/SourceFiles/data/data_groups.cpp | 2 +- .../SourceFiles/storage/localimageloader.cpp | 7 +++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp index 88dc350c11..1eaf9f6c4f 100644 --- a/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/send_gif_with_caption_box.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_document.h" #include "data/data_document_media.h" #include "data/data_file_origin.h" +#include "data/data_groups.h" #include "data/data_peer_values.h" #include "data/data_premium_limits.h" #include "data/data_session.h" @@ -231,6 +232,7 @@ namespace { void CaptionBox( not_null box, rpl::producer confirmText, + TextWithTags initialText, not_null peer, const SendMenu::Details &details, Fn done) { @@ -249,6 +251,7 @@ void CaptionBox( input->setFocus(); }); + input->setTextWithTags(std::move(initialText)); input->setSubmitSettings(Core::App().settings().sendSubmitWay()); InitMessageField(controller, input, [=](not_null) { return true; @@ -341,14 +344,14 @@ void SendGifWithCaptionBox( not_null document, not_null peer, const SendMenu::Details &details, - Fn done) { + Fn c) { box->setTitle(tr::lng_send_gif_with_caption()); [[maybe_unused]] const auto gifWidget = AddGifWidget( box->verticalLayout(), document, st::boxWidth); Ui::AddSkip(box->verticalLayout()); - CaptionBox(box, tr::lng_send_button(), peer, details, std::move(done)); + CaptionBox(box, tr::lng_send_button(), {}, peer, details, std::move(c)); } void EditCaptionBox( @@ -363,14 +366,18 @@ void EditCaptionBox( const auto item = view->data(); const auto peer = item->history()->peer; + using namespace TextUtilities; + auto done = [=](Api::SendOptions, TextWithTags textWithTags) { if (item->isUploading()) { item->setText({ base::take(textWithTags.text), - TextUtilities::ConvertTextTagsToEntities( - base::take(textWithTags.tags)), + ConvertTextTagsToEntities(base::take(textWithTags.tags)), }); peer->owner().requestViewResize(view); + if (item->groupId()) { + peer->owner().groups().refreshMessage(item, true); + } box->closeBox(); } else { controller->showToast( @@ -378,7 +385,16 @@ void EditCaptionBox( } }; - CaptionBox(box, tr::lng_settings_save(), peer, {}, std::move(done)); + CaptionBox( + box, + tr::lng_settings_save(), + TextWithTags{ + .text = item->originalText().text, + .tags = ConvertEntitiesToTextTags(item->originalText().entities), + }, + peer, + {}, + std::move(done)); } } // namespace Ui diff --git a/Telegram/SourceFiles/data/data_groups.cpp b/Telegram/SourceFiles/data/data_groups.cpp index 15bb0d820e..7af7050f14 100644 --- a/Telegram/SourceFiles/data/data_groups.cpp +++ b/Telegram/SourceFiles/data/data_groups.cpp @@ -84,7 +84,7 @@ void Groups::refreshMessage( _data->requestItemViewRefresh(item); return; } - if (!item->isRegular() && !item->isScheduled()) { + if (!item->isRegular() && !item->isScheduled() && !item->isUploading()) { return; } const auto groupId = item->groupId(); diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 476a1521b9..8603cd7c30 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -404,12 +404,15 @@ void SendingAlbum::removeItem(not_null item) { Assert(i != end(items)); items.erase(i); if (moveCaption) { - const auto caption = item->originalText(); + auto caption = item->originalText(); const auto firstId = items.front().msgId; if (const auto first = item->history()->owner().message(firstId)) { // We don't need to finishEdition() here, because the whole // album will be rebuilt after one item was removed from it. - first->setText(caption); + auto firstCaption = first->originalText(); + first->setText(firstCaption.text.isEmpty() + ? std::move(caption) + : firstCaption.append('\n').append(std::move(caption))); refreshMediaCaption(first); } }