diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index 120032c59..5d74ce7b9 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -75,10 +75,18 @@ public: return _moreChatsLoaded; } + bool lastSeenWarningSeen() const { + return _lastSeenWarningSeen; + } + void setLastSeenWarningSeen(bool lastSeenWarningSeen) { + _lastSeenWarningSeen = lastSeenWarningSeen; + } + private: base::Variable _contactsLoaded = { false } ; base::Variable _allChatsLoaded = { false }; base::Observable _moreChatsLoaded; + bool _lastSeenWarningSeen = false; }; Data &data() { diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index bd6cff7fc..e752fb034 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -585,13 +585,13 @@ colorValueInput: InputField(defaultInputField) { colorResultInput: InputField(colorValueInput) { } -editPrivacyOptionMargin: margins(23px, 0px, 21px, 10px); +editPrivacyOptionMargin: margins(23px, 8px, 21px, -3px); editPrivacyPadding: margins(23px, 0px, 21px, 0px); editPrivacyTitle: FlatLabel(defaultFlatLabel) { width: 320px; textFg: boxTitleFg; maxHeight: 46px; - margin: margins(0px, 13px, 0px, 10px); + margin: margins(0px, 13px, 0px, 7px); style: TextStyle(defaultTextStyle) { font: boxTitleFont; linkFont: boxTitleFont; @@ -603,4 +603,4 @@ editPrivacyLabel: FlatLabel(defaultFlatLabel) { textFg: membersAboutLimitFg; style: defaultTextStyle; } -editPrivacyLinkMargin: margins(0px, 0px, 0px, 10px); +editPrivacyLinkMargin: margins(0px, 0px, 0px, 8px); diff --git a/Telegram/SourceFiles/boxes/confirmbox.cpp b/Telegram/SourceFiles/boxes/confirmbox.cpp index 4c75bae89..c602e338a 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.cpp +++ b/Telegram/SourceFiles/boxes/confirmbox.cpp @@ -41,7 +41,7 @@ TextParseOptions _confirmBoxTextOptions = { Qt::LayoutDirectionAuto, // dir }; -ConfirmBox::ConfirmBox(QWidget*, const QString &text, base::lambda confirmedCallback, base::lambda cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) : _confirmText(lang(lng_box_ok)) , _cancelText(lang(lng_cancel)) , _confirmStyle(st::defaultBoxButton) @@ -51,7 +51,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, base::lambda confi init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda confirmedCallback, base::lambda cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) : _confirmText(confirmText) , _cancelText(lang(lng_cancel)) , _confirmStyle(st::defaultBoxButton) @@ -61,7 +61,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda confirmedCallback, base::lambda cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) : _confirmText(confirmText) , _cancelText(lang(lng_cancel)) , _confirmStyle(confirmStyle) @@ -71,7 +71,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda confirmedCallback, base::lambda cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) : _confirmText(confirmText) , _cancelText(cancelText) , _confirmStyle(st::defaultBoxButton) @@ -81,7 +81,7 @@ ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText init(text); } -ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda confirmedCallback, base::lambda cancelledCallback) +ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda_once confirmedCallback, base::lambda_once cancelledCallback) : _confirmText(confirmText) , _cancelText(cancelText) , _confirmStyle(st::defaultBoxButton) @@ -101,12 +101,11 @@ ConfirmBox::ConfirmBox(const InformBoxTag &, const QString &text, const QString init(text); } -base::lambda ConfirmBox::generateInformCallback(base::lambda closedCallback) { - auto callback = closedCallback; - return base::lambda_guarded(this, [this, callback] { +base::lambda_once ConfirmBox::generateInformCallback(base::lambda closedCallback) { + return base::lambda_guarded(this, [this, closedCallback] { closeBox(); - if (callback) { - callback(); + if (closedCallback) { + closedCallback(); } }); } diff --git a/Telegram/SourceFiles/boxes/confirmbox.h b/Telegram/SourceFiles/boxes/confirmbox.h index f0214b8a3..f5658930c 100644 --- a/Telegram/SourceFiles/boxes/confirmbox.h +++ b/Telegram/SourceFiles/boxes/confirmbox.h @@ -30,11 +30,11 @@ class FlatLabel; class InformBox; class ConfirmBox : public BoxContent, public ClickHandlerHost { public: - ConfirmBox(QWidget*, const QString &text, base::lambda confirmedCallback = base::lambda(), base::lambda cancelledCallback = base::lambda()); - ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda confirmedCallback = base::lambda(), base::lambda cancelledCallback = base::lambda()); - ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda confirmedCallback = base::lambda(), base::lambda cancelledCallback = base::lambda()); - ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda confirmedCallback = base::lambda(), base::lambda cancelledCallback = base::lambda()); - ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda confirmedCallback = base::lambda(), base::lambda cancelledCallback = base::lambda()); + ConfirmBox(QWidget*, const QString &text, base::lambda_once confirmedCallback = base::lambda_once(), base::lambda_once cancelledCallback = base::lambda_once()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda_once confirmedCallback = base::lambda_once(), base::lambda_once cancelledCallback = base::lambda_once()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda_once confirmedCallback = base::lambda_once(), base::lambda_once cancelledCallback = base::lambda_once()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda_once confirmedCallback = base::lambda_once(), base::lambda_once cancelledCallback = base::lambda_once()); + ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda_once confirmedCallback = base::lambda_once(), base::lambda_once cancelledCallback = base::lambda_once()); void updateLink(); @@ -63,7 +63,7 @@ private: struct InformBoxTag { }; ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, base::lambda closedCallback); - base::lambda generateInformCallback(base::lambda closedCallback); + base::lambda_once generateInformCallback(base::lambda closedCallback); friend class InformBox; void confirmed(); @@ -86,8 +86,8 @@ private: bool _confirmed = false; bool _cancelled = false; bool _strictCancel = false; - base::lambda _confirmedCallback; - base::lambda _cancelledCallback; + base::lambda_once _confirmedCallback; + base::lambda_once _cancelledCallback; }; diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 2afdfc41f..4459d7e12 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -99,6 +99,10 @@ public: return _option->checked(); } + QMargins getMargins() const override { + return _option->getMargins(); + } + protected: int resizeGetHeight(int newWidth) override; @@ -117,8 +121,8 @@ int EditPrivacyBox::OptionWidget::resizeGetHeight(int newWidth) { _option->resizeToNaturalWidth(newWidth); auto optionTextLeft = st::defaultBoxCheckbox.textPosition.x(); _description->resizeToWidth(newWidth - optionTextLeft); - _option->moveToLeft(0, 0); - _description->moveToLeft(optionTextLeft, _option->bottomNoMargins()); + _option->moveToLeft(getMargins().left(), getMargins().top()); + _description->moveToLeft(optionTextLeft + getMargins().left(), _option->bottomNoMargins()); return _description->bottomNoMargins(); } @@ -332,8 +336,11 @@ void EditPrivacyBox::createWidgets() { clearButtons(); addButton(lang(lng_settings_save), [this] { - App::api()->savePrivacy(_controller->key(), collectResult()); - closeBox(); + auto someAreDisallowed = (_option != Option::Everyone) || !_neverUsers.empty(); + _controller->confirmSave(someAreDisallowed, base::lambda_guarded(this, [this] { + App::api()->savePrivacy(_controller->key(), collectResult()); + closeBox(); + })); }); addButton(lang(lng_cancel), [this] { closeBox(); }); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.h b/Telegram/SourceFiles/boxes/edit_privacy_box.h index 550231796..bd6c774f4 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.h +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.h @@ -54,6 +54,10 @@ public: virtual QString exceptionBoxTitle(Exception exception) = 0; virtual QString exceptionsDescription() = 0; + virtual void confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) { + saveCallback(); + } + virtual ~Controller() = default; protected: diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index f42109cd8..9fae9f5ba 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -24,6 +24,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "observer_peer.h" #include "mainwidget.h" +#include "auth_session.h" +#include "storage/localstorage.h" +#include "boxes/confirmbox.h" namespace Settings { namespace { @@ -260,6 +263,24 @@ QString LastSeenPrivacyController::exceptionsDescription() { return lang(lng_edit_privacy_lastseen_exceptions); } +void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) { + if (someAreDisallowed && !AuthSession::Current().data().lastSeenWarningSeen()) { + auto weakBox = std::make_shared>(); + auto callback = [weakBox, saveCallback = std::move(saveCallback)]() mutable { + if (auto box = *weakBox) { + box->closeBox(); + } + saveCallback(); + AuthSession::Current().data().setLastSeenWarningSeen(true); + Local::writeUserSettings(); + }; + auto box = Box(lang(lng_edit_privacy_lastseen_description), lang(lng_continue), lang(lng_cancel), std::move(callback)); + *weakBox = Ui::show(std::move(box), KeepOtherLayers); + } else { + saveCallback(); + } +} + MTPInputPrivacyKey GroupsInvitePrivacyController::key() { return MTP_inputPrivacyKeyChatInvite(); } diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 7c02867f3..efb47cdb3 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -61,6 +61,8 @@ public: QString exceptionBoxTitle(Exception exception) override; QString exceptionsDescription() override; + void confirmSave(bool someAreDisallowed, base::lambda_once saveCallback) override; + }; class GroupsInvitePrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { diff --git a/Telegram/SourceFiles/storage/localstorage.cpp b/Telegram/SourceFiles/storage/localstorage.cpp index 75e2bcf7c..04f0650ec 100644 --- a/Telegram/SourceFiles/storage/localstorage.cpp +++ b/Telegram/SourceFiles/storage/localstorage.cpp @@ -48,6 +48,8 @@ using FileKey = quint64; constexpr char tdfMagic[] = { 'T', 'D', 'F', '$' }; constexpr int tdfMagicLen = sizeof(tdfMagic); +bool _cacheLastSeenWarningSeen = false; + QString toFilePart(FileKey val) { QString result; result.reserve(0x10); @@ -572,6 +574,7 @@ enum { dbiUseExternalVideoPlayer = 0x49, dbiDcOptions = 0x4a, dbiMtpAuthorization = 0x4b, + dbiLastSeenWarningSeen = 0x4c, dbiEncryptedWithSalt = 333, dbiEncrypted = 444, @@ -917,6 +920,7 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting Messenger::Instance().setMtpMainDcId(dcId); if (userId) { Messenger::Instance().authSessionCreate(UserId(userId)); + AuthSession::Current().data().setLastSeenWarningSeen(_cacheLastSeenWarningSeen); } } break; @@ -936,6 +940,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting if (!_checkStreamStatus(stream)) return false; Messenger::Instance().setMtpAuthorization(serialized); + if (AuthSession::Exists()) { + AuthSession::Current().data().setLastSeenWarningSeen(_cacheLastSeenWarningSeen); + } } break; case dbiAutoStart: { @@ -1083,6 +1090,18 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting Global::SetDialogsWidthRatio(v / 1000000.); } break; + case dbiLastSeenWarningSeen: { + qint32 v; + stream >> v; + if (!_checkStreamStatus(stream)) return false; + + if (AuthSession::Exists()) { + AuthSession::Current().data().setLastSeenWarningSeen(v == 1); + } else { + _cacheLastSeenWarningSeen = (v == 1); + } + } break; + case dbiWorkMode: { qint32 v; stream >> v; @@ -1728,6 +1747,8 @@ void _writeUserSettings() { data.stream << quint32(dbiModerateMode) << qint32(Global::ModerateModeEnabled() ? 1 : 0); data.stream << quint32(dbiAutoPlay) << qint32(cAutoPlayGif() ? 1 : 0); data.stream << quint32(dbiDialogsWidthRatio) << qint32(snap(qRound(Global::DialogsWidthRatio() * 1000000), 0, 1000000)); + auto lastSeenWarningSeen = (AuthSession::Exists() ? AuthSession::Current().data().lastSeenWarningSeen() : _cacheLastSeenWarningSeen); + data.stream << quint32(dbiLastSeenWarningSeen) << qint32(lastSeenWarningSeen ? 1 : 0); data.stream << quint32(dbiUseExternalVideoPlayer) << qint32(cUseExternalVideoPlayer()); { @@ -2329,6 +2350,7 @@ void reset() { _savedGifsKey = 0; _backgroundKey = _userSettingsKey = _recentHashtagsAndBotsKey = _savedPeersKey = 0; _oldMapVersion = _oldSettingsVersion = 0; + _cacheLastSeenWarningSeen = false; _mapChanged = true; _writeMap(WriteMapNow);