Add "Reaction button in messages" setting.

This commit is contained in:
John Preston 2022-09-13 07:44:22 +04:00
parent 20a5950f99
commit 1363faddbf
8 changed files with 63 additions and 2 deletions

View File

@ -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";

View File

@ -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<qint32>(_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 {

View File

@ -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<bool> cornerReactionValue() const {
return _cornerReaction.value();
}
[[nodiscard]] rpl::producer<bool> 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<bool> _cornerReaction = true;
rpl::variable<bool> _spellcheckerEnabled = true;
rpl::variable<float64> _videoPlaybackSpeed = 1.;
float64 _voicePlaybackSpeed = 2.;

View File

@ -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()

View File

@ -473,6 +473,7 @@ private:
uint16 _mouseTextSymbol = 0;
bool _pressWasInactive = false;
bool _recountedAfterPendingResizedItems = false;
bool _useCornerReaction = false;
QPoint _trippleClickPoint;
base::Timer _trippleClickTimer;

View File

@ -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<const Element*> view,
QPoint position,
const TextState &reactionState) const {
if (!_useCornerReaction) {
return {};
}
const auto top = itemTop(view);
if (top < 0
|| !view->data()->canReact()

View File

@ -587,6 +587,7 @@ private:
std::unique_ptr<HistoryView::Reactions::Manager> _reactionsManager;
rpl::variable<HistoryItem*> _reactionsItem;
bool _useCornerReaction = false;
int _minHeight = 0;
int _visibleTop = 0;

View File

@ -978,6 +978,21 @@ void SetupMessages(
show.showBox(Box(ReactionsSettingsBox, controller));
});
AddSkip(inner, st::settingsSendTypeSkip);
inner->add(
object_ptr<Ui::Checkbox>(
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);
}