mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added edit messages with uploaded file to api_editing.
This commit is contained in:
parent
bb73687fc5
commit
6c89f60679
3 changed files with 82 additions and 17 deletions
|
@ -23,10 +23,10 @@ namespace {
|
||||||
|
|
||||||
void EditMessage(
|
void EditMessage(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
std::optional<MTPInputMedia> inputMedia,
|
|
||||||
SendOptions options,
|
SendOptions options,
|
||||||
Fn<void(const MTPUpdates &, Fn<void()>)> done,
|
Fn<void(const MTPUpdates &, Fn<void()>)> done,
|
||||||
Fn<void(const RPCError &)> fail) {
|
Fn<void(const RPCError &)> fail,
|
||||||
|
std::optional<MTPInputMedia> inputMedia = std::nullopt) {
|
||||||
const auto session = &item->history()->session();
|
const auto session = &item->history()->session();
|
||||||
const auto api = &session->api();
|
const auto api = &session->api();
|
||||||
|
|
||||||
|
@ -74,6 +74,39 @@ void EditMessage(
|
||||||
).send();
|
).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditMessageWithUploadedMedia(
|
||||||
|
not_null<HistoryItem*> item,
|
||||||
|
SendOptions options,
|
||||||
|
MTPInputMedia media) {
|
||||||
|
const auto done = [=](const auto &result, Fn<void()> applyUpdates) {
|
||||||
|
if (item) {
|
||||||
|
item->clearSavedMedia();
|
||||||
|
item->setIsLocalUpdateMedia(true);
|
||||||
|
applyUpdates();
|
||||||
|
item->setIsLocalUpdateMedia(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const auto fail = [=](const RPCError &error) {
|
||||||
|
const auto err = error.type();
|
||||||
|
const auto session = &item->history()->session();
|
||||||
|
const auto notModified = (err == u"MESSAGE_NOT_MODIFIED"_q);
|
||||||
|
const auto mediaInvalid = (err == u"MEDIA_NEW_INVALID"_q);
|
||||||
|
if (notModified || mediaInvalid) {
|
||||||
|
item->returnSavedMedia();
|
||||||
|
session->data().sendHistoryChangeNotifications();
|
||||||
|
if (mediaInvalid) {
|
||||||
|
Ui::show(
|
||||||
|
Box<InformBox>(tr::lng_edit_media_invalid_file(tr::now)),
|
||||||
|
Ui::LayerOption::KeepOther);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session->api().sendMessageFail(error, item->history()->peer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
EditMessage(item, options, done, fail, media);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void RescheduleMessage(
|
void RescheduleMessage(
|
||||||
|
@ -84,7 +117,30 @@ void RescheduleMessage(
|
||||||
};
|
};
|
||||||
const auto fail = [](const RPCError &error) {};
|
const auto fail = [](const RPCError &error) {};
|
||||||
|
|
||||||
EditMessage(item, std::nullopt, options, done, fail);
|
EditMessage(item, options, done, fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditMessageWithUploadedDocument(
|
||||||
|
HistoryItem *item,
|
||||||
|
const MTPInputFile &file,
|
||||||
|
const std::optional<MTPInputFile> &thumb,
|
||||||
|
SendOptions options) {
|
||||||
|
if (!item || !item->media() || !item->media()->document()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto media = PrepareUploadedDocument(item, file, thumb);
|
||||||
|
EditMessageWithUploadedMedia(item, options, media);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditMessageWithUploadedPhoto(
|
||||||
|
HistoryItem *item,
|
||||||
|
const MTPInputFile &file,
|
||||||
|
SendOptions options) {
|
||||||
|
if (!item || !item->media() || !item->media()->photo()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto media = PrepareUploadedPhoto(file);
|
||||||
|
EditMessageWithUploadedMedia(item, options, media);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,15 @@ void RescheduleMessage(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
SendOptions options);
|
SendOptions options);
|
||||||
|
|
||||||
|
void EditMessageWithUploadedDocument(
|
||||||
|
HistoryItem *item,
|
||||||
|
const MTPInputFile &file,
|
||||||
|
const std::optional<MTPInputFile> &thumb,
|
||||||
|
SendOptions options);
|
||||||
|
|
||||||
|
void EditMessageWithUploadedPhoto(
|
||||||
|
HistoryItem *item,
|
||||||
|
const MTPInputFile &file,
|
||||||
|
SendOptions options);
|
||||||
|
|
||||||
} // namespace Api
|
} // namespace Api
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "storage/file_upload.h"
|
#include "storage/file_upload.h"
|
||||||
|
|
||||||
|
#include "api/api_editing.h"
|
||||||
#include "api/api_send_progress.h"
|
#include "api/api_send_progress.h"
|
||||||
#include "storage/localimageloader.h"
|
#include "storage/localimageloader.h"
|
||||||
#include "storage/file_download.h"
|
#include "storage/file_download.h"
|
||||||
|
@ -156,15 +157,12 @@ Uploader::Uploader(not_null<ApiWrap*> api)
|
||||||
stopSessionsTimer.setSingleShot(true);
|
stopSessionsTimer.setSingleShot(true);
|
||||||
connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions()));
|
connect(&stopSessionsTimer, SIGNAL(timeout()), this, SLOT(stopSessions()));
|
||||||
|
|
||||||
|
const auto session = &_api->session();
|
||||||
photoReady(
|
photoReady(
|
||||||
) | rpl::start_with_next([=](const UploadedPhoto &data) {
|
) | rpl::start_with_next([=](const UploadedPhoto &data) {
|
||||||
if (data.edit) {
|
if (data.edit) {
|
||||||
_api->editUploadedFile(
|
const auto item = session->data().message(data.fullId);
|
||||||
data.fullId,
|
Api::EditMessageWithUploadedPhoto(item, data.file, data.options);
|
||||||
data.file,
|
|
||||||
std::nullopt,
|
|
||||||
data.options,
|
|
||||||
false);
|
|
||||||
} else {
|
} else {
|
||||||
_api->sendUploadedPhoto(
|
_api->sendUploadedPhoto(
|
||||||
data.fullId,
|
data.fullId,
|
||||||
|
@ -176,12 +174,12 @@ Uploader::Uploader(not_null<ApiWrap*> api)
|
||||||
documentReady(
|
documentReady(
|
||||||
) | rpl::start_with_next([=](const UploadedDocument &data) {
|
) | rpl::start_with_next([=](const UploadedDocument &data) {
|
||||||
if (data.edit) {
|
if (data.edit) {
|
||||||
_api->editUploadedFile(
|
const auto item = session->data().message(data.fullId);
|
||||||
data.fullId,
|
Api::EditMessageWithUploadedDocument(
|
||||||
|
item,
|
||||||
data.file,
|
data.file,
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
data.options,
|
data.options);
|
||||||
true);
|
|
||||||
} else {
|
} else {
|
||||||
_api->sendUploadedDocument(
|
_api->sendUploadedDocument(
|
||||||
data.fullId,
|
data.fullId,
|
||||||
|
@ -194,12 +192,12 @@ Uploader::Uploader(not_null<ApiWrap*> api)
|
||||||
thumbDocumentReady(
|
thumbDocumentReady(
|
||||||
) | rpl::start_with_next([=](const UploadedThumbDocument &data) {
|
) | rpl::start_with_next([=](const UploadedThumbDocument &data) {
|
||||||
if (data.edit) {
|
if (data.edit) {
|
||||||
_api->editUploadedFile(
|
const auto item = session->data().message(data.fullId);
|
||||||
data.fullId,
|
Api::EditMessageWithUploadedDocument(
|
||||||
|
item,
|
||||||
data.file,
|
data.file,
|
||||||
data.thumb,
|
data.thumb,
|
||||||
data.options,
|
data.options);
|
||||||
true);
|
|
||||||
} else {
|
} else {
|
||||||
_api->sendUploadedDocument(
|
_api->sendUploadedDocument(
|
||||||
data.fullId,
|
data.fullId,
|
||||||
|
|
Loading…
Add table
Reference in a new issue