2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Apply short topic info from channelMessages.

This commit is contained in:
John Preston
2022-11-08 15:36:46 +04:00
parent 983b6af0b4
commit c7741cb62a
17 changed files with 121 additions and 74 deletions

View File

@@ -83,7 +83,6 @@ std::unique_ptr<Data::Forum> MegagroupInfo::takeForumData() {
return result;
}
return nullptr;
}
ChannelData::ChannelData(not_null<Data::Session*> owner, PeerId id)
@@ -876,6 +875,12 @@ const Data::AllowedReactions &ChannelData::allowedReactions() const {
return _allowedReactions;
}
void ChannelData::processTopics(const MTPVector<MTPForumTopic> &topics) {
if (const auto forum = this->forum()) {
forum->applyReceivedTopics(topics);
}
}
namespace Data {
void ApplyMigration(

View File

@@ -437,6 +437,8 @@ public:
return mgInfo ? mgInfo->forum() : nullptr;
}
void processTopics(const MTPVector<MTPForumTopic> &topics);
// Still public data members.
uint64 access = 0;

View File

@@ -204,7 +204,16 @@ void Forum::applyReceivedTopics(
owner().processChats(data.vchats());
owner().processMessages(data.vmessages(), NewMessageType::Existing);
channel()->ptsReceived(data.vpts().v);
const auto &list = data.vtopics().v;
applyReceivedTopics(data.vtopics(), std::move(callback));
if (!_staleRootIds.empty()) {
requestSomeStale();
}
}
void Forum::applyReceivedTopics(
const MTPVector<MTPForumTopic> &topics,
Fn<void(not_null<ForumTopic*>)> callback) {
const auto &list = topics.v;
for (const auto &topic : list) {
const auto rootId = topic.match([&](const auto &data) {
return data.vid().v;
@@ -235,9 +244,6 @@ void Forum::applyReceivedTopics(
}
});
}
if (!_staleRootIds.empty()) {
requestSomeStale();
}
}
void Forum::requestSomeStale() {

View File

@@ -74,6 +74,9 @@ public:
void applyReceivedTopics(
const MTPmessages_ForumTopics &topics,
Fn<void(not_null<ForumTopic*>)> callback = nullptr);
void applyReceivedTopics(
const MTPVector<MTPForumTopic> &topics,
Fn<void(not_null<ForumTopic*>)> callback = nullptr);
[[nodiscard]] MsgId reserveCreatingId(
const QString &title,

View File

@@ -296,6 +296,8 @@ void ForumTopic::readTillEnd() {
void ForumTopic::applyTopic(const MTPDforumTopic &data) {
Expects(_rootId == data.vid().v);
const auto min = data.is_short();
applyCreator(peerFromMTP(data.vfrom_id()));
applyCreationDate(data.vdate().v);
@@ -307,32 +309,38 @@ void ForumTopic::applyTopic(const MTPDforumTopic &data) {
}
applyColorId(data.vicon_color().v);
if (data.is_pinned()) {
owner().setChatPinned(this, 0, true);
} else {
_list->pinned()->setPinned(this, false);
}
owner().notifySettings().apply(this, data.vnotify_settings());
const auto draft = data.vdraft();
if (draft && draft->type() == mtpc_draftMessage) {
Data::ApplyPeerCloudDraft(
&session(),
channel()->id,
_rootId,
draft->c_draftMessage());
}
applyIsMy(data.is_my());
setClosed(data.is_closed());
_replies->setInboxReadTill(
data.vread_inbox_max_id().v,
data.vunread_count().v);
_replies->setOutboxReadTill(data.vread_outbox_max_id().v);
applyTopicTopMessage(data.vtop_message().v);
unreadMentions().setCount(data.vunread_mentions_count().v);
unreadReactions().setCount(data.vunread_reactions_count().v);
if (min) {
int a = 0;
} else {
if (data.is_pinned()) {
owner().setChatPinned(this, 0, true);
} else {
_list->pinned()->setPinned(this, false);
}
owner().notifySettings().apply(this, data.vnotify_settings());
if (const auto draft = data.vdraft()) {
draft->match([&](const MTPDdraftMessage &data) {
Data::ApplyPeerCloudDraft(
&session(),
channel()->id,
_rootId,
data);
}, [](const MTPDdraftMessageEmpty&) {});
}
_replies->setInboxReadTill(
data.vread_inbox_max_id().v,
data.vunread_count().v);
_replies->setOutboxReadTill(data.vread_outbox_max_id().v);
applyTopicTopMessage(data.vtop_message().v);
unreadMentions().setCount(data.vunread_mentions_count().v);
unreadReactions().setCount(data.vunread_reactions_count().v);
}
}
void ForumTopic::applyCreator(PeerId creatorId) {

View File

@@ -661,25 +661,6 @@ void RepliesList::loadAfter() {
bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
const auto guard = gsl::finally([&] { _listChanges.fire({}); });
const auto fullCount = result.match([&](
const MTPDmessages_messagesNotModified &) {
LOG(("API Error: received messages.messagesNotModified! "
"(HistoryWidget::messagesReceived)"));
return 0;
}, [&](const MTPDmessages_messages &data) {
return int(data.vmessages().v.size());
}, [&](const MTPDmessages_messagesSlice &data) {
return data.vcount().v;
}, [&](const MTPDmessages_channelMessages &data) {
if (_history->peer->isChannel()) {
_history->peer->asChannel()->ptsReceived(data.vpts().v);
} else {
LOG(("API Error: received messages.channelMessages when "
"no channel was passed! (HistoryWidget::messagesReceived)"));
}
return data.vcount().v;
});
auto &owner = _history->owner();
const auto list = result.match([&](
const MTPDmessages_messagesNotModified &) {
@@ -691,6 +672,27 @@ bool RepliesList::processMessagesIsEmpty(const MTPmessages_Messages &result) {
owner.processChats(data.vchats());
return data.vmessages().v;
});
const auto fullCount = result.match([&](
const MTPDmessages_messagesNotModified &) {
LOG(("API Error: received messages.messagesNotModified! "
"(HistoryWidget::messagesReceived)"));
return 0;
}, [&](const MTPDmessages_messages &data) {
return int(data.vmessages().v.size());
}, [&](const MTPDmessages_messagesSlice &data) {
return data.vcount().v;
}, [&](const MTPDmessages_channelMessages &data) {
if (const auto channel = _history->peer->asChannel()) {
channel->ptsReceived(data.vpts().v);
channel->processTopics(data.vtopics());
} else {
LOG(("API Error: received messages.channelMessages when "
"no channel was passed! (HistoryWidget::messagesReceived)"));
}
return data.vcount().v;
});
if (list.isEmpty()) {
return true;
}

View File

@@ -137,9 +137,10 @@ SearchResult ParseSearchResult(
} break;
case mtpc_messages_channelMessages: {
auto &d = data.c_messages_channelMessages();
if (auto channel = peer->asChannel()) {
const auto &d = data.c_messages_channelMessages();
if (const auto channel = peer->asChannel()) {
channel->ptsReceived(d.vpts().v);
channel->processTopics(d.vtopics());
} else {
LOG(("API Error: received messages.channelMessages when "
"no channel was passed! (ParseSearchResult)"));

View File

@@ -2155,6 +2155,7 @@ void Session::processExistingMessages(
data.match([&](const MTPDmessages_channelMessages &data) {
if (channel) {
channel->ptsReceived(data.vpts().v);
channel->processTopics(data.vtopics());
} else {
LOG(("App Error: received messages.channelMessages!"));
}

View File

@@ -295,6 +295,7 @@ void WebPageData::ApplyChanges(
const MTPDmessages_channelMessages &data) {
if (channel) {
channel->ptsReceived(data.vpts().v);
channel->processTopics(data.vtopics());
} else {
LOG(("API Error: received messages.channelMessages "
"when no channel was passed! (WebPageData::ApplyChanges)"));