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();
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();
}
};

View file

@ -172,7 +172,8 @@ bool Forum::creating(MsgId rootId) const {
}
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) {

View file

@ -1134,13 +1134,9 @@ void History::newItemAdded(not_null<HistoryItem*> 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);
}
}
}

View file

@ -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);
}
}