Support editing of not-fully-created topic.

This commit is contained in:
John Preston 2022-10-04 21:02:03 +04:00
parent 3722e55b67
commit 5d43073efa

View file

@ -157,8 +157,9 @@ void EditForumTopicBox(
}; };
const auto save = [=] { const auto save = [=] {
const auto topic = forum->peer->forum() const auto parent = forum->peer->forum();
? forum->peer->forum()->topicFor(rootId) const auto topic = parent
? parent->topicFor(rootId)
: nullptr; : nullptr;
if (!topic) { if (!topic) {
box->closeBox(); box->closeBox();
@ -169,29 +170,35 @@ void EditForumTopicBox(
if (title->getLastText().trimmed().isEmpty()) { if (title->getLastText().trimmed().isEmpty()) {
title->showError(); title->showError();
return; return;
} } else if (parent->creating(rootId)) {
const auto done = [=] { topic->applyTitle(title->getLastText().trimmed());
state->titleRequestId = 0; } else {
if (!state->iconRequestId) { const auto done = [=] {
box->closeBox(); state->titleRequestId = 0;
} if (!state->iconRequestId) {
}; box->closeBox();
state->titleRequestId = api->request(MTPchannels_EditForumTitle( }
topic->channel()->inputChannel, };
MTP_int(rootId), state->titleRequestId = api->request(MTPchannels_EditForumTitle(
MTP_string(title->getLastText().trimmed()) topic->channel()->inputChannel,
)).done([=](const MTPUpdates &result) { MTP_int(rootId),
api->applyUpdates(result); MTP_string(title->getLastText().trimmed())
done(); )).done([=](const MTPUpdates &result) {
}).fail([=](const MTP::Error &error) { api->applyUpdates(result);
if (error.type() == u"TOPIC_NOT_MODIFIED") {
done(); done();
} else { }).fail([=](const MTP::Error &error) {
state->titleRequestId = -1; if (error.type() == u"TOPIC_NOT_MODIFIED") {
} done();
}).send(); } else {
state->titleRequestId = -1;
}
}).send();
}
} }
if (state->iconRequestId <= 0) { if (parent->creating(rootId)) {
topic->applyIconId(state->iconId);
box->closeBox();
} else if (state->iconRequestId <= 0) {
const auto done = [=] { const auto done = [=] {
state->iconRequestId = 0; state->iconRequestId = 0;
if (!state->titleRequestId) { if (!state->titleRequestId) {