From 1363faddbf4171e4ee2476f0039d1caf69f23fd4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 13 Sep 2022 07:44:22 +0400 Subject: [PATCH] Add "Reaction button in messages" setting. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/core_settings.cpp | 10 ++++++++-- Telegram/SourceFiles/core/core_settings.h | 13 +++++++++++++ .../SourceFiles/history/history_inner_widget.cpp | 11 +++++++++++ .../SourceFiles/history/history_inner_widget.h | 1 + .../history/view/history_view_list_widget.cpp | 13 +++++++++++++ .../history/view/history_view_list_widget.h | 1 + Telegram/SourceFiles/settings/settings_chat.cpp | 15 +++++++++++++++ 8 files changed, 63 insertions(+), 2 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9fd2365888..5e96cd7b5c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -513,6 +513,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_send_cmdenter" = "Send by Cmd+Enter"; "lng_settings_chat_quick_action_reply" = "Reply with double click"; "lng_settings_chat_quick_action_react" = "Send reaction with double click"; +"lng_settings_chat_corner_reaction" = "Reaction button on messages"; "lng_settings_chat_reactions_title" = "Quick Reaction"; "lng_settings_chat_reactions_subtitle" = "Choose your favorite reaction"; diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 4205f6ba53..d7f564814b 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -153,7 +153,7 @@ QByteArray Settings::serialize() const { + Serialize::stringSize(_customDeviceModel.current()) + sizeof(qint32) * 4 + (_accountsOrder.size() * sizeof(quint64)) - + sizeof(qint32) * 4; + + sizeof(qint32) * 5; auto result = QByteArray(); result.reserve(size); @@ -266,7 +266,8 @@ QByteArray Settings::serialize() const { << qint32(0) // old hardwareAcceleratedVideo << qint32(_chatQuickAction) << qint32(_hardwareAcceleratedVideo ? 1 : 0) - << qint32(_suggestAnimatedEmoji ? 1 : 0); + << qint32(_suggestAnimatedEmoji ? 1 : 0) + << qint32(_cornerReaction.current() ? 1 : 0); } return result; } @@ -359,6 +360,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 hardwareAcceleratedVideo = _hardwareAcceleratedVideo ? 1 : 0; qint32 chatQuickAction = static_cast(_chatQuickAction); qint32 suggestAnimatedEmoji = _suggestAnimatedEmoji ? 1 : 0; + qint32 cornerReaction = _cornerReaction.current() ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -553,6 +555,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> suggestAnimatedEmoji; } + if (!stream.atEnd()) { + stream >> cornerReaction; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -721,6 +726,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { } } _suggestAnimatedEmoji = (suggestAnimatedEmoji == 1); + _cornerReaction = (cornerReaction == 1); } QString Settings::getSoundPath(const QString &key) const { diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 0719520114..a6502c1afa 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -410,6 +410,18 @@ public: void setSuggestAnimatedEmoji(bool value) { _suggestAnimatedEmoji = value; } + void setCornerReaction(bool value) { + _cornerReaction = value; + } + [[nodiscard]] bool cornerReaction() const { + return _cornerReaction.current(); + } + [[nodiscard]] rpl::producer cornerReactionValue() const { + return _cornerReaction.value(); + } + [[nodiscard]] rpl::producer cornerReactionChanges() const { + return _cornerReaction.changes(); + } void setSpellcheckerEnabled(bool value) { _spellcheckerEnabled = value; @@ -782,6 +794,7 @@ private: bool _suggestEmoji = true; bool _suggestStickersByEmoji = true; bool _suggestAnimatedEmoji = true; + rpl::variable _cornerReaction = true; rpl::variable _spellcheckerEnabled = true; rpl::variable _videoPlaybackSpeed = 1.; float64 _voicePlaybackSpeed = 2.; diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 298810a369..30a6d84286 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -453,6 +453,14 @@ HistoryInner::HistoryInner( _reactionsManager.get(), _reactionsItem.value()); + Core::App().settings().cornerReactionValue( + ) | rpl::start_with_next([=](bool value) { + _useCornerReaction = value; + if (!value) { + _reactionsManager->updateButton({}); + } + }, lifetime()); + controller->adaptive().chatWideValue( ) | rpl::start_with_next([=](bool wide) { _isChatWide = wide; @@ -3369,6 +3377,9 @@ auto HistoryInner::reactionButtonParameters( QPoint position, const HistoryView::TextState &reactionState) const -> HistoryView::Reactions::ButtonParameters { + if (!_useCornerReaction) { + return {}; + } const auto top = itemTop(view); if (top < 0 || !view->data()->canReact() diff --git a/Telegram/SourceFiles/history/history_inner_widget.h b/Telegram/SourceFiles/history/history_inner_widget.h index 6d43ca2c49..a8e359d8ba 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.h +++ b/Telegram/SourceFiles/history/history_inner_widget.h @@ -473,6 +473,7 @@ private: uint16 _mouseTextSymbol = 0; bool _pressWasInactive = false; bool _recountedAfterPendingResizedItems = false; + bool _useCornerReaction = false; QPoint _trippleClickPoint; base::Timer _trippleClickTimer; diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index b14715af28..443906fdff 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -27,6 +27,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "mainwidget.h" #include "core/click_handler_types.h" +#include "core/application.h" +#include "core/core_settings.h" #include "apiwrap.h" #include "api/api_who_reacted.h" #include "layout/layout_selection.h" @@ -401,6 +403,14 @@ ListWidget::ListWidget( _reactionsManager.get(), _reactionsItem.value()); + Core::App().settings().cornerReactionValue( + ) | rpl::start_with_next([=](bool value) { + _useCornerReaction = value; + if (!value) { + _reactionsManager->updateButton({}); + } + }, lifetime()); + controller->adaptive().chatWideValue( ) | rpl::start_with_next([=](bool wide) { _isChatWide = wide; @@ -2583,6 +2593,9 @@ Reactions::ButtonParameters ListWidget::reactionButtonParameters( not_null view, QPoint position, const TextState &reactionState) const { + if (!_useCornerReaction) { + return {}; + } const auto top = itemTop(view); if (top < 0 || !view->data()->canReact() diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index b4f604f636..74d0be6ae2 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -587,6 +587,7 @@ private: std::unique_ptr _reactionsManager; rpl::variable _reactionsItem; + bool _useCornerReaction = false; int _minHeight = 0; int _visibleTop = 0; diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index b0ba26dbf5..36338bfaeb 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -978,6 +978,21 @@ void SetupMessages( show.showBox(Box(ReactionsSettingsBox, controller)); }); + AddSkip(inner, st::settingsSendTypeSkip); + + inner->add( + object_ptr( + inner, + tr::lng_settings_chat_corner_reaction(tr::now), + Core::App().settings().cornerReaction(), + st::settingsCheckbox), + st::settingsCheckboxPadding + )->checkedChanges( + ) | rpl::start_with_next([=](bool checked) { + Core::App().settings().setCornerReaction(checked); + Core::App().saveSettingsDelayed(); + }, inner->lifetime()); + AddSkip(inner, st::settingsCheckboxesSkip); }