mirror of https://github.com/procxx/kepka.git
Refactored ApiWrap.
- Joined editUploadedPhoto with editUploadedDocument.
This commit is contained in:
parent
bc03c80d8d
commit
bd653dfdff
|
@ -4610,114 +4610,82 @@ void ApiWrap::sendUploadedDocument(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::editUploadedPhoto(
|
void ApiWrap::editUploadedFile(
|
||||||
FullMsgId localId,
|
FullMsgId localId,
|
||||||
const MTPInputFile &file,
|
const MTPInputFile &file,
|
||||||
bool silent) {
|
const std::optional<MTPInputFile> &thumb,
|
||||||
if (const auto item = App::histItemById(localId)) {
|
bool silent,
|
||||||
const auto media = MTP_inputMediaUploadedPhoto(
|
bool isDocument) {
|
||||||
|
const auto item = App::histItemById(localId);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto sentEntities = TextUtilities::EntitiesToMTP(
|
||||||
|
item->originalText().entities,
|
||||||
|
TextUtilities::ConvertOption::SkipLocal);
|
||||||
|
|
||||||
|
auto flagsEditMsg = MTPmessages_EditMessage::Flag::f_message | 0;
|
||||||
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
||||||
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_entities;
|
||||||
|
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_media;
|
||||||
|
|
||||||
|
MTPinputMedia media = MTP_inputMediaEmpty();
|
||||||
|
|
||||||
|
if (isDocument) {
|
||||||
|
const auto document = item->media()->document();
|
||||||
|
if (!document) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto flags = MTPDinputMediaUploadedDocument::Flags(0)
|
||||||
|
| (thumb
|
||||||
|
? MTPDinputMediaUploadedDocument::Flag::f_thumb
|
||||||
|
: MTPDinputMediaUploadedDocument::Flag(0))
|
||||||
|
// Never edit video as gif.
|
||||||
|
| MTPDinputMediaUploadedDocument::Flag::f_nosound_video;
|
||||||
|
media = MTP_inputMediaUploadedDocument(
|
||||||
|
MTP_flags(flags),
|
||||||
|
file,
|
||||||
|
thumb ? *thumb : MTPInputFile(),
|
||||||
|
MTP_string(document->mimeString()),
|
||||||
|
ComposeSendingDocumentAttributes(document),
|
||||||
|
MTPVector<MTPInputDocument>(),
|
||||||
|
MTP_int(0));
|
||||||
|
} else {
|
||||||
|
const auto photo = item->media()->photo();
|
||||||
|
if (!photo) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
media = MTP_inputMediaUploadedPhoto(
|
||||||
MTP_flags(0),
|
MTP_flags(0),
|
||||||
file,
|
file,
|
||||||
MTPVector<MTPInputDocument>(),
|
MTPVector<MTPInputDocument>(),
|
||||||
MTP_int(0));
|
MTP_int(0));
|
||||||
|
|
||||||
auto flagsEditMsg = MTPmessages_EditMessage::Flag::f_message | 0;
|
|
||||||
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
|
||||||
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_entities;
|
|
||||||
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_media;
|
|
||||||
|
|
||||||
auto sentEntities = TextUtilities::EntitiesToMTP(
|
|
||||||
item->originalText().entities,
|
|
||||||
TextUtilities::ConvertOption::SkipLocal);
|
|
||||||
|
|
||||||
request(MTPmessages_EditMessage(
|
|
||||||
MTP_flags(flagsEditMsg),
|
|
||||||
item->history()->peer->input,
|
|
||||||
MTP_int(item->id),
|
|
||||||
MTP_string(item->originalText().text),
|
|
||||||
media,
|
|
||||||
MTPReplyMarkup(),
|
|
||||||
sentEntities
|
|
||||||
)).done([=](const MTPUpdates &result) {
|
|
||||||
item->clearSavedMedia();
|
|
||||||
item->setIsLocalUpdateMedia(true);
|
|
||||||
applyUpdates(result);
|
|
||||||
}).fail([=](const RPCError &error) {
|
|
||||||
QString err = error.type();
|
|
||||||
if (err == qstr("MESSAGE_NOT_MODIFIED")
|
|
||||||
|| err == qstr("MEDIA_NEW_INVALID")) {
|
|
||||||
item->returnSavedMedia();
|
|
||||||
_session->data().sendHistoryChangeNotifications();
|
|
||||||
} else {
|
|
||||||
sendMessageFail(error);
|
|
||||||
}
|
|
||||||
}).send();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ApiWrap::editUploadedDocument(
|
request(MTPmessages_EditMessage(
|
||||||
FullMsgId localId,
|
MTP_flags(flagsEditMsg),
|
||||||
const MTPInputFile &file,
|
item->history()->peer->input,
|
||||||
const std::optional<MTPInputFile> &thumb,
|
MTP_int(item->id),
|
||||||
bool silent) {
|
MTP_string(item->originalText().text),
|
||||||
if (const auto item = App::histItemById(localId)) {
|
media,
|
||||||
QString filename = "file";
|
MTPReplyMarkup(),
|
||||||
if (const auto document = item->media()->document()) {
|
sentEntities
|
||||||
filename = document->filename();
|
)).done([=](const MTPUpdates &result) {
|
||||||
|
item->clearSavedMedia();
|
||||||
const auto filenameAttribute = MTP_documentAttributeFilename(
|
item->setIsLocalUpdateMedia(true);
|
||||||
MTP_string(filename));
|
applyUpdates(result);
|
||||||
auto attributes = QVector<MTPDocumentAttribute>(1, filenameAttribute);
|
}).fail([=](const RPCError &error) {
|
||||||
|
QString err = error.type();
|
||||||
const auto groupId = item->groupId();
|
if (err == qstr("MESSAGE_NOT_MODIFIED")
|
||||||
const auto flags = MTPDinputMediaUploadedDocument::Flags(0)
|
|| err == qstr("MEDIA_NEW_INVALID")) {
|
||||||
| (thumb
|
item->returnSavedMedia();
|
||||||
? MTPDinputMediaUploadedDocument::Flag::f_thumb
|
_session->data().sendHistoryChangeNotifications();
|
||||||
: MTPDinputMediaUploadedDocument::Flag(0))
|
} else {
|
||||||
// Never edit video as gif.
|
sendMessageFail(error);
|
||||||
| MTPDinputMediaUploadedDocument::Flag::f_nosound_video;
|
|
||||||
const auto media = MTP_inputMediaUploadedDocument(
|
|
||||||
MTP_flags(flags),
|
|
||||||
file,
|
|
||||||
thumb ? *thumb : MTPInputFile(),
|
|
||||||
MTP_string(document->mimeString()),
|
|
||||||
ComposeSendingDocumentAttributes(document),
|
|
||||||
MTPVector<MTPInputDocument>(),
|
|
||||||
MTP_int(0));
|
|
||||||
|
|
||||||
auto flagsEditMsg = MTPmessages_EditMessage::Flag::f_message | 0;
|
|
||||||
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
|
||||||
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_entities;
|
|
||||||
flagsEditMsg |= MTPmessages_EditMessage::Flag::f_media;
|
|
||||||
|
|
||||||
auto sentEntities = TextUtilities::EntitiesToMTP(
|
|
||||||
item->originalText().entities,
|
|
||||||
TextUtilities::ConvertOption::SkipLocal);
|
|
||||||
|
|
||||||
request(MTPmessages_EditMessage(
|
|
||||||
MTP_flags(flagsEditMsg),
|
|
||||||
item->history()->peer->input,
|
|
||||||
MTP_int(item->id),
|
|
||||||
MTP_string(item->originalText().text),
|
|
||||||
media,
|
|
||||||
MTPReplyMarkup(),
|
|
||||||
sentEntities
|
|
||||||
)).done([=](const MTPUpdates &result) {
|
|
||||||
item->clearSavedMedia();
|
|
||||||
item->setIsLocalUpdateMedia(true);
|
|
||||||
applyUpdates(result);
|
|
||||||
}).fail([=](const RPCError &error) {
|
|
||||||
QString err = error.type();
|
|
||||||
if (err == qstr("MESSAGE_NOT_MODIFIED")
|
|
||||||
|| err == qstr("MEDIA_NEW_INVALID")) {
|
|
||||||
item->returnSavedMedia();
|
|
||||||
_session->data().sendHistoryChangeNotifications();
|
|
||||||
} else {
|
|
||||||
sendMessageFail(error);
|
|
||||||
}
|
|
||||||
}).send();
|
|
||||||
}
|
}
|
||||||
}
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiWrap::cancelLocalItem(not_null<HistoryItem*> item) {
|
void ApiWrap::cancelLocalItem(not_null<HistoryItem*> item) {
|
||||||
|
|
|
@ -344,15 +344,12 @@ public:
|
||||||
const MTPInputFile &file,
|
const MTPInputFile &file,
|
||||||
const std::optional<MTPInputFile> &thumb,
|
const std::optional<MTPInputFile> &thumb,
|
||||||
bool silent);
|
bool silent);
|
||||||
void editUploadedDocument(
|
void editUploadedFile(
|
||||||
FullMsgId localId,
|
FullMsgId localId,
|
||||||
const MTPInputFile &file,
|
const MTPInputFile &file,
|
||||||
const std::optional<MTPInputFile> &thumb,
|
const std::optional<MTPInputFile> &thumb,
|
||||||
bool silent);
|
bool silent,
|
||||||
void editUploadedPhoto(
|
bool isDocument);
|
||||||
FullMsgId localId,
|
|
||||||
const MTPInputFile &file,
|
|
||||||
bool silent);
|
|
||||||
|
|
||||||
void cancelLocalItem(not_null<HistoryItem*> item);
|
void cancelLocalItem(not_null<HistoryItem*> item);
|
||||||
|
|
||||||
|
|
|
@ -4421,14 +4421,14 @@ void HistoryWidget::documentEdited(
|
||||||
const FullMsgId &newId,
|
const FullMsgId &newId,
|
||||||
bool silent,
|
bool silent,
|
||||||
const MTPInputFile &file) {
|
const MTPInputFile &file) {
|
||||||
Auth().api().editUploadedDocument(newId, file, std::nullopt, silent);
|
Auth().api().editUploadedFile(newId, file, std::nullopt, silent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::photoEdited(
|
void HistoryWidget::photoEdited(
|
||||||
const FullMsgId &newId,
|
const FullMsgId &newId,
|
||||||
bool silent,
|
bool silent,
|
||||||
const MTPInputFile &file) {
|
const MTPInputFile &file) {
|
||||||
Auth().api().editUploadedPhoto(newId, file, silent);
|
Auth().api().editUploadedFile(newId, file, std::nullopt, silent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::thumbDocumentUploaded(
|
void HistoryWidget::thumbDocumentUploaded(
|
||||||
|
@ -4438,7 +4438,7 @@ void HistoryWidget::thumbDocumentUploaded(
|
||||||
const MTPInputFile &thumb,
|
const MTPInputFile &thumb,
|
||||||
bool edit) {
|
bool edit) {
|
||||||
edit
|
edit
|
||||||
? Auth().api().editUploadedDocument(newId, file, thumb, silent)
|
? Auth().api().editUploadedFile(newId, file, thumb, silent, true)
|
||||||
: Auth().api().sendUploadedDocument(newId, file, thumb, silent);
|
: Auth().api().sendUploadedDocument(newId, file, thumb, silent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue