Show warning when user edits last seen first time.

This commit is contained in:
John Preston 2017-03-17 21:44:55 +03:00
parent fc77b0a51c
commit 7546245213
9 changed files with 88 additions and 25 deletions

View File

@ -75,10 +75,18 @@ public:
return _moreChatsLoaded;
}
bool lastSeenWarningSeen() const {
return _lastSeenWarningSeen;
}
void setLastSeenWarningSeen(bool lastSeenWarningSeen) {
_lastSeenWarningSeen = lastSeenWarningSeen;
}
private:
base::Variable<bool> _contactsLoaded = { false } ;
base::Variable<bool> _allChatsLoaded = { false };
base::Observable<void> _moreChatsLoaded;
bool _lastSeenWarningSeen = false;
};
Data &data() {

View File

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

View File

@ -41,7 +41,7 @@ TextParseOptions _confirmBoxTextOptions = {
Qt::LayoutDirectionAuto, // dir
};
ConfirmBox::ConfirmBox(QWidget*, const QString &text, base::lambda<void()> confirmedCallback, base::lambda<void()> cancelledCallback)
ConfirmBox::ConfirmBox(QWidget*, const QString &text, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> 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<void()> confi
init(text);
}
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda<void()> confirmedCallback, base::lambda<void()> cancelledCallback)
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> 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<void()> confirmedCallback, base::lambda<void()> cancelledCallback)
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> 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<void()> confirmedCallback, base::lambda<void()> cancelledCallback)
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> 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<void()> confirmedCallback, base::lambda<void()> cancelledCallback)
ConfirmBox::ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda_once<void()> confirmedCallback, base::lambda_once<void()> 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<void()> ConfirmBox::generateInformCallback(base::lambda<void()> closedCallback) {
auto callback = closedCallback;
return base::lambda_guarded(this, [this, callback] {
base::lambda_once<void()> ConfirmBox::generateInformCallback(base::lambda<void()> closedCallback) {
return base::lambda_guarded(this, [this, closedCallback] {
closeBox();
if (callback) {
callback();
if (closedCallback) {
closedCallback();
}
});
}

View File

@ -30,11 +30,11 @@ class FlatLabel;
class InformBox;
class ConfirmBox : public BoxContent, public ClickHandlerHost {
public:
ConfirmBox(QWidget*, const QString &text, base::lambda<void()> confirmedCallback = base::lambda<void()>(), base::lambda<void()> cancelledCallback = base::lambda<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda<void()> confirmedCallback = base::lambda<void()>(), base::lambda<void()> cancelledCallback = base::lambda<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda<void()> confirmedCallback = base::lambda<void()>(), base::lambda<void()> cancelledCallback = base::lambda<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda<void()> confirmedCallback = base::lambda<void()>(), base::lambda<void()> cancelledCallback = base::lambda<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda<void()> confirmedCallback = base::lambda<void()>(), base::lambda<void()> cancelledCallback = base::lambda<void()>());
ConfirmBox(QWidget*, const QString &text, base::lambda_once<void()> confirmedCallback = base::lambda_once<void()>(), base::lambda_once<void()> cancelledCallback = base::lambda_once<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, base::lambda_once<void()> confirmedCallback = base::lambda_once<void()>(), base::lambda_once<void()> cancelledCallback = base::lambda_once<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, base::lambda_once<void()> confirmedCallback = base::lambda_once<void()>(), base::lambda_once<void()> cancelledCallback = base::lambda_once<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const QString &cancelText, base::lambda_once<void()> confirmedCallback = base::lambda_once<void()>(), base::lambda_once<void()> cancelledCallback = base::lambda_once<void()>());
ConfirmBox(QWidget*, const QString &text, const QString &confirmText, const style::RoundButton &confirmStyle, const QString &cancelText, base::lambda_once<void()> confirmedCallback = base::lambda_once<void()>(), base::lambda_once<void()> cancelledCallback = base::lambda_once<void()>());
void updateLink();
@ -63,7 +63,7 @@ private:
struct InformBoxTag {
};
ConfirmBox(const InformBoxTag &, const QString &text, const QString &doneText, base::lambda<void()> closedCallback);
base::lambda<void()> generateInformCallback(base::lambda<void()> closedCallback);
base::lambda_once<void()> generateInformCallback(base::lambda<void()> closedCallback);
friend class InformBox;
void confirmed();
@ -86,8 +86,8 @@ private:
bool _confirmed = false;
bool _cancelled = false;
bool _strictCancel = false;
base::lambda<void()> _confirmedCallback;
base::lambda<void()> _cancelledCallback;
base::lambda_once<void()> _confirmedCallback;
base::lambda_once<void()> _cancelledCallback;
};

View File

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

View File

@ -54,6 +54,10 @@ public:
virtual QString exceptionBoxTitle(Exception exception) = 0;
virtual QString exceptionsDescription() = 0;
virtual void confirmSave(bool someAreDisallowed, base::lambda_once<void()> saveCallback) {
saveCallback();
}
virtual ~Controller() = default;
protected:

View File

@ -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<void()> saveCallback) {
if (someAreDisallowed && !AuthSession::Current().data().lastSeenWarningSeen()) {
auto weakBox = std::make_shared<QPointer<ConfirmBox>>();
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<ConfirmBox>(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();
}

View File

@ -61,6 +61,8 @@ public:
QString exceptionBoxTitle(Exception exception) override;
QString exceptionsDescription() override;
void confirmSave(bool someAreDisallowed, base::lambda_once<void()> saveCallback) override;
};
class GroupsInvitePrivacyController : public EditPrivacyBox::Controller, private base::Subscriber {

View File

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