Added ability to remember last choice in delete messages box.
This commit is contained in:
		
							parent
							
								
									a043e22622
								
							
						
					
					
						commit
						994d789c60
					
				
					 5 changed files with 63 additions and 1 deletions
				
			
		| 
						 | 
					@ -166,6 +166,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
"lng_scam_badge" = "SCAM";
 | 
					"lng_scam_badge" = "SCAM";
 | 
				
			||||||
"lng_fake_badge" = "FAKE";
 | 
					"lng_fake_badge" = "FAKE";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"lng_remember" = "Remember this choice";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"lng_channels_limit_title" = "Too Many Communities";
 | 
					"lng_channels_limit_title" = "Too Many Communities";
 | 
				
			||||||
"lng_channels_limit1#one" = "You are a member of **{count}** groups and channels.";
 | 
					"lng_channels_limit1#one" = "You are a member of **{count}** groups and channels.";
 | 
				
			||||||
"lng_channels_limit1#other" = "You are a member of **{count}** groups and channels.";
 | 
					"lng_channels_limit1#other" = "You are a member of **{count}** groups and channels.";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "api/api_messages_search.h"
 | 
					#include "api/api_messages_search.h"
 | 
				
			||||||
#include "base/unixtime.h"
 | 
					#include "base/unixtime.h"
 | 
				
			||||||
#include "core/application.h"
 | 
					#include "core/application.h"
 | 
				
			||||||
 | 
					#include "core/core_settings.h"
 | 
				
			||||||
#include "data/data_channel.h"
 | 
					#include "data/data_channel.h"
 | 
				
			||||||
#include "data/data_chat.h"
 | 
					#include "data/data_chat.h"
 | 
				
			||||||
#include "data/data_histories.h"
 | 
					#include "data/data_histories.h"
 | 
				
			||||||
| 
						 | 
					@ -27,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "ui/widgets/buttons.h"
 | 
					#include "ui/widgets/buttons.h"
 | 
				
			||||||
#include "ui/widgets/checkbox.h"
 | 
					#include "ui/widgets/checkbox.h"
 | 
				
			||||||
#include "ui/widgets/labels.h"
 | 
					#include "ui/widgets/labels.h"
 | 
				
			||||||
 | 
					#include "ui/wrap/slide_wrap.h"
 | 
				
			||||||
#include "styles/style_layers.h"
 | 
					#include "styles/style_layers.h"
 | 
				
			||||||
