From 01748d8aba298f02e9e9ea950032f4ded6367663 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 29 Nov 2022 17:48:51 +0400 Subject: [PATCH] Better General topic support. --- Telegram/SourceFiles/apiwrap.cpp | 10 ++-- .../SourceFiles/data/data_forum_topic.cpp | 51 +++++++++++-------- Telegram/SourceFiles/data/data_forum_topic.h | 2 + .../admin_log/history_admin_log_item.cpp | 1 + .../SourceFiles/history/history_service.cpp | 2 + .../history/view/history_view_element.cpp | 5 +- 6 files changed, 46 insertions(+), 25 deletions(-) diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 639c75d7f..11f564467 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -3490,10 +3490,12 @@ void ApiWrap::sendMessage(MessageToSend &&message) { const auto replyTo = replyToId ? peer->owner().message(peer, replyToId) : nullptr; - const auto topicRootId = replyTo ? replyTo->topicRootId() : replyToId; - const auto topic = topicRootId - ? peer->forumTopicFor(topicRootId) - : nullptr; + const auto topicRootId = replyTo + ? replyTo->topicRootId() + : action.topicRootId + ? action.topicRootId + : Data::ForumTopic::kGeneralId; + const auto topic = peer->forumTopicFor(topicRootId); if (!(topic ? topic->canWrite() : peer->canWrite()) || Api::SendDice(message)) { return; diff --git a/Telegram/SourceFiles/data/data_forum_topic.cpp b/Telegram/SourceFiles/data/data_forum_topic.cpp index e9e168aae..d2f71f1f3 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.cpp +++ b/Telegram/SourceFiles/data/data_forum_topic.cpp @@ -162,9 +162,12 @@ QImage ForumTopicGeneralIconFrame(int size, const style::color &color) { } TextWithEntities ForumTopicIconWithTitle( + MsgId rootId, DocumentId iconId, const QString &title) { - return iconId + return (rootId == ForumTopic::kGeneralId) + ? TextWithEntities{ u"# "_q + title } + : iconId ? Data::SingleCustomEmoji(iconId).append(title) : TextWithEntities{ title }; } @@ -185,24 +188,7 @@ ForumTopic::ForumTopic(not_null forum, MsgId rootId) Thread::setMuted(owner().notifySettings().isMuted(this)); _sendActionPainter->setTopic(this); - - _replies->unreadCountValue( - ) | rpl::map([=](std::optional value) { - return value ? _replies->displayedUnreadCount() : value; - }) | rpl::distinct_until_changed( - ) | rpl::combine_previous( - ) | rpl::filter([=] { - return inChatList(); - }) | rpl::start_with_next([=]( - std::optional previous, - std::optional now) { - if (previous.value_or(0) != now.value_or(0)) { - _forum->recentTopicsInvalidate(this); - } - notifyUnreadStateChange(unreadStateFor( - previous.value_or(0), - previous.has_value())); - }, _replies->lifetime()); + subscribeToUnreadChanges(); if (isGeneral()) { style::PaletteChanged( @@ -311,12 +297,37 @@ void ForumTopic::setRealRootId(MsgId realId) { _rootId = realId; _lastKnownServerMessageId = realId; _replies = std::make_shared(history(), _rootId); + if (_sendActionPainter) { + _sendActionPainter->setTopic(nullptr); + } _sendActionPainter = owner().sendActionManager().repliesPainter( history(), _rootId); + _sendActionPainter->setTopic(this); + subscribeToUnreadChanges(); } } +void ForumTopic::subscribeToUnreadChanges() { + _replies->unreadCountValue( + ) | rpl::map([=](std::optional value) { + return value ? _replies->displayedUnreadCount() : value; + }) | rpl::distinct_until_changed( + ) | rpl::combine_previous( + ) | rpl::filter([=] { + return inChatList(); + }) | rpl::start_with_next([=]( + std::optional previous, + std::optional now) { + if (previous.value_or(0) != now.value_or(0)) { + _forum->recentTopicsInvalidate(this); + } + notifyUnreadStateChange(unreadStateFor( + previous.value_or(0), + previous.has_value())); + }, _lifetime); +} + void ForumTopic::readTillEnd() { _replies->readTill(_lastKnownServerMessageId); } @@ -672,7 +683,7 @@ QString ForumTopic::title() const { } TextWithEntities ForumTopic::titleWithIcon() const { - return ForumTopicIconWithTitle(_iconId, _title); + return ForumTopicIconWithTitle(_rootId, _iconId, _title); } int ForumTopic::titleVersion() const { diff --git a/Telegram/SourceFiles/data/data_forum_topic.h b/Telegram/SourceFiles/data/data_forum_topic.h index 329b4cf8f..763c62bf0 100644 --- a/Telegram/SourceFiles/data/data_forum_topic.h +++ b/Telegram/SourceFiles/data/data_forum_topic.h @@ -49,6 +49,7 @@ class Forum; int size, const style::color &color); [[nodiscard]] TextWithEntities ForumTopicIconWithTitle( + MsgId rootId, DocumentId iconId, const QString &title); @@ -181,6 +182,7 @@ private: int chatListNameVersion() const override; + void subscribeToUnreadChanges(); [[nodiscard]] Dialogs::UnreadState unreadStateFor( int count, bool known) const; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index d4224034f..a63deeb70 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -627,6 +627,7 @@ TextWithEntities GenerateDefaultBannedRightsChangeText( return topic.match([&](const MTPDforumTopic &data) { return Ui::Text::Link( Data::ForumTopicIconWithTitle( + data.vid().v, data.vicon_emoji_id().value_or_empty(), qs(data.vtitle())), u"internal:url:https://t.me/c/%1/%2"_q.arg( diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index 6e26c53a3..10c876f1d 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -646,6 +646,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { lt_topic, Ui::Text::Link( Data::ForumTopicIconWithTitle( + id, action.vicon_emoji_id().value_or_empty(), qs(action.vtitle())), topicUrl), @@ -693,6 +694,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { { tr::lng_action_topic_placeholder(tr::now) }, lt_title, Data::ForumTopicIconWithTitle( + topicRootId(), action.vicon_emoji_id().value_or_empty(), qs(*action.vtitle())), Ui::Text::WithEntities); diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 1b0746a83..ff5a25197 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -705,7 +705,10 @@ auto Element::contextDependentServiceText() -> TextWithLinks { const QString &title, std::optional iconId) { return Ui::Text::Link( - Data::ForumTopicIconWithTitle(iconId.value_or(0), title), + Data::ForumTopicIconWithTitle( + topicRootId, + iconId.value_or(0), + title), topicUrl); }; const auto wrapParentTopic = [&] {