Moved edit text messages from HistoryWidget to api_editing.

This commit is contained in:
23rd 2020-05-30 02:08:31 +03:00
parent 1c41808042
commit 63dff9ff91
3 changed files with 57 additions and 39 deletions

View File

@ -192,5 +192,21 @@ mtpRequestId EditCaption(
return EditMessage(item, caption, SendOptions(), done, fail);
}
mtpRequestId EditTextMessage(
not_null<HistoryItem*> item,
const TextWithEntities &caption,
SendOptions options,
Fn<void(const MTPUpdates &, mtpRequestId requestId)> done,
Fn<void(const RPCError &, mtpRequestId requestId)> fail) {
const auto callback = [=](
const auto &result,
Fn<void()> applyUpdates,
auto id) {
applyUpdates();
done(result, id);
};
return EditMessage(item, caption, options, callback, fail);
}
} // namespace Api

View File

@ -35,4 +35,11 @@ mtpRequestId EditCaption(
Fn<void(const MTPUpdates &)> done,
Fn<void(const RPCError &)> fail);
mtpRequestId EditTextMessage(
not_null<HistoryItem*> item,
const TextWithEntities &caption,
SendOptions options,
Fn<void(const MTPUpdates &, mtpRequestId requestId)> done,
Fn<void(const RPCError &, mtpRequestId requestId)> fail);
} // namespace Api

View File

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/history_widget.h"
#include "api/api_editing.h"
#include "api/api_bot.h"
#include "api/api_sending.h"
#include "api/api_text_entities.h"
@ -3005,7 +3006,6 @@ void HistoryWidget::saveEditMsg() {
if (webPageId == CancelledWebPageId) {
sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage;
}
auto localEntities = Api::EntitiesToMTP(&session(), sending.entities);
auto sentEntities = Api::EntitiesToMTP(
&session(),
sending.entities,
@ -3016,46 +3016,41 @@ void HistoryWidget::saveEditMsg() {
const auto weak = Ui::MakeWeak(this);
const auto history = _history;
_saveEditMsgRequestId = history->session().api().request(
MTPmessages_EditMessage(
MTP_flags(sendFlags),
_history->peer->input,
MTP_int(_editMsgId),
MTP_string(sending.text),
MTPInputMedia(),
MTPReplyMarkup(),
sentEntities,
MTP_int(0)
)).done([history, weak](const MTPUpdates &result, mtpRequestId requestId) {
SaveEditMsgDone(history, result, requestId);
if (const auto strong = weak.data()) {
if (requestId == strong->_saveEditMsgRequestId) {
strong->_saveEditMsgRequestId = 0;
strong->cancelEdit();
_saveEditMsgRequestId = Api::EditTextMessage(
session().data().message(_channel, _editMsgId),
sending,
Api::SendOptions(),
[history, weak](const MTPUpdates &result, mtpRequestId requestId) {
SaveEditMsgDone(history, result, requestId);
if (const auto strong = weak.data()) {
if (requestId == strong->_saveEditMsgRequestId) {
strong->_saveEditMsgRequestId = 0;
strong->cancelEdit();
}
}
}
}).fail([history, weak](const RPCError &error, mtpRequestId requestId) {
SaveEditMsgFail(history, error, requestId);
if (const auto strong = weak.data()) {
if (requestId == strong->_saveEditMsgRequestId) {
strong->_saveEditMsgRequestId = 0;
},
[history, weak](const RPCError &error, mtpRequestId requestId) {
SaveEditMsgFail(history, error, requestId);
if (const auto strong = weak.data()) {
if (requestId == strong->_saveEditMsgRequestId) {
strong->_saveEditMsgRequestId = 0;
}
const auto &err = error.type();
if (err == qstr("MESSAGE_ID_INVALID")
|| err == qstr("CHAT_ADMIN_REQUIRED")
|| err == qstr("MESSAGE_EDIT_TIME_EXPIRED")) {
Ui::show(Box<InformBox>(tr::lng_edit_error(tr::now)));
} else if (err == qstr("MESSAGE_NOT_MODIFIED")) {
strong->cancelEdit();
} else if (err == qstr("MESSAGE_EMPTY")) {
strong->_field->selectAll();
strong->_field->setFocus();
} else {
Ui::show(Box<InformBox>(tr::lng_edit_error(tr::now)));
}
strong->update();
}
const auto &err = error.type();
if (err == qstr("MESSAGE_ID_INVALID")
|| err == qstr("CHAT_ADMIN_REQUIRED")
|| err == qstr("MESSAGE_EDIT_TIME_EXPIRED")) {
Ui::show(Box<InformBox>(tr::lng_edit_error(tr::now)));
} else if (err == qstr("MESSAGE_NOT_MODIFIED")) {
strong->cancelEdit();
} else if (err == qstr("MESSAGE_EMPTY")) {
strong->_field->selectAll();
strong->_field->setFocus();
} else {
Ui::show(Box<InformBox>(tr::lng_edit_error(tr::now)));
}
strong->update();
}
}).send();
});
}
void HistoryWidget::SaveEditMsgDone(