From cb4781360ae632819bf888cc18b2cdb42214da6a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 14 Jan 2024 18:50:15 +0300 Subject: [PATCH] Added first shown tooltip to ttl button from voice record bar. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/core_settings.cpp | 9 +++- Telegram/SourceFiles/core/core_settings.h | 10 +++++ .../history_view_voice_record_bar.cpp | 44 +++++++++++++++---- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 1bbb82bd5..357838992 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2492,6 +2492,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_record_listen_cancel_sure" = "Are you sure you want to discard your recorded voice message?"; "lng_record_lock_discard" = "Discard"; "lng_record_hold_tip" = "Please hold the mouse button pressed to record a voice message."; +"lng_record_once_first_tooltip" = "Tap to set this message to **Play Once**."; "lng_record_once_active_tooltip" = "The recipients will be able to listen to it only once."; "lng_will_be_notified" = "Members will be notified when you post"; "lng_wont_be_notified" = "Members will not be notified when you post"; diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index ac4119d95..0ab441fe0 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -339,7 +339,8 @@ QByteArray Settings::serialize() const { << qint32(_ignoreBatterySaving.current() ? 1 : 0) << quint64(_macRoundIconDigest.value_or(0)) << qint32(_storiesClickTooltipHidden.current() ? 1 : 0) - << qint32(_recentEmojiSkip.size()); + << qint32(_recentEmojiSkip.size()) + << qint32(_ttlVoiceClickTooltipHidden.current() ? 1 : 0); for (const auto &id : _recentEmojiSkip) { stream << id; } @@ -453,6 +454,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 storiesClickTooltipHidden = _storiesClickTooltipHidden.current() ? 1 : 0; base::flat_set recentEmojiSkip; qint32 trayIconMonochrome = (_trayIconMonochrome.current() ? 1 : 0); + qint32 ttlVoiceClickTooltipHidden = _ttlVoiceClickTooltipHidden.current() ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -709,6 +711,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { // Let existing clients use the old value. trayIconMonochrome = 0; } + if (!stream.atEnd()) { + stream >> ttlVoiceClickTooltipHidden; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -903,6 +908,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { _storiesClickTooltipHidden = (storiesClickTooltipHidden == 1); _recentEmojiSkip = std::move(recentEmojiSkip); _trayIconMonochrome = (trayIconMonochrome == 1); + _ttlVoiceClickTooltipHidden = (ttlVoiceClickTooltipHidden == 1); } QString Settings::getSoundPath(const QString &key) const { @@ -1259,6 +1265,7 @@ void Settings::resetOnLastLogout() { _systemDarkModeEnabled = false; _hiddenGroupCallTooltips = 0; _storiesClickTooltipHidden = false; + _ttlVoiceClickTooltipHidden = false; _recentEmojiPreload.clear(); _recentEmoji.clear(); diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 0f7082293..5afab71f9 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -820,6 +820,15 @@ public: void setStoriesClickTooltipHidden(bool value) { _storiesClickTooltipHidden = value; } + [[nodiscard]] bool ttlVoiceClickTooltipHidden() const { + return _ttlVoiceClickTooltipHidden.current(); + } + [[nodiscard]] rpl::producer ttlVoiceClickTooltipHiddenValue() const { + return _ttlVoiceClickTooltipHidden.value(); + } + void setTtlVoiceClickTooltipHidden(bool value) { + _ttlVoiceClickTooltipHidden = value; + } [[nodiscard]] static bool ThirdColumnByDefault(); [[nodiscard]] static float64 DefaultDialogsWidthRatio(); @@ -945,6 +954,7 @@ private: rpl::variable _ignoreBatterySaving = false; std::optional _macRoundIconDigest; rpl::variable _storiesClickTooltipHidden = false; + rpl::variable _ttlVoiceClickTooltipHidden = false; bool _tabbedReplacedWithInfo = false; // per-window rpl::event_stream _tabbedReplacedWithInfoValue; // per-window diff --git a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp index f8bd585b2..d78bc4b41 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_voice_record_bar.cpp @@ -280,7 +280,6 @@ protected: private: const style::RecordBar &_st; const QRect _rippleRect; - const QString _text; Ui::Animations::Simple _activeAnimation; @@ -292,8 +291,7 @@ TTLButton::TTLButton( : RippleButton(parent, st.lock.ripple) , _st(st) , _rippleRect(Rect(Size(st::historyRecordLockTopShadow.width())) - - (st::historyRecordLockRippleMargin)) -, _text(u"1"_q) { + - (st::historyRecordLockRippleMargin)) { resize(Size(st::historyRecordLockTopShadow.width())); setClickedCallback([=] { @@ -306,20 +304,27 @@ TTLButton::TTLButton( st::historyRecordVoiceShowDuration); }); - { + Ui::RpWidget::shownValue() | rpl::filter( + rpl::mappers::_1 + ) | rpl::skip(1) | rpl::take(1) | rpl::start_with_next([=] { + auto text = rpl::conditional( + Core::App().settings().ttlVoiceClickTooltipHiddenValue(), + tr::lng_record_once_active_tooltip( + Ui::Text::RichLangValue), + tr::lng_record_once_first_tooltip( + Ui::Text::RichLangValue)); const auto tooltip = Ui::CreateChild( parent.get(), object_ptr>( parent.get(), Ui::MakeNiceTooltipLabel( parent, - tr::lng_record_once_active_tooltip( - Ui::Text::RichLangValue), + std::move(text), st::historyMessagesTTLLabel.minWidth, st::ttlMediaImportantTooltipLabel), st::defaultImportantTooltip.padding), st::historyRecordTooltip); - geometryValue( + Ui::RpWidget::geometryValue( ) | rpl::start_with_next([=](const QRect &r) { if (r.isEmpty()) { return; @@ -336,6 +341,15 @@ TTLButton::TTLButton( }); }, tooltip->lifetime()); tooltip->show(); + if (!Core::App().settings().ttlVoiceClickTooltipHidden()) { + clicks( + ) | rpl::take(1) | rpl::start_with_next([=] { + Core::App().settings().setTtlVoiceClickTooltipHidden(true); + }, tooltip->lifetime()); + tooltip->toggleAnimated(true); + } else { + tooltip->toggleFast(false); + } clicks( ) | rpl::start_with_next([=] { @@ -347,7 +361,19 @@ TTLButton::TTLButton( tooltip->hideAfter(kTimeout); } }, tooltip->lifetime()); - } + + Ui::RpWidget::geometryValue( + ) | rpl::map([=](const QRect &r) { + return (r.left() + r.width() > parentWidget()->width()); + }) | rpl::distinct_until_changed( + ) | rpl::start_with_next([=](bool toHide) { + const auto isFirstTooltip = + !Core::App().settings().ttlVoiceClickTooltipHidden(); + if (isFirstTooltip || (!isFirstTooltip && toHide)) { + tooltip->toggleAnimated(!toHide); + } + }, tooltip->lifetime()); + }, lifetime()); paintRequest( ) | rpl::start_with_next([=](const QRect &clip) { @@ -1633,6 +1659,8 @@ void VoiceRecordBar::finish() { _listen = nullptr; + [[maybe_unused]] const auto s = takeTTLState(); + _sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 }); }