Allow fix chats order and auto switch (support).

This commit is contained in:
John Preston 2018-09-29 15:18:26 +03:00
parent 29432d5d6a
commit 25cefc6eab
16 changed files with 238 additions and 47 deletions

View File

@ -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<qint32>(_variables.sendFilesWay);
qint32 callsPeerToPeer = qint32(_variables.callsPeerToPeer.current());
qint32 sendSubmitWay = static_cast<qint32>(_variables.sendSubmitWay);
qint32 supportSwitch = static_cast<qint32>(_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<Ui::InputSubmitSettings>(
sendSubmitWay);
switch (uncheckedSendSubmitWay) {
case Ui::InputSubmitSettings::Enter:
case Ui::InputSubmitSettings::CtrlEnter: _variables.sendSubmitWay = uncheckedSendSubmitWay; break;
}
auto uncheckedSupportSwitch = static_cast<Support::SwitchSettings>(
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;

View File

@ -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<Calls::PeerToPeer> callsPeerToPeer
= Calls::PeerToPeer();
Ui::InputSubmitSettings sendSubmitWay;
Support::SwitchSettings supportSwitch;
bool supportFixChatsOrder = true;
};
rpl::event_stream<bool> _thirdSectionInfoEnabledValue;

View File

@ -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,

View File

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

View File

@ -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<History*> 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);

View File

@ -738,6 +738,8 @@ private:
bool readyToForward() const;
bool hasSilentToggle() const;
void handleSupportSwitch(not_null<History*> updated);
PeerData *_peer = nullptr;
ChannelId _channel = NoChannel;

View File

@ -40,8 +40,6 @@ int32 gLastUpdateCheck = 0;
bool gNoStartUpdate = false;
bool gStartToSettings = false;
bool gCtrlEnter = false;
uint32 gConnectionsInSession = 1;
QString gLoggedPhoneNumber;

View File

@ -64,7 +64,6 @@ DeclareSetting(QString, DialogHelperPath);
inline const QString &cDialogHelperPathFinal() {
return cDialogHelperPath().isEmpty() ? cExeDir() : cDialogHelperPath();
}
DeclareSetting(bool, CtrlEnter);
DeclareSetting(bool, AutoUpdate);

View File

@ -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<Ui::VerticalLayout*> 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<Ui::RadioenumGroup<SendByType>>(
cCtrlEnter() ? SendByType::CtrlEnter : SendByType::Enter);
auto wrap = object_ptr<Ui::VerticalLayout>(container);
const auto inner = wrap.data();
container->add(
@ -507,10 +504,9 @@ void SetupMessages(not_null<Ui::VerticalLayout*> 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<Ui::RadioenumGroup<SendByType>>(
Auth().settings().sendSubmitWay());
const auto add = [&](SendByType value, LangKey key) {
inner->add(
object_ptr<Ui::Radioenum<SendByType>>(
inner,
@ -522,18 +518,15 @@ void SetupMessages(not_null<Ui::VerticalLayout*> 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<Ui::VerticalLayout*> container) {
AddSkip(container);
}
void SetupSupport(not_null<Ui::VerticalLayout*> 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<Ui::VerticalLayout>(container);
const auto inner = wrap.data();
container->add(
object_ptr<Ui::OverrideMargins>(
container,
std::move(wrap),
QMargins(0, skip, 0, skip)));
const auto group = std::make_shared<Ui::RadioenumGroup<SwitchType>>(
Auth().settings().supportSwitch());
const auto add = [&](SwitchType value, const QString &label) {
inner->add(
object_ptr<Ui::Radioenum<SwitchType>>(
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<Ui::Checkbox>(
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<UserData*> 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);
}

View File

@ -161,15 +161,21 @@ not_null<Button*> AddButtonWithLabel(
void AddSubsectionTitle(
not_null<Ui::VerticalLayout*> container,
LangKey text) {
rpl::producer<QString> text) {
container->add(
object_ptr<Ui::FlatLabel>(
container,
Lang::Viewer(text),
std::move(text),
st::settingsSubsectionTitle),
st::settingsSubsectionTitlePadding);
}
void AddSubsectionTitle(
not_null<Ui::VerticalLayout*> container,
LangKey text) {
AddSubsectionTitle(container, Lang::Viewer(text));
}
void FillMenu(Fn<void(Type)> showOther, MenuCallback addAction) {
addAction(
lang(lng_settings_information),

View File

@ -94,6 +94,9 @@ void CreateRightLabel(
rpl::producer<QString> label,
const style::InfoProfileButton &st,
LangKey buttonText);
void AddSubsectionTitle(
not_null<Ui::VerticalLayout*> container,
rpl::producer<QString> text);
void AddSubsectionTitle(
not_null<Ui::VerticalLayout*> conatiner,
LangKey text);

View File

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

View File

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

View File

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

View File

@ -33,6 +33,13 @@ struct InstantReplaces {
};
enum class InputSubmitSettings {
Enter,
CtrlEnter,
Both,
None,
};
class FlatInput : public TWidgetHelper<QLineEdit>, 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);

View File

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