#include "styles/style_boxes.h"
 | 
					#include "styles/style_boxes.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -229,11 +231,32 @@ void DeleteMessagesBox::prepare() {
 | 
				
			||||||
			auto count = int(_ids.size());
 | 
								auto count = int(_ids.size());
 | 
				
			||||||
			if (hasScheduledMessages()) {
 | 
								if (hasScheduledMessages()) {
 | 
				
			||||||
			} else if (auto revoke = revokeText(peer)) {
 | 
								} else if (auto revoke = revokeText(peer)) {
 | 
				
			||||||
 | 
									const auto &settings = Core::App().settings();
 | 
				
			||||||
 | 
									const auto revokeByDefault =
 | 
				
			||||||
 | 
										!settings.rememberedDeleteMessageOnlyForYou();
 | 
				
			||||||
				_revoke.create(
 | 
									_revoke.create(
 | 
				
			||||||
					this,
 | 
										this,
 | 
				
			||||||
					revoke->checkbox,
 | 
										revoke->checkbox,
 | 
				
			||||||
					true,
 | 
										revokeByDefault,
 | 
				
			||||||
					st::defaultBoxCheckbox);
 | 
										st::defaultBoxCheckbox);
 | 
				
			||||||
 | 
									_revokeRemember.create(
 | 
				
			||||||
 | 
										this,
 | 
				
			||||||
 | 
										object_ptr<Ui::Checkbox>(
 | 
				
			||||||
 | 
											this,
 | 
				
			||||||
 | 
											tr::lng_remember(),
 | 
				
			||||||
 | 
											false,
 | 
				
			||||||
 | 
											st::defaultBoxCheckbox));
 | 
				
			||||||
 | 
									_revokeRemember->hide(anim::type::instant);
 | 
				
			||||||
 | 
									_revoke->checkedValue(
 | 
				
			||||||
 | 
									) | rpl::start_with_next([=](bool checked) {
 | 
				
			||||||
 | 
										_revokeRemember->toggle(
 | 
				
			||||||
 | 
											checked != revokeByDefault,
 | 
				
			||||||
 | 
											anim::type::normal);
 | 
				
			||||||
 | 
									}, _revokeRemember->lifetime());
 | 
				
			||||||
 | 
									_revokeRemember->heightValue(
 | 
				
			||||||
 | 
									) | rpl::start_with_next([=](int h) {
 | 
				
			||||||
 | 
										setDimensions(st::boxWidth, _fullHeight + h);
 | 
				
			||||||
 | 
									}, lifetime());
 | 
				
			||||||
				appendDetails(std::move(revoke->description));
 | 
									appendDetails(std::move(revoke->description));
 | 
				
			||||||
			} else if (peer->isChannel()) {
 | 
								} else if (peer->isChannel()) {
 | 
				
			||||||
				if (peer->isMegagroup()) {
 | 
									if (peer->isMegagroup()) {
 | 
				
			||||||
| 
						 | 
					@ -309,6 +332,7 @@ void DeleteMessagesBox::prepare() {
 | 
				
			||||||
			+ st::boxLittleSkip;
 | 
								+ st::boxLittleSkip;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	setDimensions(st::boxWidth, fullHeight);
 | 
						setDimensions(st::boxWidth, fullHeight);
 | 
				
			||||||
 | 
						_fullHeight = fullHeight;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool DeleteMessagesBox::hasScheduledMessages() const {
 | 
					bool DeleteMessagesBox::hasScheduledMessages() const {
 | 
				
			||||||
| 
						 | 
					@ -450,6 +474,11 @@ void DeleteMessagesBox::resizeEvent(QResizeEvent *e) {
 | 
				
			||||||
		_revoke->resizeToNaturalWidth(availableWidth);
 | 
							_revoke->resizeToNaturalWidth(availableWidth);
 | 
				
			||||||
		_revoke->moveToLeft(padding.left(), top);
 | 
							_revoke->moveToLeft(padding.left(), top);
 | 
				
			||||||
		top += _revoke->heightNoMargins() + st::boxLittleSkip;
 | 
							top += _revoke->heightNoMargins() + st::boxLittleSkip;
 | 
				
			||||||
 | 
							if (_revokeRemember) {
 | 
				
			||||||
 | 
								_revokeRemember->resizeToNaturalWidth(availableWidth);
 | 
				
			||||||
 | 
								_revokeRemember->moveToLeft(padding.left(),top);
 | 
				
			||||||
 | 
								top += _revokeRemember->heightNoMargins();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (_autoDeleteSettings) {
 | 
						if (_autoDeleteSettings) {
 | 
				
			||||||
		top += st::boxMediumSkip - st::boxLittleSkip;
 | 
							top += st::boxMediumSkip - st::boxLittleSkip;
 | 
				
			||||||
| 
						 | 
					@ -469,6 +498,14 @@ void DeleteMessagesBox::keyPressEvent(QKeyEvent *e) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DeleteMessagesBox::deleteAndClear() {
 | 
					void DeleteMessagesBox::deleteAndClear() {
 | 
				
			||||||
 | 
						if (_revoke
 | 
				
			||||||
 | 
							&& _revokeRemember
 | 
				
			||||||
 | 
							&& _revokeRemember->toggled()
 | 
				
			||||||
 | 
							&& _revokeRemember->entity()->checked()) {
 | 
				
			||||||
 | 
							Core::App().settings().setRememberedDeleteMessageOnlyForYou(
 | 
				
			||||||
 | 
								!_revoke->checked());
 | 
				
			||||||
 | 
							Core::App().saveSettingsDelayed();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	const auto revoke = _revoke ? _revoke->checked() : _revokeForBot;
 | 
						const auto revoke = _revoke ? _revoke->checked() : _revokeForBot;
 | 
				
			||||||
	const auto session = _session;
 | 
						const auto session = _session;
 | 
				
			||||||
	const auto invokeCallbackAndClose = [&] {
 | 
						const auto invokeCallbackAndClose = [&] {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,8 @@ namespace Ui {
 | 
				
			||||||
class Checkbox;
 | 
					class Checkbox;
 | 
				
			||||||
class FlatLabel;
 | 
					class FlatLabel;
 | 
				
			||||||
class LinkButton;
 | 
					class LinkButton;
 | 
				
			||||||
 | 
					template <typename Widget>
 | 
				
			||||||
 | 
					class SlideWrap;
 | 
				
			||||||
} // namespace Ui
 | 
					} // namespace Ui
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DeleteMessagesBox final : public Ui::BoxContent {
 | 
					class DeleteMessagesBox final : public Ui::BoxContent {
 | 
				
			||||||
| 
						 | 
					@ -73,11 +75,14 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	object_ptr<Ui::FlatLabel> _text = { nullptr };
 | 
						object_ptr<Ui::FlatLabel> _text = { nullptr };
 | 
				
			||||||
	object_ptr<Ui::Checkbox> _revoke = { nullptr };
 | 
						object_ptr<Ui::Checkbox> _revoke = { nullptr };
 | 
				
			||||||
 | 
						object_ptr<Ui::SlideWrap<Ui::Checkbox>> _revokeRemember = { nullptr };
 | 
				
			||||||
	object_ptr<Ui::Checkbox> _banUser = { nullptr };
 | 
						object_ptr<Ui::Checkbox> _banUser = { nullptr };
 | 
				
			||||||
	object_ptr<Ui::Checkbox> _reportSpam = { nullptr };
 | 
						object_ptr<Ui::Checkbox> _reportSpam = { nullptr };
 | 
				
			||||||
	object_ptr<Ui::Checkbox> _deleteAll = { nullptr };
 | 
						object_ptr<Ui::Checkbox> _deleteAll = { nullptr };
 | 
				
			||||||
	object_ptr<Ui::LinkButton> _autoDeleteSettings = { nullptr };
 | 
						object_ptr<Ui::LinkButton> _autoDeleteSettings = { nullptr };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						int _fullHeight = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Fn<void()> _deleteConfirmedCallback;
 | 
						Fn<void()> _deleteConfirmedCallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -274,6 +274,9 @@ QByteArray Settings::serialize() const {
 | 
				
			||||||
		for (const auto &lang : _skipTranslationForLanguages) {
 | 
							for (const auto &lang : _skipTranslationForLanguages) {
 | 
				
			||||||
			stream << quint64(lang);
 | 
								stream << quint64(lang);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							stream
 | 
				
			||||||
 | 
								<< qint32(_rememberedDeleteMessageOnlyForYou ? 1 : 0);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -370,6 +373,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
 | 
				
			||||||
	qint32 legacySkipTranslationForLanguage = _translateButtonEnabled ? 1 : 0;
 | 
						qint32 legacySkipTranslationForLanguage = _translateButtonEnabled ? 1 : 0;
 | 
				
			||||||
	qint32 skipTranslationForLanguagesCount = 0;
 | 
						qint32 skipTranslationForLanguagesCount = 0;
 | 
				
			||||||
	std::vector<int> skipTranslationForLanguages;
 | 
						std::vector<int> skipTranslationForLanguages;
 | 
				
			||||||
 | 
						qint32 rememberedDeleteMessageOnlyForYou = _rememberedDeleteMessageOnlyForYou ? 1 : 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	stream >> themesAccentColors;
 | 
						stream >> themesAccentColors;
 | 
				
			||||||
	if (!stream.atEnd()) {
 | 
						if (!stream.atEnd()) {
 | 
				
			||||||
| 
						 | 
					@ -579,6 +583,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
 | 
				
			||||||
				skipTranslationForLanguages.emplace_back(language);
 | 
									skipTranslationForLanguages.emplace_back(language);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							stream >> rememberedDeleteMessageOnlyForYou;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (stream.status() != QDataStream::Ok) {
 | 
						if (stream.status() != QDataStream::Ok) {
 | 
				
			||||||
		LOG(("App Error: "
 | 
							LOG(("App Error: "
 | 
				
			||||||
| 
						 | 
					@ -761,6 +767,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
 | 
				
			||||||
				std::abs(legacySkipTranslationForLanguage));
 | 
									std::abs(legacySkipTranslationForLanguage));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						_rememberedDeleteMessageOnlyForYou = (rememberedDeleteMessageOnlyForYou == 1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString Settings::getSoundPath(const QString &key) const {
 | 
					QString Settings::getSoundPath(const QString &key) const {
 | 
				
			||||||
| 
						 | 
					@ -1083,4 +1090,11 @@ std::vector<int> Settings::skipTranslationForLanguages() const {
 | 
				
			||||||
	return _skipTranslationForLanguages;
 | 
						return _skipTranslationForLanguages;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Settings::setRememberedDeleteMessageOnlyForYou(bool value) {
 | 
				
			||||||
 | 
						_rememberedDeleteMessageOnlyForYou = value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					bool Settings::rememberedDeleteMessageOnlyForYou() const {
 | 
				
			||||||
 | 
						return _rememberedDeleteMessageOnlyForYou;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Core
 | 
					} // namespace Core
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -727,6 +727,9 @@ public:
 | 
				
			||||||
	void setSkipTranslationForLanguages(std::vector<int> languages);
 | 
						void setSkipTranslationForLanguages(std::vector<int> languages);
 | 
				
			||||||
	[[nodiscard]] std::vector<int> skipTranslationForLanguages() const;
 | 
						[[nodiscard]] std::vector<int> skipTranslationForLanguages() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void setRememberedDeleteMessageOnlyForYou(bool value);
 | 
				
			||||||
 | 
						[[nodiscard]] bool rememberedDeleteMessageOnlyForYou() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] static bool ThirdColumnByDefault();
 | 
						[[nodiscard]] static bool ThirdColumnByDefault();
 | 
				
			||||||
	[[nodiscard]] static float64 DefaultDialogsWidthRatio();
 | 
						[[nodiscard]] static float64 DefaultDialogsWidthRatio();
 | 
				
			||||||
	[[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) {
 | 
						[[nodiscard]] static qint32 SerializePlaybackSpeed(float64 speed) {
 | 
				
			||||||
| 
						 | 
					@ -843,6 +846,7 @@ private:
 | 
				
			||||||
		HistoryView::DoubleClickQuickAction();
 | 
							HistoryView::DoubleClickQuickAction();
 | 
				
			||||||
	bool _translateButtonEnabled = false;
 | 
						bool _translateButtonEnabled = false;
 | 
				
			||||||
	std::vector<int> _skipTranslationForLanguages;
 | 
						std::vector<int> _skipTranslationForLanguages;
 | 
				
			||||||
 | 
						bool _rememberedDeleteMessageOnlyForYou = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool _tabbedReplacedWithInfo = false; // per-window
 | 
						bool _tabbedReplacedWithInfo = false; // per-window
 | 
				
			||||||
	rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
 | 
						rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue