mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-23 01:27:15 +02:00
Moved HistoryWidget::saveEditMsgDone/Fail to lambdas.
This commit is contained in:
parent
c52da743fd
commit
b02b690747
4 changed files with 54 additions and 70 deletions
|
@ -14,6 +14,12 @@ namespace Api {
|
||||||
|
|
||||||
struct SendOptions;
|
struct SendOptions;
|
||||||
|
|
||||||
|
const auto kDefaultEditMessagesErrors = {
|
||||||
|
u"MESSAGE_ID_INVALID"_q,
|
||||||
|
u"CHAT_ADMIN_REQUIRED"_q,
|
||||||
|
u"MESSAGE_EDIT_TIME_EXPIRED"_q,
|
||||||
|
};
|
||||||
|
|
||||||
void RescheduleMessage(
|
void RescheduleMessage(
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
SendOptions options);
|
SendOptions options);
|
||||||
|
|
|
@ -953,15 +953,9 @@ void EditCaptionBox::save() {
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto fail = crl::guard(this, [=](const RPCError &error) {
|
const auto fail = crl::guard(this, [=](const RPCError &error) {
|
||||||
const auto defaultErrors = {
|
|
||||||
u"MESSAGE_ID_INVALID"_q,
|
|
||||||
u"CHAT_ADMIN_REQUIRED"_q,
|
|
||||||
u"MESSAGE_EDIT_TIME_EXPIRED"_q,
|
|
||||||
};
|
|
||||||
|
|
||||||
_saveRequestId = 0;
|
_saveRequestId = 0;
|
||||||
const auto &type = error.type();
|
const auto &type = error.type();
|
||||||
if (ranges::contains(defaultErrors, type)) {
|
if (ranges::contains(Api::kDefaultEditMessagesErrors, type)) {
|
||||||
_error = tr::lng_edit_error(tr::now);
|
_error = tr::lng_edit_error(tr::now);
|
||||||
update();
|
update();
|
||||||
} else if (type == u"MESSAGE_NOT_MODIFIED"_q) {
|
} else if (type == u"MESSAGE_NOT_MODIFIED"_q) {
|
||||||
|
|
|
@ -2988,8 +2988,9 @@ void HistoryWidget::saveEditMsg() {
|
||||||
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) };
|
TextUtilities::ConvertTextTagsToEntities(textWithTags.tags) };
|
||||||
TextUtilities::PrepareForSending(left, prepareFlags);
|
TextUtilities::PrepareForSending(left, prepareFlags);
|
||||||
|
|
||||||
|
const auto item = session().data().message(_channel, _editMsgId);
|
||||||
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
if (!TextUtilities::CutPart(sending, left, MaxMessageSize)) {
|
||||||
if (const auto item = session().data().message(_channel, _editMsgId)) {
|
if (item) {
|
||||||
const auto suggestModerateActions = false;
|
const auto suggestModerateActions = false;
|
||||||
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
Ui::show(Box<DeleteMessagesBox>(item, suggestModerateActions));
|
||||||
} else {
|
} else {
|
||||||
|
@ -3002,70 +3003,55 @@ void HistoryWidget::saveEditMsg() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto options = Api::SendOptions();
|
|
||||||
options.removeWebPageId = (webPageId == CancelledWebPageId);
|
|
||||||
|
|
||||||
const auto weak = Ui::MakeWeak(this);
|
const auto weak = Ui::MakeWeak(this);
|
||||||
const auto history = _history;
|
const auto history = _history;
|
||||||
_saveEditMsgRequestId = Api::EditTextMessage(
|
|
||||||
session().data().message(_channel, _editMsgId),
|
|
||||||
sending,
|
|
||||||
options,
|
|
||||||
[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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryWidget::SaveEditMsgDone(
|
const auto done = [=](const MTPUpdates &result, mtpRequestId requestId) {
|
||||||
not_null<History*> history,
|
crl::guard(weak, [=] {
|
||||||
const MTPUpdates &updates,
|
if (requestId == _saveEditMsgRequestId) {
|
||||||
mtpRequestId requestId) {
|
_saveEditMsgRequestId = 0;
|
||||||
history->session().api().applyUpdates(updates);
|
cancelEdit();
|
||||||
|
}
|
||||||
|
})();
|
||||||
if (auto editDraft = history->editDraft()) {
|
if (auto editDraft = history->editDraft()) {
|
||||||
if (editDraft->saveRequestId == requestId) {
|
if (editDraft->saveRequestId == requestId) {
|
||||||
history->clearEditDraft();
|
history->clearEditDraft();
|
||||||
history->session().local().writeDrafts(history);
|
history->session().local().writeDrafts(history);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
void HistoryWidget::SaveEditMsgFail(
|
const auto fail = [=](const RPCError &error, mtpRequestId requestId) {
|
||||||
not_null<History*> history,
|
if (const auto editDraft = history->editDraft()) {
|
||||||
const RPCError &error,
|
|
||||||
mtpRequestId requestId) {
|
|
||||||
if (auto editDraft = history->editDraft()) {
|
|
||||||
if (editDraft->saveRequestId == requestId) {
|
if (editDraft->saveRequestId == requestId) {
|
||||||
editDraft->saveRequestId = 0;
|
editDraft->saveRequestId = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
crl::guard(weak, [=] {
|
||||||
|
if (requestId == _saveEditMsgRequestId) {
|
||||||
|
_saveEditMsgRequestId = 0;
|
||||||
|
}
|
||||||
|
const auto &err = error.type();
|
||||||
|
if (ranges::contains(Api::kDefaultEditMessagesErrors, err)) {
|
||||||
|
Ui::show(Box<InformBox>(tr::lng_edit_error(tr::now)));
|
||||||
|
} else if (err == u"MESSAGE_NOT_MODIFIED"_q) {
|
||||||
|
cancelEdit();
|
||||||
|
} else if (err == u"MESSAGE_EMPTY"_q) {
|
||||||
|
_field->selectAll();
|
||||||
|
_field->setFocus();
|
||||||
|
} else {
|
||||||
|
Ui::show(Box<InformBox>(tr::lng_edit_error(tr::now)));
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
|
||||||
|
_saveEditMsgRequestId = Api::EditTextMessage(
|
||||||
|
item,
|
||||||
|
sending,
|
||||||
|
{ .removeWebPageId = (webPageId == CancelledWebPageId) },
|
||||||
|
done,
|
||||||
|
fail);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::hideSelectorControlsAnimated() {
|
void HistoryWidget::hideSelectorControlsAnimated() {
|
||||||
|
|
|
@ -525,8 +525,6 @@ private:
|
||||||
void createUnreadBarAndResize();
|
void createUnreadBarAndResize();
|
||||||
|
|
||||||
void saveEditMsg();
|
void saveEditMsg();
|
||||||
static void SaveEditMsgDone(not_null<History*> history, const MTPUpdates &updates, mtpRequestId requestId);
|
|
||||||
static void SaveEditMsgFail(not_null<History*> history, const RPCError &error, mtpRequestId requestId);
|
|
||||||
|
|
||||||
void checkPreview();
|
void checkPreview();
|
||||||
void requestPreview();
|
void requestPreview();
|
||||||
|
|
Loading…
Add table
Reference in a new issue