mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-23 04:13:21 +02:00
Added ability to edit caption from box even when file is uploaded.
This commit is contained in:
parent
adc1ee71a9
commit
81b432140c
4 changed files with 68 additions and 40 deletions
|
@ -4198,7 +4198,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_context_unpin_msg" = "Unpin";
|
"lng_context_unpin_msg" = "Unpin";
|
||||||
"lng_context_cancel_upload" = "Cancel Upload";
|
"lng_context_cancel_upload" = "Cancel Upload";
|
||||||
"lng_context_upload_edit_caption" = "Edit Caption";
|
"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" = "Copy Selected Text";
|
||||||
"lng_context_copy_selected_items" = "Copy Selected as Text";
|
"lng_context_copy_selected_items" = "Copy Selected as Text";
|
||||||
"lng_context_forward_selected" = "Forward Selected";
|
"lng_context_forward_selected" = "Forward Selected";
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "boxes/send_gif_with_caption_box.h"
|
#include "boxes/send_gif_with_caption_box.h"
|
||||||
|
|
||||||
|
#include "api/api_editing.h"
|
||||||
#include "base/event_filter.h"
|
#include "base/event_filter.h"
|
||||||
#include "boxes/premium_preview_box.h"
|
#include "boxes/premium_preview_box.h"
|
||||||
#include "chat_helpers/field_autocomplete.h"
|
#include "chat_helpers/field_autocomplete.h"
|
||||||
|
@ -357,34 +358,59 @@ void SendGifWithCaptionBox(
|
||||||
void EditCaptionBox(
|
void EditCaptionBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<HistoryView::Element*> view) {
|
not_null<HistoryView::Element*> 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;
|
|
||||||
|
|
||||||
using namespace TextUtilities;
|
using namespace TextUtilities;
|
||||||
|
|
||||||
auto done = [=](Api::SendOptions, TextWithTags textWithTags) {
|
box->setTitle(tr::lng_context_upload_edit_caption());
|
||||||
|
|
||||||
|
const auto data = &view->data()->history()->peer->owner();
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
FullMsgId fullId;
|
||||||
|
};
|
||||||
|
const auto state = box->lifetime().make_state<State>();
|
||||||
|
state->fullId = view->data()->fullId();
|
||||||
|
|
||||||
|
data->itemIdChanged(
|
||||||
|
) | rpl::start_with_next([=](Data::Session::IdChange event) {
|
||||||
|
if (event.oldId == state->fullId.msg) {
|
||||||
|
state->fullId = event.newId;
|
||||||
|
}
|
||||||
|
}, box->lifetime());
|
||||||
|
|
||||||
|
auto done = [=, show = box->uiShow()](
|
||||||
|
Api::SendOptions,
|
||||||
|
TextWithTags textWithTags) {
|
||||||
|
const auto item = data->message(state->fullId);
|
||||||
|
if (!item) {
|
||||||
|
show->showToast(tr::lng_message_not_found(tr::now));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(item->media() && item->media()->allowsEditCaption())) {
|
||||||
|
show->showToast(tr::lng_edit_error(tr::now));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto text = TextWithEntities{
|
||||||
|
base::take(textWithTags.text),
|
||||||
|
ConvertTextTagsToEntities(base::take(textWithTags.tags)),
|
||||||
|
};
|
||||||
if (item->isUploading()) {
|
if (item->isUploading()) {
|
||||||
item->setText({
|
item->setText(std::move(text));
|
||||||
base::take(textWithTags.text),
|
data->requestViewResize(view);
|
||||||
ConvertTextTagsToEntities(base::take(textWithTags.tags)),
|
|
||||||
});
|
|
||||||
peer->owner().requestViewResize(view);
|
|
||||||
if (item->groupId()) {
|
if (item->groupId()) {
|
||||||
peer->owner().groups().refreshMessage(item, true);
|
data->groups().refreshMessage(item, true);
|
||||||
}
|
}
|
||||||
box->closeBox();
|
box->closeBox();
|
||||||
} else {
|
} else {
|
||||||
controller->showToast(
|
Api::EditCaption(
|
||||||
tr::lng_context_upload_edit_caption_error(tr::now));
|
item,
|
||||||
|
std::move(text),
|
||||||
|
{ .invertCaption = item->invertMedia() },
|
||||||
|
[=] { box->closeBox(); },
|
||||||
|
[=](const QString &e) { box->uiShow()->showToast(e); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto item = view->data();
|
||||||
CaptionBox(
|
CaptionBox(
|
||||||
box,
|
box,
|
||||||
tr::lng_settings_save(),
|
tr::lng_settings_save(),
|
||||||
|
@ -392,7 +418,7 @@ void EditCaptionBox(
|
||||||
.text = item->originalText().text,
|
.text = item->originalText().text,
|
||||||
.tags = ConvertEntitiesToTextTags(item->originalText().entities),
|
.tags = ConvertEntitiesToTextTags(item->originalText().entities),
|
||||||
},
|
},
|
||||||
peer,
|
item->history()->peer,
|
||||||
{},
|
{},
|
||||||
std::move(done));
|
std::move(done));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2719,16 +2719,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
if (item->canDelete()) {
|
if (item->canDelete()) {
|
||||||
const auto callback = [=] { deleteItem(itemId); };
|
const auto callback = [=] { deleteItem(itemId); };
|
||||||
if (item->isUploading()) {
|
if (item->isUploading()) {
|
||||||
_menu->addAction(
|
if (item->media()
|
||||||
tr::lng_context_upload_edit_caption(tr::now),
|
&& item->media()->allowsEditCaption()) {
|
||||||
[=] {
|
_menu->addAction(
|
||||||
if (const auto view = viewByItem(item)) {
|
tr::lng_context_upload_edit_caption(tr::now),
|
||||||
controller->uiShow()->show(Box(
|
[=] { editCaptionUploadLayer(item); },
|
||||||
Ui::EditCaptionBox,
|
&st::menuIconEdit);
|
||||||
view));
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
&st::menuIconEdit);
|
|
||||||
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel);
|
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel);
|
||||||
} else {
|
} else {
|
||||||
_menu->addAction(Ui::DeleteMessageContextAction(
|
_menu->addAction(Ui::DeleteMessageContextAction(
|
||||||
|
@ -2973,16 +2970,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
||||||
deleteAsGroup(itemId);
|
deleteAsGroup(itemId);
|
||||||
};
|
};
|
||||||
if (item->isUploading()) {
|
if (item->isUploading()) {
|
||||||
_menu->addAction(
|
if (item->media()
|
||||||
tr::lng_context_upload_edit_caption(tr::now),
|
&& item->media()->allowsEditCaption()) {
|
||||||
[=] {
|
_menu->addAction(
|
||||||
if (const auto view = viewByItem(item)) {
|
tr::lng_context_upload_edit_caption(tr::now),
|
||||||
controller->uiShow()->show(Box(
|
[=] { editCaptionUploadLayer(item); },
|
||||||
Ui::EditCaptionBox,
|
&st::menuIconEdit);
|
||||||
view));
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
&st::menuIconEdit);
|
|
||||||
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel);
|
_menu->addAction(tr::lng_context_cancel_upload(tr::now), callback, &st::menuIconCancel);
|
||||||
} else {
|
} else {
|
||||||
_menu->addAction(Ui::DeleteMessageContextAction(
|
_menu->addAction(Ui::DeleteMessageContextAction(
|
||||||
|
@ -3119,6 +3113,14 @@ void HistoryInner::copySelectedText() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HistoryInner::editCaptionUploadLayer(not_null<HistoryItem*> item) {
|
||||||
|
if (const auto view = viewByItem(item)) {
|
||||||
|
if (item->isUploading()) {
|
||||||
|
_controller->uiShow()->show(Box(Ui::EditCaptionBox, view));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HistoryInner::savePhotoToFile(not_null<PhotoData*> photo) {
|
void HistoryInner::savePhotoToFile(not_null<PhotoData*> photo) {
|
||||||
const auto media = photo->activeMediaView();
|
const auto media = photo->activeMediaView();
|
||||||
if (photo->isNull() || !media || !media->loaded()) {
|
if (photo->isNull() || !media || !media->loaded()) {
|
||||||
|
|
|
@ -418,6 +418,7 @@ private:
|
||||||
void blockSenderItem(FullMsgId itemId);
|
void blockSenderItem(FullMsgId itemId);
|
||||||
void blockSenderAsGroup(FullMsgId itemId);
|
void blockSenderAsGroup(FullMsgId itemId);
|
||||||
void copySelectedText();
|
void copySelectedText();
|
||||||
|
void editCaptionUploadLayer(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
[[nodiscard]] auto reactionButtonParameters(
|
[[nodiscard]] auto reactionButtonParameters(
|
||||||
not_null<const Element*> view,
|
not_null<const Element*> view,
|
||||||
|
|
Loading…
Add table
Reference in a new issue