mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix pasting file for media replacement.
This commit is contained in:
parent
22ca4e25d9
commit
ad3ec244e9
3 changed files with 58 additions and 0 deletions
|
@ -291,6 +291,49 @@ void EditCaptionBox::StartMediaReplace(
|
||||||
crl::guard(controller, show));
|
crl::guard(controller, show));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditCaptionBox::StartMediaReplace(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
FullMsgId itemId,
|
||||||
|
Ui::PreparedList &&list,
|
||||||
|
TextWithTags text,
|
||||||
|
Fn<void()> saved) {
|
||||||
|
const auto session = &controller->session();
|
||||||
|
const auto item = session->data().message(itemId);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto type = ComputeAlbumType(item);
|
||||||
|
const auto showError = [=](tr::phrase<> t) {
|
||||||
|
controller->showToast({ t(tr::now) });
|
||||||
|
};
|
||||||
|
const auto checkResult = [=](const Ui::PreparedList &list) {
|
||||||
|
if (list.files.size() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const auto &file = list.files.front();
|
||||||
|
const auto mime = file.information->filemime;
|
||||||
|
if (Core::IsMimeSticker(mime)) {
|
||||||
|
showError(tr::lng_edit_media_invalid_file);
|
||||||
|
return false;
|
||||||
|
} else if (type != Ui::AlbumType::None
|
||||||
|
&& !file.canBeInAlbumType(type)) {
|
||||||
|
showError(tr::lng_edit_media_album_error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
if (list.error != Ui::PreparedList::Error::None) {
|
||||||
|
showError(tr::lng_send_media_invalid_files);
|
||||||
|
} else if (checkResult(list)) {
|
||||||
|
controller->show(Box<EditCaptionBox>(
|
||||||
|
controller,
|
||||||
|
item,
|
||||||
|
std::move(text),
|
||||||
|
std::move(list),
|
||||||
|
std::move(saved)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditCaptionBox::StartPhotoEdit(
|
void EditCaptionBox::StartPhotoEdit(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
std::shared_ptr<Data::PhotoMedia> media,
|
std::shared_ptr<Data::PhotoMedia> media,
|
||||||
|
|
|
@ -50,6 +50,12 @@ public:
|
||||||
FullMsgId itemId,
|
FullMsgId itemId,
|
||||||
TextWithTags text,
|
TextWithTags text,
|
||||||
Fn<void()> saved);
|
Fn<void()> saved);
|
||||||
|
static void StartMediaReplace(
|
||||||
|
not_null<Window::SessionController*> controller,
|
||||||
|
FullMsgId itemId,
|
||||||
|
Ui::PreparedList &&list,
|
||||||
|
TextWithTags text,
|
||||||
|
Fn<void()> saved);
|
||||||
static void StartPhotoEdit(
|
static void StartPhotoEdit(
|
||||||
not_null<Window::SessionController*> controller,
|
not_null<Window::SessionController*> controller,
|
||||||
std::shared_ptr<Data::PhotoMedia> media,
|
std::shared_ptr<Data::PhotoMedia> media,
|
||||||
|
|
|
@ -5182,6 +5182,15 @@ bool HistoryWidget::confirmSendingFiles(
|
||||||
Ui::PreparedList &&list,
|
Ui::PreparedList &&list,
|
||||||
const QString &insertTextOnCancel) {
|
const QString &insertTextOnCancel) {
|
||||||
if (_editMsgId) {
|
if (_editMsgId) {
|
||||||
|
if (_canReplaceMedia) {
|
||||||
|
EditCaptionBox::StartMediaReplace(
|
||||||
|
controller(),
|
||||||
|
{ _history->peer->id, _editMsgId },
|
||||||
|
std::move(list),
|
||||||
|
_field->getTextWithTags(),
|
||||||
|
crl::guard(_list, [=] { cancelEdit(); }));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
controller()->showToast({ tr::lng_edit_caption_attach(tr::now) });
|
controller()->showToast({ tr::lng_edit_caption_attach(tr::now) });
|
||||||
return false;
|
return false;
|
||||||
} else if (showSendingFilesError(list)) {
|
} else if (showSendingFilesError(list)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue