Improve topic by message resolving.

This commit is contained in:
John Preston 2022-09-27 21:47:30 +04:00
parent d7fdd80f55
commit 4724ef91f6
4 changed files with 27 additions and 30 deletions

View file

@ -189,47 +189,47 @@ void EditForumTopicBox(
title->showError(); title->showError();
return; return;
} }
const auto done = [=] {
state->titleRequestId = 0;
if (!state->iconRequestId) {
box->closeBox();
}
};
state->titleRequestId = api->request(MTPchannels_EditForumTitle( state->titleRequestId = api->request(MTPchannels_EditForumTitle(
topic->channel()->inputChannel, topic->channel()->inputChannel,
MTP_int(rootId), MTP_int(rootId),
MTP_string(title->getLastText().trimmed()) MTP_string(title->getLastText().trimmed())
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
api->applyUpdates(result); api->applyUpdates(result);
state->titleRequestId = 0; done();
if (!state->iconRequestId) {
box->closeBox();
}
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
if (error.type() == u"TOPIC_NOT_MODIFIED") { if (error.type() == u"TOPIC_NOT_MODIFIED") {
state->titleRequestId = 0; done();
if (!state->iconRequestId) { } else {
box->closeBox(); state->titleRequestId = -1;
}
return;
} }
state->titleRequestId = -1;
}).send(); }).send();
} }
if (state->iconRequestId <= 0) { if (state->iconRequestId <= 0) {
const auto done = [=] {
state->iconRequestId = 0;
if (!state->titleRequestId) {
box->closeBox();
}
};
state->iconRequestId = api->request(MTPchannels_EditForumIcon( state->iconRequestId = api->request(MTPchannels_EditForumIcon(
topic->channel()->inputChannel, topic->channel()->inputChannel,
MTP_int(rootId), MTP_int(rootId),
MTP_long(state->iconId) MTP_long(state->iconId)
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
api->applyUpdates(result); api->applyUpdates(result);
state->iconRequestId = 0; done();
if (!state->titleRequestId) {
box->closeBox();
}
}).fail([=](const MTP::Error &error) { }).fail([=](const MTP::Error &error) {
if (error.type() == u"TOPIC_NOT_MODIFIED") { if (error.type() == u"TOPIC_NOT_MODIFIED") {
state->iconRequestId = 0; done();
if (!state->titleRequestId) { } else {
box->closeBox(); state->iconRequestId = -1;
}
return;
} }
state->iconRequestId = -1;
}).send(); }).send();
} }
}; };

View file

@ -172,7 +172,8 @@ bool Forum::creating(MsgId rootId) const {
} }
ForumTopic *Forum::topicFor(not_null<HistoryItem*> item) { ForumTopic *Forum::topicFor(not_null<HistoryItem*> item) {
return topicFor(item->topicRootId()); const auto maybe = topicFor(item->replyToTop());
return maybe ? maybe : topicFor(item->topicRootId());
} }
ForumTopic *Forum::topicFor(MsgId rootId) { ForumTopic *Forum::topicFor(MsgId rootId) {

View file

@ -1134,13 +1134,9 @@ void History::newItemAdded(not_null<HistoryItem*> item) {
if (!folderKnown()) { if (!folderKnown()) {
owner().histories().requestDialogEntry(this); owner().histories().requestDialogEntry(this);
} }
if (peer->isForum()) { if (const auto forum = peer->forum()) {
if (const auto forum = peer->asChannel()->forum()) { if (const auto topic = forum->topicFor(item)) {
/*if (item->isTopicStart()) { // #TODO forum isTopicStart legacy? topic->applyItemAdded(item);
forum->topicAdded(item);
} else */if (const auto topic = forum->topicFor(item)) {
topic->applyItemAdded(item);
}
} }
} }
} }

View file

@ -809,13 +809,13 @@ void HistoryService::applyAction(const MTPMessageAction &action) {
} }
}, [&](const MTPDmessageActionTopicEditTitle &data) { }, [&](const MTPDmessageActionTopicEditTitle &data) {
if (const auto forum = history()->peer->forum()) { if (const auto forum = history()->peer->forum()) {
if (const auto topic = forum->topicFor(replyToTop())) { if (const auto topic = forum->topicFor(this)) {
topic->applyTitle(qs(data.vtitle())); topic->applyTitle(qs(data.vtitle()));
} }
} }
}, [&](const MTPDmessageActionTopicEditIcon &data) { }, [&](const MTPDmessageActionTopicEditIcon &data) {
if (const auto forum = history()->peer->forum()) { if (const auto forum = history()->peer->forum()) {
if (const auto topic = forum->topicFor(replyToTop())) { if (const auto topic = forum->topicFor(this)) {
topic->applyIconId(data.vemoji_document_id().v); topic->applyIconId(data.vemoji_document_id().v);
} }
} }