From 33643ff7fcd5343ea8124f06cd59910aabe29f7a Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 11 Jan 2024 11:06:30 +0400 Subject: [PATCH] Add "show" button for last seen hidden. --- Telegram/SourceFiles/info/info.style | 11 ++++++ .../info/profile/info_profile_cover.cpp | 37 +++++++++++++++++++ .../info/profile/info_profile_cover.h | 3 ++ 3 files changed, 51 insertions(+) diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index c709a70141..fbd6157e38 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -304,6 +304,9 @@ InfoProfileCover { status: FlatLabel; statusLeft: pixels; statusTop: pixels; + showLastSeen: RoundButton; + showLastSeenPosition: point; + showLastSeenVisible: bool; rightSkip: pixels; } infoProfilePhotoInnerSize: 72px; @@ -334,6 +337,14 @@ infoProfileCover: InfoProfileCover { status: infoProfileStatus; statusLeft: 109px; statusTop: 58px; + showLastSeen: RoundButton(defaultActiveButton) { + width: -12px; + height: 20px; + textTop: 2px; + font: font(11px semibold); + } + showLastSeenPosition: point(4px, 56px); + showLastSeenVisible: true; rightSkip: 20px; } infoProfileMegagroupCover: InfoProfileCover(infoProfileCover) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp index a15e49ccb5..3f94457878 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/media/history_view_sticker_player.h" #include "lang/lang_keys.h" #include "ui/controls/userpic_button.h" +#include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/text/text_utilities.h" #include "base/unixtime.h" @@ -323,6 +324,7 @@ Cover::Cover( : nullptr) , _name(this, _st.name) , _status(this, _st.status) +, _showLastSeen(this, tr::lng_status_lastseen_show(), _st.showLastSeen) , _refreshStatusTimer([this] { refreshStatusText(); }) { _peer->updateFull(); @@ -333,6 +335,8 @@ Cover::Cover( _status->setAttribute(Qt::WA_TransparentForMouseEvents); } + setupShowLastSeen(); + _badge->setPremiumClickCallback([=] { if (const auto panel = _emojiStatusPanel.get()) { panel->show(_controller, _badge->widget(), _badge->sizeTag()); @@ -361,6 +365,34 @@ Cover::Cover( } } +void Cover::setupShowLastSeen() { + const auto user = _peer->asUser(); + if (_st.showLastSeenVisible + && user + && !user->isSelf() + && !user->isBot() + && !user->isServiceUser() + && user->session().premiumPossible()) { + rpl::combine( + user->session().changes().peerFlagsValue( + user, + Data::PeerUpdate::Flag::OnlineStatus), + Data::AmPremiumValue(&user->session()) + ) | rpl::start_with_next([=] { + _showLastSeen->setVisible( + (user->onlineTill == kOnlineHidden) + && !user->session().premium() + && user->session().premiumPossible()); + }, _showLastSeen->lifetime()); + } else { + _showLastSeen->hide(); + } + + _showLastSeen->setClickedCallback([=] { + ::Settings::ShowPremium(_controller, u"lastseen_hidden"_q); + }); +} + void Cover::setupChildGeometry() { widthValue( ) | rpl::start_with_next([this](int newWidth) { @@ -577,6 +609,11 @@ void Cover::refreshStatusGeometry(int newWidth) { auto statusWidth = newWidth - _st.statusLeft - _st.rightSkip; _status->resizeToWidth(statusWidth); _status->moveToLeft(_st.statusLeft, _st.statusTop, newWidth); + const auto left = _st.statusLeft + _status->textMaxWidth(); + _showLastSeen->moveToLeft( + left + _st.showLastSeenPosition.x(), + _st.showLastSeenPosition.y(), + newWidth); } } // namespace Info::Profile diff --git a/Telegram/SourceFiles/info/profile/info_profile_cover.h b/Telegram/SourceFiles/info/profile/info_profile_cover.h index 42a40b190b..20389e7c5e 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_cover.h +++ b/Telegram/SourceFiles/info/profile/info_profile_cover.h @@ -20,6 +20,7 @@ class UserpicButton; class FlatLabel; template class SlideWrap; +class RoundButton; } // namespace Ui namespace HistoryView { @@ -126,6 +127,7 @@ private: Role role, rpl::producer title); + void setupShowLastSeen(); void setupChildGeometry(); void initViewers(rpl::producer title); void refreshStatusText(); @@ -149,6 +151,7 @@ private: object_ptr _iconButton; object_ptr _name = { nullptr }; object_ptr _status = { nullptr }; + object_ptr _showLastSeen = { nullptr }; //object_ptr _dropArea = { nullptr }; base::Timer _refreshStatusTimer;