From d0d2a4f488e261fe74164cc6b896a04874353f97 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 8 Nov 2022 19:48:46 +0400 Subject: [PATCH] Show messages count in forum. --- Telegram/Resources/langs/lang.strings | 3 +++ .../SourceFiles/data/data_replies_list.cpp | 4 +++ Telegram/SourceFiles/data/data_replies_list.h | 1 + .../view/history_view_replies_section.cpp | 26 ++++++++++++------- .../view/history_view_top_bar_widget.cpp | 3 ++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7c17f71d68..1416b6bf00 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3556,6 +3556,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_forum_create_topic" = "Create topic"; "lng_forum_discard_sure" = "Are you sure you want to discard this topic?"; "lng_forum_view_as_messages" = "View as Messages"; +"lng_forum_no_messages" = "No messages"; +"lng_forum_messages#one" = "{count} message"; +"lng_forum_messages#other" = "{count} messages"; // Wnd specific diff --git a/Telegram/SourceFiles/data/data_replies_list.cpp b/Telegram/SourceFiles/data/data_replies_list.cpp index 3263c788af..40ba50eb7a 100644 --- a/Telegram/SourceFiles/data/data_replies_list.cpp +++ b/Telegram/SourceFiles/data/data_replies_list.cpp @@ -276,6 +276,10 @@ rpl::producer RepliesList::fullCount() const { return _fullCount.value() | rpl::filter_optional(); } +rpl::producer> RepliesList::maybeFullCount() const { + return _fullCount.value(); +} + bool RepliesList::unreadCountKnown() const { return _unreadCount.current().has_value(); } diff --git a/Telegram/SourceFiles/data/data_replies_list.h b/Telegram/SourceFiles/data/data_replies_list.h index 6b4107c8cc..e38d9c80a4 100644 --- a/Telegram/SourceFiles/data/data_replies_list.h +++ b/Telegram/SourceFiles/data/data_replies_list.h @@ -42,6 +42,7 @@ public: int limitAfter); [[nodiscard]] rpl::producer fullCount() const; + [[nodiscard]] rpl::producer> maybeFullCount() const; [[nodiscard]] bool unreadCountKnown() const; [[nodiscard]] int unreadCountCurrent() const; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index f2afd17549..59d60193e4 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -2046,20 +2046,28 @@ void RepliesWidget::setReplies(std::shared_ptr replies) { ? _replies->unreadCountCurrent() : std::optional()); - if (_topic) { - return; - } + const auto isTopic = (_topic != nullptr); + const auto isTopicCreating = isTopic && _topic->creating(); rpl::combine( - rpl::single(0) | rpl::then(_replies->fullCount()), + rpl::single( + std::optional() + ) | rpl::then(_replies->maybeFullCount()), _areComments.value() - ) | rpl::map([=](int count, bool areComments) { - return count - ? (areComments + ) | rpl::map([=](std::optional count, bool areComments) { + const auto sub = isTopic ? 1 : 0; + return (count && (*count > sub)) + ? (isTopic + ? tr::lng_forum_messages + : areComments ? tr::lng_comments_header : tr::lng_replies_header)( lt_count_decimal, - rpl::single(count) | tr::to_count()) - : (areComments + rpl::single(*count - sub) | tr::to_count()) + : (isTopic + ? ((count.has_value() || isTopicCreating) + ? tr::lng_forum_no_messages + : tr::lng_contacts_loading) + : areComments ? tr::lng_comments_header_none : tr::lng_replies_header_none)(); }) | rpl::flatten_latest( diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index f3d2e2dac9..dd932c2c3c 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -484,7 +484,8 @@ void TopBarWidget::paintTopBar(Painter &p) { width(), st::historyStatusFgTyping, now)) { - paintStatus(p, nameleft, statustop, availableWidth, width()); + p.setPen(st::historyStatusFg); + p.drawTextLeft(nameleft, statustop, width(), _customTitleText); } } else if (folder || history->peer->sharedMediaInfo()