Show messages count in forum.

This commit is contained in:
John Preston 2022-11-08 19:48:46 +04:00
parent 8ee28f6665
commit d0d2a4f488
5 changed files with 27 additions and 10 deletions

View file

@ -3556,6 +3556,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_forum_create_topic" = "Create topic"; "lng_forum_create_topic" = "Create topic";
"lng_forum_discard_sure" = "Are you sure you want to discard this topic?"; "lng_forum_discard_sure" = "Are you sure you want to discard this topic?";
"lng_forum_view_as_messages" = "View as Messages"; "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 // Wnd specific

View file

@ -276,6 +276,10 @@ rpl::producer<int> RepliesList::fullCount() const {
return _fullCount.value() | rpl::filter_optional(); return _fullCount.value() | rpl::filter_optional();
} }
rpl::producer<std::optional<int>> RepliesList::maybeFullCount() const {
return _fullCount.value();
}
bool RepliesList::unreadCountKnown() const { bool RepliesList::unreadCountKnown() const {
return _unreadCount.current().has_value(); return _unreadCount.current().has_value();
} }

View file

@ -42,6 +42,7 @@ public:
int limitAfter); int limitAfter);
[[nodiscard]] rpl::producer<int> fullCount() const; [[nodiscard]] rpl::producer<int> fullCount() const;
[[nodiscard]] rpl::producer<std::optional<int>> maybeFullCount() const;
[[nodiscard]] bool unreadCountKnown() const; [[nodiscard]] bool unreadCountKnown() const;
[[nodiscard]] int unreadCountCurrent() const; [[nodiscard]] int unreadCountCurrent() const;

View file

@ -2046,20 +2046,28 @@ void RepliesWidget::setReplies(std::shared_ptr<Data::RepliesList> replies) {
? _replies->unreadCountCurrent() ? _replies->unreadCountCurrent()
: std::optional<int>()); : std::optional<int>());
if (_topic) { const auto isTopic = (_topic != nullptr);
return; const auto isTopicCreating = isTopic && _topic->creating();
}
rpl::combine( rpl::combine(
rpl::single(0) | rpl::then(_replies->fullCount()), rpl::single(
std::optional<int>()
) | rpl::then(_replies->maybeFullCount()),
_areComments.value() _areComments.value()
) | rpl::map([=](int count, bool areComments) { ) | rpl::map([=](std::optional<int> count, bool areComments) {
return count const auto sub = isTopic ? 1 : 0;
? (areComments return (count && (*count > sub))
? (isTopic
? tr::lng_forum_messages
: areComments
? tr::lng_comments_header ? tr::lng_comments_header
: tr::lng_replies_header)( : tr::lng_replies_header)(
lt_count_decimal, lt_count_decimal,
rpl::single(count) | tr::to_count()) rpl::single(*count - sub) | tr::to_count())
: (areComments : (isTopic
? ((count.has_value() || isTopicCreating)
? tr::lng_forum_no_messages
: tr::lng_contacts_loading)
: areComments
? tr::lng_comments_header_none ? tr::lng_comments_header_none
: tr::lng_replies_header_none)(); : tr::lng_replies_header_none)();
}) | rpl::flatten_latest( }) | rpl::flatten_latest(

View file

@ -484,7 +484,8 @@ void TopBarWidget::paintTopBar(Painter &p) {
width(), width(),
st::historyStatusFgTyping, st::historyStatusFgTyping,
now)) { now)) {
paintStatus(p, nameleft, statustop, availableWidth, width()); p.setPen(st::historyStatusFg);
p.drawTextLeft(nameleft, statustop, width(), _customTitleText);
} }
} else if (folder } else if (folder
|| history->peer->sharedMediaInfo() || history->peer->sharedMediaInfo()