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_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

View File

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

View File

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

View File

@ -2046,20 +2046,28 @@ void RepliesWidget::setReplies(std::shared_ptr<Data::RepliesList> replies) {
? _replies->unreadCountCurrent()
: std::optional<int>());
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<int>()
) | rpl::then(_replies->maybeFullCount()),
_areComments.value()
) | rpl::map([=](int count, bool areComments) {
return count
? (areComments
) | rpl::map([=](std::optional<int> 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(

View File

@ -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()