diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 52dad65d5c..7d59ccfb1d 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -23,6 +23,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/section_widget.h" #include "chat_helpers/tabbed_selector.h" #include "boxes/send_files_box.h" +#include "ui/widgets/input_fields.h" +#include "support/support_common.h" #include "observer_peer.h" namespace { @@ -35,7 +37,9 @@ AuthSessionSettings::Variables::Variables() : sendFilesWay(SendFilesWay::Album) , selectorTab(ChatHelpers::SelectorTab::Emoji) , floatPlayerColumn(Window::Column::Second) -, floatPlayerCorner(RectPart::TopRight) { +, floatPlayerCorner(RectPart::TopRight) +, sendSubmitWay(Ui::InputSubmitSettings::Enter) +, supportSwitch(Support::SwitchSettings::None) { } QByteArray AuthSessionSettings::serialize() const { @@ -74,6 +78,9 @@ QByteArray AuthSessionSettings::serialize() const { stream << qint32(_variables.thirdSectionExtendedBy); stream << qint32(_variables.sendFilesWay); stream << qint32(_variables.callsPeerToPeer.current()); + stream << qint32(_variables.sendSubmitWay); + stream << qint32(_variables.supportSwitch); + stream << qint32(_variables.supportFixChatsOrder ? 1 : 0); } return result; } @@ -100,6 +107,10 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy; qint32 sendFilesWay = static_cast(_variables.sendFilesWay); qint32 callsPeerToPeer = qint32(_variables.callsPeerToPeer.current()); + qint32 sendSubmitWay = static_cast(_variables.sendSubmitWay); + qint32 supportSwitch = static_cast(_variables.supportSwitch); + qint32 supportFixChatsOrder = _variables.supportFixChatsOrder ? 1 : 0; + stream >> selectorTab; stream >> lastSeenWarningSeen; if (!stream.atEnd()) { @@ -154,6 +165,11 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) if (!stream.atEnd()) { stream >> callsPeerToPeer; } + if (!stream.atEnd()) { + stream >> sendSubmitWay; + stream >> supportSwitch; + stream >> supportFixChatsOrder; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for AuthSessionSettings::constructFromSerialized()")); @@ -206,6 +222,20 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) case Calls::PeerToPeer::Contacts: case Calls::PeerToPeer::Nobody: _variables.callsPeerToPeer = uncheckedCallsPeerToPeer; break; } + auto uncheckedSendSubmitWay = static_cast( + sendSubmitWay); + switch (uncheckedSendSubmitWay) { + case Ui::InputSubmitSettings::Enter: + case Ui::InputSubmitSettings::CtrlEnter: _variables.sendSubmitWay = uncheckedSendSubmitWay; break; + } + auto uncheckedSupportSwitch = static_cast( + supportSwitch); + switch (uncheckedSupportSwitch) { + case Support::SwitchSettings::None: + case Support::SwitchSettings::Next: + case Support::SwitchSettings::Previous: _variables.supportSwitch = uncheckedSupportSwitch; break; + } + _variables.supportFixChatsOrder = (supportFixChatsOrder ? 1 : 0); } void AuthSessionSettings::setTabbedSelectorSectionEnabled(bool enabled) { @@ -392,8 +422,8 @@ void AuthSession::checkAutoLockIn(TimeMs time) { } bool AuthSession::supportMode() const { -// return true; AssertIsDebug(); - return false; + return true; AssertIsDebug(); + return _user->phone().startsWith(qstr("424")); } AuthSession::~AuthSession() = default; diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index b0e0caeeda..4aea4755ba 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -15,6 +15,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class ApiWrap; enum class SendFilesWay; +namespace Ui { +enum class InputSubmitSettings; +} // namespace Ui + +namespace Support { +enum class SwitchSettings; +} // namespace Support + namespace Data { class Session; } // namespace Data @@ -68,6 +76,26 @@ public: SendFilesWay sendFilesWay() const { return _variables.sendFilesWay; } + void setSendSubmitWay(Ui::InputSubmitSettings value) { + _variables.sendSubmitWay = value; + } + Ui::InputSubmitSettings sendSubmitWay() const { + return _variables.sendSubmitWay; + } + + void setSupportSwitch(Support::SwitchSettings value) { + _variables.supportSwitch = value; + } + Support::SwitchSettings supportSwitch() const { + return _variables.supportSwitch; + } + void setSupportFixChatsOrder(bool fix) { + _variables.supportFixChatsOrder = fix; + } + bool supportFixChatsOrder() const { + return _variables.supportFixChatsOrder; + } + ChatHelpers::SelectorTab selectorTab() const { return _variables.selectorTab; } @@ -183,6 +211,10 @@ private: = kDefaultThirdColumnWidth; // per-window rpl::variable callsPeerToPeer = Calls::PeerToPeer(); + Ui::InputSubmitSettings sendSubmitWay; + + Support::SwitchSettings supportSwitch; + bool supportFixChatsOrder = true; }; rpl::event_stream _thirdSectionInfoEnabledValue; diff --git a/Telegram/SourceFiles/core/utils.h b/Telegram/SourceFiles/core/utils.h index 0cd40599ee..ac00f6a354 100644 --- a/Telegram/SourceFiles/core/utils.h +++ b/Telegram/SourceFiles/core/utils.h @@ -344,11 +344,6 @@ protected: QString translitRusEng(const QString &rus); QString rusKeyboardLayoutSwitch(const QString &from); -enum DBISendKey { - dbiskEnter = 0, - dbiskCtrlEnter = 1, -}; - enum DBINotifyView { dbinvShowPreview = 0, dbinvShowName = 1, diff --git a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp index 2f5ec41b5d..d6407e340f 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_entry.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_entry.cpp @@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "dialogs/dialogs_key.h" #include "dialogs/dialogs_indexed_list.h" #include "mainwidget.h" +#include "auth_session.h" #include "styles/style_dialogs.h" #include "history/history_item.h" #include "history/history.h" @@ -69,6 +70,11 @@ bool Entry::needUpdateInChatList() const { } void Entry::updateChatListSortPosition() { + if (Auth().supportMode() + && _sortKeyInChatList != 0 + && Auth().settings().supportFixChatsOrder()) { + return; + } _sortKeyInChatList = useProxyPromotion() ? ProxyPromotedDialogPos() : isPinnedDialog() diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index e0eba948fe..8fb5de07d3 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -69,6 +69,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "inline_bots/inline_results_widget.h" #include "chat_helpers/emoji_suggestions_widget.h" #include "core/crash_reports.h" +#include "support/support_common.h" #include "dialogs/dialogs_key.h" #include "styles/style_history.h" #include "styles/style_dialogs.h" @@ -753,6 +754,7 @@ HistoryWidget::HistoryWidget( if (cancelReply(lastKeyboardUsed) && !options.clearDraft) { onCloudDraftSave(); } + handleSupportSwitch(options.history); }, lifetime()); orderWidgets(); @@ -1958,12 +1960,9 @@ void HistoryWidget::clearAllLoadRequests() { } void HistoryWidget::updateFieldSubmitSettings() { - auto settings = Ui::InputField::SubmitSettings::Enter; - if (_isInlineBot) { - settings = Ui::InputField::SubmitSettings::None; - } else if (cCtrlEnter()) { - settings = Ui::InputField::SubmitSettings::CtrlEnter; - } + const auto settings = _isInlineBot + ? Ui::InputField::SubmitSettings::None + : Auth().settings().sendSubmitWay(); _field->setSubmitSettings(settings); } @@ -3682,6 +3681,15 @@ bool HistoryWidget::hasSilentToggle() const { && !Auth().data().notifySilentPostsUnknown(_peer); } +void HistoryWidget::handleSupportSwitch(not_null updated) { + if (_history != updated || !Auth().supportMode()) { + return; + } + crl::on_main(this, [to = Auth().settings().supportSwitch()] { + Support::PerformSwitch(to); + }); +} + void HistoryWidget::inlineBotResolveDone( const MTPcontacts_ResolvedPeer &result) { Expects(result.type() == mtpc_contacts_resolvedPeer); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index e2a5cbd140..dbe3894075 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -738,6 +738,8 @@ private: bool readyToForward() const; bool hasSilentToggle() const; + void handleSupportSwitch(not_null updated); + PeerData *_peer = nullptr; ChannelId _channel = NoChannel; diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 48c947d0b8..aff25ee3ad 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -40,8 +40,6 @@ int32 gLastUpdateCheck = 0; bool gNoStartUpdate = false; bool gStartToSettings = false; -bool gCtrlEnter = false; - uint32 gConnectionsInSession = 1; QString gLoggedPhoneNumber; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 0db5b7f76a..4ece78ab87 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -64,7 +64,6 @@ DeclareSetting(QString, DialogHelperPath); inline const QString &cDialogHelperPathFinal() { return cDialogHelperPath().isEmpty() ? cExeDir() : cDialogHelperPath(); } -DeclareSetting(bool, CtrlEnter); DeclareSetting(bool, AutoUpdate); diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 72fecd6b99..c1dd430e0b 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/local_storage_box.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" +#include "ui/widgets/input_fields.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/labels.h" #include "ui/effects/radial_animation.h" @@ -25,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/localstorage.h" #include "core/file_utilities.h" #include "data/data_session.h" +#include "support/support_common.h" #include "auth_session.h" #include "mainwidget.h" #include "styles/style_settings.h" @@ -491,14 +493,9 @@ void SetupMessages(not_null container) { AddSkip(container, st::settingsSendTypeSkip); - enum class SendByType { - Enter, - CtrlEnter, - }; + using SendByType = Ui::InputSubmitSettings; const auto skip = st::settingsSendTypeSkip; - const auto group = std::make_shared>( - cCtrlEnter() ? SendByType::CtrlEnter : SendByType::Enter); auto wrap = object_ptr(container); const auto inner = wrap.data(); container->add( @@ -507,10 +504,9 @@ void SetupMessages(not_null container) { std::move(wrap), QMargins(0, skip, 0, skip))); - const auto add = [&]( - SendByType value, - LangKey key, - style::margins padding) { + const auto group = std::make_shared>( + Auth().settings().sendSubmitWay()); + const auto add = [&](SendByType value, LangKey key) { inner->add( object_ptr>( inner, @@ -522,18 +518,15 @@ void SetupMessages(not_null container) { }; const auto small = st::settingsSendTypePadding; const auto top = skip; - add( - SendByType::Enter, - lng_settings_send_enter, - { small.left(), small.top() + top, small.right(), small.bottom() }); + add(SendByType::Enter, lng_settings_send_enter); add( SendByType::CtrlEnter, ((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_settings_send_cmdenter - : lng_settings_send_ctrlenter), - { small.left(), small.top(), small.right(), small.bottom() + top }); + : lng_settings_send_ctrlenter)); + group->setChangedCallback([](SendByType value) { - cSetCtrlEnter(value == SendByType::CtrlEnter); + Auth().settings().setSendSubmitWay(value); if (App::main()) { App::main()->ctrlEnterSubmitUpdated(); } @@ -912,6 +905,65 @@ void SetupThemeOptions(not_null container) { AddSkip(container); } +void SetupSupport(not_null container) { + AddDivider(container); + AddSkip(container); + + AddSubsectionTitle(container, rpl::single(qsl("Support settings"))); + + AddSkip(container, st::settingsSendTypeSkip); + + using SwitchType = Support::SwitchSettings; + + const auto skip = st::settingsSendTypeSkip; + auto wrap = object_ptr(container); + const auto inner = wrap.data(); + container->add( + object_ptr( + container, + std::move(wrap), + QMargins(0, skip, 0, skip))); + + const auto group = std::make_shared>( + Auth().settings().supportSwitch()); + const auto add = [&](SwitchType value, const QString &label) { + inner->add( + object_ptr>( + inner, + group, + value, + label, + st::settingsSendType), + st::settingsSendTypePadding); + }; + add(SwitchType::None, "Just send the reply"); + add(SwitchType::Next, "Send and switch to next"); + add(SwitchType::Previous, "Send and switch to previous"); + group->setChangedCallback([](SwitchType value) { + Auth().settings().setSupportSwitch(value); + Local::writeUserSettings(); + }); + + AddSkip(inner, st::settingsCheckboxesSkip); + + base::ObservableViewer( + inner->add( + object_ptr( + inner, + "Fix chats order", + Auth().settings().supportFixChatsOrder(), + st::settingsSendType), + st::settingsSendTypePadding + )->checkedChanged + ) | rpl::start_with_next([](bool fix) { + Auth().settings().setSupportFixChatsOrder(fix); + Local::writeUserSettings(); + }, inner->lifetime()); + + + AddSkip(inner, st::settingsCheckboxesSkip); +} + Chat::Chat(QWidget *parent, not_null self) : Section(parent) , _self(self) { @@ -925,6 +977,9 @@ void Chat::setupContent() { SetupChatBackground(content); SetupStickersEmoji(content); SetupMessages(content); + if (Auth().supportMode()) { + SetupSupport(content); + } Ui::ResizeFitChild(this, content); } diff --git a/Telegram/SourceFiles/settings/settings_common.cpp b/Telegram/SourceFiles/settings/settings_common.cpp index 1397ef53a3..52845cbf83 100644 --- a/Telegram/SourceFiles/settings/settings_common.cpp +++ b/Telegram/SourceFiles/settings/settings_common.cpp @@ -161,15 +161,21 @@ not_null AddButtonWithLabel( void AddSubsectionTitle( not_null container, - LangKey text) { + rpl::producer text) { container->add( object_ptr( container, - Lang::Viewer(text), + std::move(text), st::settingsSubsectionTitle), st::settingsSubsectionTitlePadding); } +void AddSubsectionTitle( + not_null container, + LangKey text) { + AddSubsectionTitle(container, Lang::Viewer(text)); +} + void FillMenu(Fn showOther, MenuCallback addAction) { addAction( lang(lng_settings_information), diff --git a/Telegram/SourceFiles/settings/settings_common.h b/Telegram/SourceFiles/settings/settings_common.h index 28ad856d3e..de21aaf1a9 100644 --- a/Telegram/SourceFiles/settings/settings_common.h +++ b/Telegram/SourceFiles/settings/settings_common.h @@ -94,6 +94,9 @@ void CreateRightLabel( rpl::producer label, const style::InfoProfileButton &st, LangKey buttonText); +void AddSubsectionTitle( + not_null container, + rpl::producer text); void AddSubsectionTitle( not_null conatiner, LangKey text); diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index d701cb8139..b07ba56309 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_drafts.h" #include "boxes/send_files_box.h" #include "window/themes/window_theme.h" +#include "ui/widgets/input_fields.h" #include "export/export_settings.h" #include "core/crash_reports.h" #include "core/update_checker.h" @@ -522,7 +523,7 @@ enum { dbiDcOptionOldOld = 0x02, dbiChatSizeMax = 0x03, dbiMutePeer = 0x04, - dbiSendKey = 0x05, + dbiSendKeyOld = 0x05, dbiAutoStart = 0x06, dbiStartMinimized = 0x07, dbiSoundNotify = 0x08, @@ -1432,13 +1433,19 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting if (!_checkStreamStatus(stream)) return false; } break; - case dbiSendKey: { + case dbiSendKeyOld: { qint32 v; stream >> v; if (!_checkStreamStatus(stream)) return false; - cSetCtrlEnter(v == dbiskCtrlEnter); - if (App::main()) App::main()->ctrlEnterSubmitUpdated(); + using SendSettings = Ui::InputSubmitSettings; + const auto unchecked = static_cast(v); + + if (unchecked != SendSettings::Enter + && unchecked != SendSettings::CtrlEnter) { + return false; + } + GetStoredAuthSessionCache().setSendSubmitWay(unchecked); } break; case dbiCatsAndDogs: { // deprecated @@ -1945,7 +1952,6 @@ void _writeUserSettings() { } EncryptedDescriptor data(size); - data.stream << quint32(dbiSendKey) << qint32(cCtrlEnter() ? dbiskCtrlEnter : dbiskEnter); data.stream << quint32(dbiTileBackground) << qint32(Window::Theme::Background()->tileDay() ? 1 : 0) diff --git a/Telegram/SourceFiles/support/support_common.cpp b/Telegram/SourceFiles/support/support_common.cpp new file mode 100644 index 0000000000..e1ca3e60a3 --- /dev/null +++ b/Telegram/SourceFiles/support/support_common.cpp @@ -0,0 +1,27 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "support/support_common.h" + +#include "shortcuts.h" + +namespace Support { + +void PerformSwitch(SwitchSettings value) { + switch (value) { + case SwitchSettings::Next: + Shortcuts::launch("next_chat"); + break; + case SwitchSettings::Previous: + Shortcuts::launch("previous_chat"); + break; + default: + break; + } +} + +} // namespace Support diff --git a/Telegram/SourceFiles/support/support_common.h b/Telegram/SourceFiles/support/support_common.h new file mode 100644 index 0000000000..baba305d58 --- /dev/null +++ b/Telegram/SourceFiles/support/support_common.h @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Support { + +enum class SwitchSettings { + None, + Next, + Previous, +}; + +void PerformSwitch(SwitchSettings value); + +} // namespace Support diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.h b/Telegram/SourceFiles/ui/widgets/input_fields.h index 863fd11712..e418da7944 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.h +++ b/Telegram/SourceFiles/ui/widgets/input_fields.h @@ -33,6 +33,13 @@ struct InstantReplaces { }; +enum class InputSubmitSettings { + Enter, + CtrlEnter, + Both, + None, +}; + class FlatInput : public TWidgetHelper, private base::Subscriber { Q_OBJECT @@ -258,12 +265,7 @@ public: bool isUndoAvailable() const; bool isRedoAvailable() const; - enum class SubmitSettings { - None, - Enter, - CtrlEnter, - Both, - }; + using SubmitSettings = InputSubmitSettings; void setSubmitSettings(SubmitSettings settings); void customUpDown(bool isCustom); void customTab(bool isCustom); diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index f02296c8a9..f844f31fe5 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -576,6 +576,8 @@ <(src_loc)/storage/storage_sparse_ids_list.h <(src_loc)/storage/storage_user_photos.cpp <(src_loc)/storage/storage_user_photos.h +<(src_loc)/support/support_common.cpp +<(src_loc)/support/support_common.h <(src_loc)/ui/effects/cross_animation.cpp <(src_loc)/ui/effects/cross_animation.h <(src_loc)/ui/effects/fade_animation.cpp