diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index 5b57469259..dbaa95c68e 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -194,6 +194,10 @@ historyComposeButton: FlatButton { color: historyComposeButtonBgRipple; } } +historyComposeButtonLabel: FlatLabel(defaultFlatLabel) { + textFg: windowActiveTextFg; + style: semiboldTextStyle; +} historyUnblock: FlatButton(historyComposeButton) { color: attentionButtonFg; overColor: attentionButtonFgOver; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index cdd153f5c5..e309ddc1d1 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -45,6 +45,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_element.h" #include "profile/profile_block_group_members.h" #include "info/info_memento.h" +#include "info/profile/info_profile_values.h" // Info::Profile::ToUpperValue #include "core/click_handler_types.h" #include "chat_helpers/tabbed_panel.h" #include "chat_helpers/tabbed_selector.h" @@ -68,6 +69,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_regex.h" #include "ui/widgets/popup_menu.h" #include "ui/text_options.h" +#include "ui/unread_badge.h" #include "auth_session.h" #include "window/themes/window_theme.h" #include "window/notifications_manager.h" @@ -143,6 +145,97 @@ bool ShowHistoryEndInsteadOfUnread( return (last != nullptr) && !IsServerMsgId(last->id); } +object_ptr SetupDiscussButton( + not_null parent, + not_null controller) { + auto result = object_ptr( + parent, + QString(), + st::historyComposeButton); + const auto button = result.data(); + auto text = Lang::Viewer( + lng_channel_discuss + ) | Info::Profile::ToUpperValue(); + const auto label = Ui::CreateChild( + button, + rpl::duplicate(text), + st::historyComposeButtonLabel); + const auto badge = Ui::CreateChild(button); + label->show(); + + controller->activeChatValue( + ) | rpl::map([=](Dialogs::Key chat) { + return chat.history(); + }) | rpl::map([=](History *history) { + return history ? history->peer->asChannel() : nullptr; + }) | rpl::map([=](ChannelData *channel) -> rpl::producer { + if (channel && channel->isBroadcast()) { + return PeerUpdateValue( + channel, + Notify::PeerUpdate::Flag::ChannelLinkedChat + ) | rpl::map([=] { + return channel->linkedChat(); + }); + } + return rpl::single(nullptr); + }) | rpl::flatten_latest( + ) | rpl::distinct_until_changed( + ) | rpl::map([=](ChannelData *chat) + -> rpl::producer> { + if (chat) { + return PeerUpdateValue( + chat, + Notify::PeerUpdate::Flag::UnreadViewChanged + | Notify::PeerUpdate::Flag::NotificationsEnabled + | Notify::PeerUpdate::Flag::ChannelAmIn + ) | rpl::map([=] { + const auto history = chat->amIn() + ? chat->owner().historyLoaded(chat) + : nullptr; + return history + ? std::make_tuple( + history->unreadCountForBadge(), + !history->mute()) + : std::make_tuple(0, false); + }); + } else { + return rpl::single(std::make_tuple(0, false)); + } + }) | rpl::flatten_latest( + ) | rpl::distinct_until_changed( + ) | rpl::start_with_next([=](int count, bool active) { + badge->setText(QString::number(count), active); + badge->setVisible(count > 0); + }, badge->lifetime()); + + rpl::combine( + badge->shownValue(), + badge->widthValue(), + label->widthValue(), + button->widthValue() + ) | rpl::start_with_next([=]( + bool badgeShown, + int badgeWidth, + int labelWidth, + int width) { + const auto textTop = st::historyComposeButton.textTop; + const auto badgeTop = textTop + + st::historyComposeButton.font->height + - badge->textBaseline(); + const auto add = badgeShown + ? (textTop + badgeWidth) + : 0; + const auto total = labelWidth + add; + label->moveToLeft((width - total) / 2, textTop, width); + badge->moveToRight((width - total) / 2, textTop, width); + }, button->lifetime()); + + label->setAttribute(Qt::WA_TransparentForMouseEvents); + badge->setAttribute(Qt::WA_TransparentForMouseEvents); + + return result; +} + } // namespace ReportSpamPanel::ReportSpamPanel(QWidget *parent) : TWidget(parent), @@ -214,10 +307,7 @@ HistoryWidget::HistoryWidget( this, lang(lng_channel_mute).toUpper(), st::historyComposeButton) -, _discuss( - this, - lang(lng_channel_discuss).toUpper(), - st::historyComposeButton) +, _discuss(SetupDiscussButton(this, controller)) , _attachToggle(this, st::historyAttach) , _tabbedSelectorToggle(this, st::historyAttachEmoji) , _botKeyboardShow(this, st::historyBotKeyboardShow) 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 5902f00e50..6383a44819 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -523,13 +523,6 @@ void TopBarWidget::updateControlsGeometry() { && (width() < _back->width() + _search->width()); _leftTaken = smallDialogsColumn ? (width() - _back->width()) / 2 : 0; _back->moveToLeft(_leftTaken, otherButtonsTop); - if (_unreadBadge) { - _unreadBadge->setGeometryToLeft( - _leftTaken, - otherButtonsTop + st::titleUnreadCounterTop, - _back->width(), - st::dialogsUnreadHeight); - } _leftTaken += _back->width(); if (_info && !_info->isHidden()) { _info->moveToLeft(_leftTaken, otherButtonsTop); @@ -708,11 +701,16 @@ void TopBarWidget::refreshUnreadBadge() { return; } _unreadBadge.create(this); - _unreadBadge->setGeometryToLeft( - 0, - st::titleUnreadCounterTop, - _back->width(), - st::dialogsUnreadHeight); + + rpl::combine( + _back->geometryValue(), + _unreadBadge->widthValue() + ) | rpl::start_with_next([=](QRect geometry, int width) { + _unreadBadge->move( + geometry.x() + geometry.width() - width, + geometry.y() + st::titleUnreadCounterTop); + }, _unreadBadge->lifetime()); + _unreadBadge->show(); _unreadBadge->setAttribute(Qt::WA_TransparentForMouseEvents); _unreadCounterSubscription = subscribe( diff --git a/Telegram/SourceFiles/ui/unread_badge.cpp b/Telegram/SourceFiles/ui/unread_badge.cpp index 1b1d63b73d..b9d53909b3 100644 --- a/Telegram/SourceFiles/ui/unread_badge.cpp +++ b/Telegram/SourceFiles/ui/unread_badge.cpp @@ -14,9 +14,18 @@ namespace Ui { void UnreadBadge::setText(const QString &text, bool active) { _text = text; _active = active; + const auto st = Dialogs::Layout::UnreadBadgeStyle(); + resize( + std::max(st.font->width(text) + 2 * st.padding, st.size), + st.size); update(); } +int UnreadBadge::textBaseline() const { + const auto st = Dialogs::Layout::UnreadBadgeStyle(); + return ((st.size - st.font->height) / 2) + st.font->ascent; +} + void UnreadBadge::paintEvent(QPaintEvent *e) { if (_text.isEmpty()) { return; diff --git a/Telegram/SourceFiles/ui/unread_badge.h b/Telegram/SourceFiles/ui/unread_badge.h index 06836249e7..f204a50155 100644 --- a/Telegram/SourceFiles/ui/unread_badge.h +++ b/Telegram/SourceFiles/ui/unread_badge.h @@ -16,6 +16,7 @@ public: using RpWidget::RpWidget; void setText(const QString &text, bool active); + int textBaseline() const; protected: void paintEvent(QPaintEvent *e) override;