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 a928104e8..7cb026791 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -838,7 +838,10 @@ void TopBarWidget::setCustomTitle(const QString &title) { } void TopBarWidget::refreshInfoButton() { - if (const auto peer = _activeChat.key.peer()) { + if (_activeChat.key.topic() + || _activeChat.section == Section::ChatsList) { + _info.destroy(); + } else if (const auto peer = _activeChat.key.peer()) { auto info = object_ptr( this, _controller, @@ -924,6 +927,9 @@ void TopBarWidget::updateControlsGeometry() { if (_info && !_info->isHidden()) { _info->moveToLeft(_leftTaken, otherButtonsTop); _leftTaken += _info->width(); + } else if (_activeChat.key.topic() + || _activeChat.section == Section::ChatsList) { + _leftTaken += st::topBarArrowPadding.right(); } _rightTaken = 0; @@ -984,8 +990,8 @@ void TopBarWidget::updateControlsVisibility() { _back->setVisible(backVisible && !_chooseForReportReason); _cancelChoose->setVisible(_chooseForReportReason.has_value()); if (_info) { - _info->setVisible((isOneColumn || !_primaryWindow) - && !_chooseForReportReason); + _info->setVisible(!_chooseForReportReason + && (isOneColumn || !_primaryWindow)); } if (_unreadBadge) { _unreadBadge->setVisible(!_chooseForReportReason); diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index 24279dd19..13fd5c9ce 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -116,6 +116,106 @@ Cover::Cover( : st::infoProfileCover; } +TopicIconView::TopicIconView( + QWidget *parent, + not_null controller, + not_null topic) +: AbstractButton(parent) { + setup(topic, [=] { + return controller->isGifPausedAtLeastFor( + Window::GifPauseReason::Layer); + }); +} + +void TopicIconView::setup( + not_null topic, + Fn paused) { + setupPlayer(topic); + setupImage(topic); + + resize(st::infoTopicCover.photo.size); + paintRequest( + ) | rpl::start_with_next([=] { + auto p = QPainter(this); + const auto paint = [&](const QImage &image) { + const auto size = image.size() / image.devicePixelRatio(); + p.drawImage( + (st::infoTopicCover.photo.size.width() - size.width()) / 2, + (st::infoTopicCover.photo.size.height() - size.height()) / 2, + image); + }; + if (_player && _player->ready()) { + paint(_player->frame( + st::infoTopicCover.photo.size, + QColor(0, 0, 0, 0), + false, + crl::now(), + paused()).image); + _player->markFrameShown(); + } else if (!topic->iconId() && !_image.isNull()) { + paint(_image); + } + }, lifetime()); +} + +void TopicIconView::setupPlayer(not_null topic) { + IconIdValue( + topic + ) | rpl::map([=](DocumentId id) { + return topic->owner().customEmojiManager().resolve(id); + }) | rpl::flatten_latest( + ) | rpl::map([=](not_null document) { + const auto media = document->createMediaView(); + media->checkStickerLarge(); + media->goodThumbnailWanted(); + + return rpl::single() | rpl::then( + document->owner().session().downloaderTaskFinished() + ) | rpl::filter([=] { + return media->loaded(); + }) | rpl::take(1) | rpl::map([=] { + auto result = std::shared_ptr(); + const auto sticker = document->sticker(); + if (sticker->isLottie()) { + result = std::make_shared( + ChatHelpers::LottiePlayerFromDocument( + media.get(), + ChatHelpers::StickerLottieSize::StickerSet, + st::infoTopicCover.photo.size, + Lottie::Quality::High)); + } else if (sticker->isWebm()) { + result = std::make_shared( + media->owner()->location(), + media->bytes(), + st::infoTopicCover.photo.size); + } else { + result = std::make_shared( + media->owner()->location(), + media->bytes(), + st::infoTopicCover.photo.size); + } + result->setRepaintCallback([=] { update(); }); + return result; + }); + }) | rpl::flatten_latest( + ) | rpl::start_with_next([=](std::shared_ptr player) { + _player = std::move(player); + }, lifetime()); +} + +void TopicIconView::setupImage(not_null topic) { + rpl::combine( + TitleValue(topic), + ColorIdValue(topic) + ) | rpl::map([=](const QString &title, int32 colorId) { + using namespace Data; + return ForumTopicIconFrame(colorId, title, st::infoForumTopicIcon); + }) | rpl::start_with_next([=](QImage &&image) { + _image = std::move(image); + update(); + }, lifetime()); +} + Cover::Cover( QWidget *parent, not_null peer, @@ -147,14 +247,12 @@ Cover::Cover( _peer, Ui::UserpicButton::Role::OpenPhoto, _st.photo)) -, _iconView(topic ? object_ptr(this) : nullptr) +, _iconView(topic + ? object_ptr(this, controller, topic) + : nullptr) , _name(this, _st.name) , _status(this, _st.status) , _refreshStatusTimer([this] { refreshStatusText(); }) { - if (topic) { - setupIcon(topic); - } - _peer->updateFull(); _name->setSelectable(true); @@ -190,94 +288,6 @@ Cover::Cover( } } -void Cover::setupIconPlayer(not_null topic) { - IconIdValue( - topic - ) | rpl::map([=](DocumentId id) { - return topic->owner().customEmojiManager().resolve(id); - }) | rpl::flatten_latest( - ) | rpl::map([=](not_null document) { - const auto media = document->createMediaView(); - media->checkStickerLarge(); - media->goodThumbnailWanted(); - - return rpl::single() | rpl::then( - document->owner().session().downloaderTaskFinished() - ) | rpl::filter([=] { - return media->loaded(); - }) | rpl::take(1) | rpl::map([=] { - auto result = std::shared_ptr(); - const auto sticker = document->sticker(); - if (sticker->isLottie()) { - result = std::make_shared( - ChatHelpers::LottiePlayerFromDocument( - media.get(), - ChatHelpers::StickerLottieSize::StickerSet, - _st.photo.size, - Lottie::Quality::High)); - } else if (sticker->isWebm()) { - result = std::make_shared( - media->owner()->location(), - media->bytes(), - _st.photo.size); - } else { - result = std::make_shared( - media->owner()->location(), - media->bytes(), - _st.photo.size); - } - result->setRepaintCallback([=] { _iconView->update(); }); - return result; - }); - }) | rpl::flatten_latest( - ) | rpl::start_with_next([=](std::shared_ptr player) { - _iconPlayer = std::move(player); - }, lifetime()); -} - -void Cover::setupIconImage(not_null topic) { - rpl::combine( - TitleValue(topic), - ColorIdValue(topic) - ) | rpl::map([=](const QString &title, int32 colorId) { - using namespace Data; - return ForumTopicIconFrame(colorId, title, st::infoForumTopicIcon); - }) | rpl::start_with_next([=](QImage &&image) { - _iconImage = std::move(image); - _iconView->update(); - }, lifetime()); -} - -void Cover::setupIcon(not_null topic) { - setupIconPlayer(topic); - setupIconImage(topic); - - _iconView->resize(_st.photo.size); - _iconView->paintRequest( - ) | rpl::start_with_next([=] { - auto p = QPainter(_iconView.data()); - const auto paint = [&](const QImage &image) { - const auto size = image.size() / image.devicePixelRatio(); - p.drawImage( - (_st.photo.size.width() - size.width()) / 2, - (_st.photo.size.height() - size.height()) / 2, - image); - }; - if (_iconPlayer && _iconPlayer->ready()) { - paint(_iconPlayer->frame( - _st.photo.size, - QColor(0, 0, 0, 0), - false, - crl::now(), - _controller->isGifPausedAtLeastFor( - Window::GifPauseReason::Layer)).image); - _iconPlayer->markFrameShown(); - } else if (!topic->iconId() && !_iconImage.isNull()) { - paint(_iconImage); - } - }, _iconView->lifetime()); -} - void Cover::setupChildGeometry() { widthValue( ) | rpl::start_with_next([this](int newWidth) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.h b/Telegram/SourceFiles/info/profile/info_profile_cover.h index 739744231..2bf12c676 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.h +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "ui/wrap/padding_wrap.h" +#include "ui/abstract_button.h" #include "base/timer.h" namespace Window { @@ -43,6 +44,27 @@ namespace Info::Profile { class EmojiStatusPanel; class Badge; +class TopicIconView final : public Ui::AbstractButton { +public: + TopicIconView( + QWidget *parent, + not_null controller, + not_null topic); + +private: + using StickerPlayer = HistoryView::StickerPlayer; + + void setup( + not_null topic, + Fn paused); + void setupPlayer(not_null topic); + void setupImage(not_null topic); + + std::shared_ptr _player; + QImage _image; + +}; + class Cover final : public Ui::FixedHeightWidget { public: Cover( @@ -67,8 +89,6 @@ public: } private: - using StickerPlayer = HistoryView::StickerPlayer; - Cover( QWidget *parent, not_null peer, @@ -76,9 +96,6 @@ private: not_null controller, rpl::producer title); - void setupIcon(not_null topic); - void setupIconPlayer(not_null topic); - void setupIconImage(not_null topic); void setupChildGeometry(); void initViewers(rpl::producer title); void refreshStatusText(); @@ -95,9 +112,7 @@ private: int _onlineCount = 0; object_ptr _userpic; - object_ptr _iconView; - std::shared_ptr _iconPlayer; - QImage _iconImage; + object_ptr _iconView; object_ptr _name = { nullptr }; object_ptr _status = { nullptr }; //object_ptr _dropArea = { nullptr }; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index c6f6dd8a0..8cfe2aa91 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -523,7 +523,7 @@ void Filler::addToggleUnreadMark() { return; } const auto unread = IsUnreadThread(_thread); - if (_thread->asTopic() && !unread) { + if ((_thread->asTopic() || peer->isForum()) && !unread) { return; } const auto weak = base::make_weak(_thread);