mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 15:13:57 +02:00
Moved edit text messages from HistoryWidget to api_editing.
This commit is contained in:
parent
1c41808042
commit
63dff9ff91
3 changed files with 57 additions and 39 deletions
|
@ -192,5 +192,21 @@ mtpRequestId EditCaption(
|
||||||
return EditMessage(item, caption, SendOptions(), done, fail);
|
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
|
} // namespace Api
|
||||||
|
|
|
@ -35,4 +35,11 @@ mtpRequestId EditCaption(
|
||||||
Fn<void(const MTPUpdates &)> done,
|
Fn<void(const MTPUpdates &)> done,
|
||||||
Fn<void(const RPCError &)> fail);
|
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
|
} // namespace Api
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/history_widget.h"
|
#include "history/history_widget.h"
|
||||||
|
|
||||||
|
#include "api/api_editing.h"
|
||||||
#include "api/api_bot.h"
|
#include "api/api_bot.h"
|
||||||
#include "api/api_sending.h"
|
#include "api/api_sending.h"
|
||||||
#include "api/api_text_entities.h"
|
#include "api/api_text_entities.h"
|
||||||
|
@ -3005,7 +3006,6 @@ void HistoryWidget::saveEditMsg() {
|
||||||
if (webPageId == CancelledWebPageId) {
|
if (webPageId == CancelledWebPageId) {
|
||||||
sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
sendFlags |= MTPmessages_EditMessage::Flag::f_no_webpage;
|
||||||
}
|
}
|
||||||
auto localEntities = Api::EntitiesToMTP(&session(), sending.entities);
|
|
||||||
auto sentEntities = Api::EntitiesToMTP(
|
auto sentEntities = Api::EntitiesToMTP(
|
||||||
&session(),
|
&session(),
|
||||||
sending.entities,
|
sending.entities,
|
||||||
|
@ -3016,46 +3016,41 @@ void HistoryWidget::saveEditMsg() {
|
||||||
|
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(this);
|
||||||
const auto history = _history;
|
const auto history = _history;
|
||||||
_saveEditMsgRequestId = history->session().api().request(
|
_saveEditMsgRequestId = Api::EditTextMessage(
|
||||||
MTPmessages_EditMessage(
|
session().data().message(_channel, _editMsgId),
|
||||||
MTP_flags(sendFlags),
|
sending,
|
||||||
_history->peer->input,
|
Api::SendOptions(),
|
||||||
MTP_int(_editMsgId),
|
[history, weak](const MTPUpdates &result, mtpRequestId requestId) {
|
||||||
MTP_string(sending.text),
|
SaveEditMsgDone(history, result, requestId);
|
||||||
MTPInputMedia(),
|
if (const auto strong = weak.data()) {
|
||||||
MTPReplyMarkup(),
|
if (requestId == strong->_saveEditMsgRequestId) {
|
||||||
sentEntities,
|
strong->_saveEditMsgRequestId = 0;
|
||||||
MTP_int(0)
|
strong->cancelEdit();
|
||||||
)).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();
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}).fail([history, weak](const RPCError &error, mtpRequestId requestId) {
|
[history, weak](const RPCError &error, mtpRequestId requestId) {
|
||||||
SaveEditMsgFail(history, error, requestId);
|
SaveEditMsgFail(history, error, requestId);
|
||||||
if (const auto strong = weak.data()) {
|
if (const auto strong = weak.data()) {
|
||||||
if (requestId == strong->_saveEditMsgRequestId) {
|
if (requestId == strong->_saveEditMsgRequestId) {
|
||||||
strong->_saveEditMsgRequestId = 0;
|
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(
|
void HistoryWidget::SaveEditMsgDone(
|
||||||
|
|
Loading…
Add table
Reference in a new issue