From d0e5ea78a5403716f12284385bbd7866d1a6c02d Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 29 May 2025 18:25:41 +0400 Subject: [PATCH] Improve topics layout management. --- Telegram/Resources/langs/lang.strings | 1 + .../boxes/peers/edit_peer_info_box.cpp | 4 +-- .../boxes/peers/toggle_topics_box.cpp | 8 ++++-- .../dialogs/ui/dialogs_topics_view.cpp | 7 ++++- .../dialogs/ui/dialogs_topics_view.h | 1 + Telegram/SourceFiles/history/history_item.cpp | 28 +++++++++++++------ .../view/history_view_top_bar_widget.cpp | 4 ++- 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7ce0e8ad1c..0253369e8d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2078,6 +2078,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_action_changed_title" = "{from} changed group name to «{title}»"; "lng_action_changed_title_channel" = "Channel name was changed to «{title}»"; "lng_action_created_chat" = "{from} created the group «{title}»"; +"lng_action_created_monoforum" = "Direct messages were enabled in this channel."; "lng_action_ttl_changed" = "{from} set messages to auto-delete in {duration}"; "lng_action_ttl_changed_you" = "You set messages to auto-delete in {duration}"; "lng_action_ttl_changed_channel" = "Messages in this channel will be automatically deleted after {duration}"; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index c53412162a..9ae378d7db 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -1087,7 +1087,7 @@ void Controller::fillDirectMessagesButton() { tr::lng_manage_monoforum(), std::move(label), [=] { showEditDirectMessagesBox(); }, - { &st::menuIconChatBubble }); + { .icon = &st::menuIconChatBubble, .newBadge = true }); } // //void Controller::fillInviteLinkButton() { @@ -1127,7 +1127,7 @@ void Controller::fillForumButton() { changes->events_starting_with({}) | rpl::map(label), [] {}, st::manageGroupTopicsButton, - { &st::menuIconTopics })); + { .icon = &st::menuIconTopics, .newBadge = true })); button->setClickedCallback(crl::guard(this, [=] { if (!*_forumSavedValue && _controls.forumToggleLocked) { diff --git a/Telegram/SourceFiles/boxes/peers/toggle_topics_box.cpp b/Telegram/SourceFiles/boxes/peers/toggle_topics_box.cpp index b2fed66b25..4d6d5454dd 100644 --- a/Telegram/SourceFiles/boxes/peers/toggle_topics_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/toggle_topics_box.cpp @@ -81,6 +81,7 @@ LayoutButton::LayoutButton( const auto icon = iconWidget.release(); setClickedCallback([=] { group->setValue(type); + iconAnimate(anim::repeat::once); }); group->value() | rpl::start_with_next([=](LayoutType value) { const auto active = (value == type); @@ -93,9 +94,6 @@ LayoutButton::LayoutButton( } _active = active; _text.update(); - if (_active) { - iconAnimate(anim::repeat::once); - } _activeAnimation.start([=] { icon->update(); }, _active ? 0. : 1., _active ? 0. : 1., st::fadeWrapDuration); @@ -170,6 +168,10 @@ void ToggleTopicsBox( st::settingsButtonNoIcon)); toggle->toggleOn(rpl::single(enabled)); + Ui::AddSkip(container); + Ui::AddDivider(container); + Ui::AddSkip(container); + const auto group = std::make_shared>(tabs ? LayoutType::Tabs : LayoutType::List); diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp index 4ce796c92e..9286e40cdb 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.cpp @@ -110,6 +110,7 @@ void TopicsView::prepare(MsgId frontRootId, Fn customEmojiRepaint) { _jumpToTopic = false; } } + _allLoaded = _forum->topicsList()->loaded(); } void TopicsView::prepare(PeerId frontPeerId, Fn customEmojiRepaint) { @@ -182,6 +183,7 @@ void TopicsView::prepare(PeerId frontPeerId, Fn customEmojiRepaint) { _jumpToTopic = false; } } + _allLoaded = _monoforum->chatsList()->loaded(); } int TopicsView::jumpToTopicWidth() const { @@ -207,10 +209,13 @@ void TopicsView::paint( rect.setWidth(rect.width() - _lastTopicJumpGeometry.rightCut); auto skipBig = _jumpToTopic && !context.active; if (_titles.empty()) { + const auto text = (_monoforum && _allLoaded) + ? tr::lng_filters_no_chats(tr::now) + : tr::lng_contacts_loading(tr::now); p.drawText( rect.x(), rect.y() + st::normalFont->ascent, - tr::lng_contacts_loading(tr::now)); + text); return; } for (const auto &title : _titles) { diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.h b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.h index 7c41337fad..9dd5d3aa7b 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.h +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_topics_view.h @@ -121,6 +121,7 @@ private: JumpToLastGeometry _lastTopicJumpGeometry; int _version = -1; bool _jumpToTopic = false; + bool _allLoaded = false; rpl::lifetime _lifetime; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 04c3f1076b..672b322412 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -4632,20 +4632,30 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { auto prepareChatCreate = [this](const MTPDmessageActionChatCreate &action) { auto result = PreparedServiceText(); - result.links.push_back(fromLink()); - result.text = tr::lng_action_created_chat( - tr::now, - lt_from, - fromLinkText(), // Link 1. - lt_title, - { .text = qs(action.vtitle()) }, - Ui::Text::WithEntities); + if (_history->peer->isMonoforum()) { + result.text = tr::lng_action_created_monoforum( + tr::now, + Ui::Text::WithEntities); + } else { + result.links.push_back(fromLink()); + result.text = tr::lng_action_created_chat( + tr::now, + lt_from, + fromLinkText(), // Link 1. + lt_title, + { .text = qs(action.vtitle()) }, + Ui::Text::WithEntities); + } return result; }; auto prepareChannelCreate = [this](const MTPDmessageActionChannelCreate &action) { auto result = PreparedServiceText(); - if (isPost()) { + if (_history->peer->isMonoforum()) { + result.text = tr::lng_action_created_monoforum( + tr::now, + Ui::Text::WithEntities); + } else if (isPost()) { result.text = tr::lng_action_created_channel( tr::now, Ui::Text::WithEntities); 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 2ea31c2dc1..b825a2b19e 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -1695,7 +1695,9 @@ void TopBarWidget::updateOnlineDisplay() { } else if (const auto monoforum = peer->monoforum()) { const auto chats = monoforum->chatsList(); const auto count = chats->fullSize().current(); - text = tr::lng_filters_chats_count(tr::now, lt_count, count); + text = (count > 0) + ? tr::lng_filters_chats_count(tr::now, lt_count, count) + : tr::lng_filters_no_chats(tr::now); } else if (peer->isMonoforum()) { text = tr::lng_chat_status_direct(tr::now); } else if (const auto channel = peer->asChannel()) {