From 4724ef91f68b76d9e6ba06cd82b1c6fbcde66473 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 27 Sep 2022 21:47:30 +0400 Subject: [PATCH] Improve topic by message resolving. --- .../boxes/peers/edit_forum_topic_box.cpp | 40 +++++++++---------- Telegram/SourceFiles/data/data_forum.cpp | 3 +- Telegram/SourceFiles/history/history.cpp | 10 ++--- .../SourceFiles/history/history_service.cpp | 4 +- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp index 2f5a383de..0c541bee4 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_forum_topic_box.cpp @@ -189,47 +189,47 @@ void EditForumTopicBox( title->showError(); return; } + const auto done = [=] { + state->titleRequestId = 0; + if (!state->iconRequestId) { + box->closeBox(); + } + }; state->titleRequestId = api->request(MTPchannels_EditForumTitle( topic->channel()->inputChannel, MTP_int(rootId), MTP_string(title->getLastText().trimmed()) )).done([=](const MTPUpdates &result) { api->applyUpdates(result); - state->titleRequestId = 0; - if (!state->iconRequestId) { - box->closeBox(); - } + done(); }).fail([=](const MTP::Error &error) { if (error.type() == u"TOPIC_NOT_MODIFIED") { - state->titleRequestId = 0; - if (!state->iconRequestId) { - box->closeBox(); - } - return; + done(); + } else { + state->titleRequestId = -1; } - state->titleRequestId = -1; }).send(); } if (state->iconRequestId <= 0) { + const auto done = [=] { + state->iconRequestId = 0; + if (!state->titleRequestId) { + box->closeBox(); + } + }; state->iconRequestId = api->request(MTPchannels_EditForumIcon( topic->channel()->inputChannel, MTP_int(rootId), MTP_long(state->iconId) )).done([=](const MTPUpdates &result) { api->applyUpdates(result); - state->iconRequestId = 0; - if (!state->titleRequestId) { - box->closeBox(); - } + done(); }).fail([=](const MTP::Error &error) { if (error.type() == u"TOPIC_NOT_MODIFIED") { - state->iconRequestId = 0; - if (!state->titleRequestId) { - box->closeBox(); - } - return; + done(); + } else { + state->iconRequestId = -1; } - state->iconRequestId = -1; }).send(); } }; diff --git a/Telegram/SourceFiles/data/data_forum.cpp b/Telegram/SourceFiles/data/data_forum.cpp index 7d8ab9f4c..73de5760f 100644 --- a/Telegram/SourceFiles/data/data_forum.cpp +++ b/Telegram/SourceFiles/data/data_forum.cpp @@ -172,7 +172,8 @@ bool Forum::creating(MsgId rootId) const { } ForumTopic *Forum::topicFor(not_null item) { - return topicFor(item->topicRootId()); + const auto maybe = topicFor(item->replyToTop()); + return maybe ? maybe : topicFor(item->topicRootId()); } ForumTopic *Forum::topicFor(MsgId rootId) { diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index 7e3ffa121..06b68b066 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -1134,13 +1134,9 @@ void History::newItemAdded(not_null item) { if (!folderKnown()) { owner().histories().requestDialogEntry(this); } - if (peer->isForum()) { - if (const auto forum = peer->asChannel()->forum()) { - /*if (item->isTopicStart()) { // #TODO forum isTopicStart legacy? - forum->topicAdded(item); - } else */if (const auto topic = forum->topicFor(item)) { - topic->applyItemAdded(item); - } + if (const auto forum = peer->forum()) { + if (const auto topic = forum->topicFor(item)) { + topic->applyItemAdded(item); } } } diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index c568645aa..0c416cf8b 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -809,13 +809,13 @@ void HistoryService::applyAction(const MTPMessageAction &action) { } }, [&](const MTPDmessageActionTopicEditTitle &data) { 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())); } } }, [&](const MTPDmessageActionTopicEditIcon &data) { 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); } }