2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-04 00:25:17 +00:00

Optimize updates subscription in topics.

This commit is contained in:
John Preston
2022-11-02 20:59:12 +04:00
parent 9d4840c0de
commit a21c73facd
5 changed files with 108 additions and 39 deletions

View File

@@ -56,6 +56,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_wall_paper.h"
#include "data/data_game.h"
#include "data/data_poll.h"
#include "data/data_replies_list.h"
#include "data/data_chat_filters.h"
#include "data/data_scheduled_messages.h"
#include "data/data_send_action.h"
@@ -292,6 +293,8 @@ Session::Session(not_null<Main::Session*> session)
}
}, _lifetime);
subscribeForTopicRepliesLists();
crl::on_main(_session, [=] {
AmPremiumValue(
_session
@@ -307,6 +310,37 @@ Session::Session(not_null<Main::Session*> session)
});
}
void Session::subscribeForTopicRepliesLists() {
repliesReadTillUpdates(
) | rpl::start_with_next([=](const RepliesReadTillUpdate &update) {
if (const auto peer = peerLoaded(update.id.peer)) {
if (const auto topic = peer->forumTopicFor(update.id.msg)) {
topic->replies()->apply(update);
}
}
}, _lifetime);
session().changes().messageUpdates(
MessageUpdate::Flag::NewAdded
| MessageUpdate::Flag::NewMaybeAdded
| MessageUpdate::Flag::ReplyToTopAdded
| MessageUpdate::Flag::Destroyed
) | rpl::start_with_next([=](const MessageUpdate &update) {
if (const auto topic = update.item->topic()) {
topic->replies()->apply(update);
}
}, _lifetime);
channelDifferenceTooLong(
) | rpl::start_with_next([=](not_null<ChannelData*> channel) {
if (const auto forum = channel->forum()) {
forum->enumerateTopics([](not_null<ForumTopic*> topic) {
topic->replies()->applyDifferenceTooLong();
});
}
}, _lifetime);
}
void Session::clear() {
// Optimization: clear notifications before destroying items.
Core::App().notifications().clearFromSession(_session);