Slightly improved box to edit caption of grouped file.

This commit is contained in:
23rd 2025-05-22 17:25:32 +03:00
parent 5ac373d4aa
commit adc1ee71a9
3 changed files with 27 additions and 8 deletions

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_document_media.h" #include "data/data_document_media.h"
#include "data/data_file_origin.h" #include "data/data_file_origin.h"
#include "data/data_groups.h"
#include "data/data_peer_values.h" #include "data/data_peer_values.h"
#include "data/data_premium_limits.h" #include "data/data_premium_limits.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -231,6 +232,7 @@ namespace {
void CaptionBox( void CaptionBox(
not_null<Ui::GenericBox*> box, not_null<Ui::GenericBox*> box,
rpl::producer<QString> confirmText, rpl::producer<QString> confirmText,
TextWithTags initialText,
not_null<PeerData*> peer, not_null<PeerData*> peer,
const SendMenu::Details &details, const SendMenu::Details &details,
Fn<void(Api::SendOptions, TextWithTags)> done) { Fn<void(Api::SendOptions, TextWithTags)> done) {
@ -249,6 +251,7 @@ void CaptionBox(
input->setFocus(); input->setFocus();
}); });
input->setTextWithTags(std::move(initialText));
input->setSubmitSettings(Core::App().settings().sendSubmitWay()); input->setSubmitSettings(Core::App().settings().sendSubmitWay());
InitMessageField(controller, input, [=](not_null<DocumentData*>) { InitMessageField(controller, input, [=](not_null<DocumentData*>) {
return true; return true;
@ -341,14 +344,14 @@ void SendGifWithCaptionBox(
not_null<DocumentData*> document, not_null<DocumentData*> document,
not_null<PeerData*> peer, not_null<PeerData*> peer,
const SendMenu::Details &details, const SendMenu::Details &details,
Fn<void(Api::SendOptions, TextWithTags)> done) { Fn<void(Api::SendOptions, TextWithTags)> c) {
box->setTitle(tr::lng_send_gif_with_caption()); box->setTitle(tr::lng_send_gif_with_caption());
[[maybe_unused]] const auto gifWidget = AddGifWidget( [[maybe_unused]] const auto gifWidget = AddGifWidget(
box->verticalLayout(), box->verticalLayout(),
document, document,
st::boxWidth); st::boxWidth);
Ui::AddSkip(box->verticalLayout()); 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( void EditCaptionBox(
@ -363,14 +366,18 @@ void EditCaptionBox(
const auto item = view->data(); const auto item = view->data();
const auto peer = item->history()->peer; const auto peer = item->history()->peer;
using namespace TextUtilities;
auto done = [=](Api::SendOptions, TextWithTags textWithTags) { auto done = [=](Api::SendOptions, TextWithTags textWithTags) {
if (item->isUploading()) { if (item->isUploading()) {
item->setText({ item->setText({
base::take(textWithTags.text), base::take(textWithTags.text),
TextUtilities::ConvertTextTagsToEntities( ConvertTextTagsToEntities(base::take(textWithTags.tags)),
base::take(textWithTags.tags)),
}); });
peer->owner().requestViewResize(view); peer->owner().requestViewResize(view);
if (item->groupId()) {
peer->owner().groups().refreshMessage(item, true);
}
box->closeBox(); box->closeBox();
} else { } else {
controller->showToast( 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 } // namespace Ui

View file

@ -84,7 +84,7 @@ void Groups::refreshMessage(
_data->requestItemViewRefresh(item); _data->requestItemViewRefresh(item);
return; return;
} }
if (!item->isRegular() && !item->isScheduled()) { if (!item->isRegular() && !item->isScheduled() && !item->isUploading()) {
return; return;
} }
const auto groupId = item->groupId(); const auto groupId = item->groupId();

View file

@ -404,12 +404,15 @@ void SendingAlbum::removeItem(not_null<HistoryItem*> item) {
Assert(i != end(items)); Assert(i != end(items));
items.erase(i); items.erase(i);
if (moveCaption) { if (moveCaption) {
const auto caption = item->originalText(); auto caption = item->originalText();
const auto firstId = items.front().msgId; const auto firstId = items.front().msgId;
if (const auto first = item->history()->owner().message(firstId)) { if (const auto first = item->history()->owner().message(firstId)) {
// We don't need to finishEdition() here, because the whole // We don't need to finishEdition() here, because the whole
// album will be rebuilt after one item was removed from it. // 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); refreshMediaCaption(first);
} }
} }