From 0ce4d666013977c11799ddda51b25833df3037ae Mon Sep 17 00:00:00 2001
From: John Preston <johnprestonmail@gmail.com>
Date: Fri, 4 Jan 2019 11:57:07 +0400
Subject: [PATCH] Rename restrictionReason to unavailableReason.

---
 Telegram/SourceFiles/data/data_peer.cpp       | 28 +++++++++++++------
 Telegram/SourceFiles/data/data_peer.h         | 22 ++++++---------
 Telegram/SourceFiles/data/data_session.cpp    | 20 +++++--------
 .../SourceFiles/history/history_widget.cpp    | 10 +++----
 Telegram/SourceFiles/mainwidget.cpp           |  6 ++--
 Telegram/SourceFiles/observer_peer.h          |  2 +-
 6 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp
index 4c8b37db6..8a7b898ed 100644
--- a/Telegram/SourceFiles/data/data_peer.cpp
+++ b/Telegram/SourceFiles/data/data_peer.cpp
@@ -474,10 +474,16 @@ bool UserData::setAbout(const QString &newAbout) {
 	return true;
 }
 
-void UserData::setRestrictionReason(const QString &text) {
-	if (_restrictionReason != text) {
-		_restrictionReason = text;
-		Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::RestrictionReasonChanged);
+QString UserData::unavailableReason() const {
+	return _unavailableReason;
+}
+
+void UserData::setUnavailableReason(const QString &text) {
+	if (_unavailableReason != text) {
+		_unavailableReason = text;
+		Notify::peerUpdatedDelayed(
+			this,
+			Notify::PeerUpdate::Flag::UnavailableReasonChanged);
 	}
 }
 
@@ -924,10 +930,16 @@ bool ChannelData::isGroupAdmin(not_null<UserData*> user) const {
 	return false;
 }
 
-void ChannelData::setRestrictionReason(const QString &text) {
-	if (_restrictionReason != text) {
-		_restrictionReason = text;
-		Notify::peerUpdatedDelayed(this, Notify::PeerUpdate::Flag::RestrictionReasonChanged);
+QString ChannelData::unavailableReason() const {
+	return _unavailableReason;
+}
+
+void ChannelData::setUnavailableReason(const QString &text) {
+	if (_unavailableReason != text) {
+		_unavailableReason = text;
+		Notify::peerUpdatedDelayed(
+			this,
+			Notify::PeerUpdate::Flag::UnavailableReasonChanged);
 	}
 }
 
diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h
index b4817fe56..d12ed6e9e 100644
--- a/Telegram/SourceFiles/data/data_peer.h
+++ b/Telegram/SourceFiles/data/data_peer.h
@@ -199,9 +199,9 @@ public:
 
 	int nameVersion = 1;
 
-	// if this string is not empty we must not allow to open the
-	// conversation and we must show this string instead
-	virtual QString restrictionReason() const {
+	// If this string is not empty we must not allow to open the
+	// conversation and we must show this string instead.
+	virtual QString unavailableReason() const {
 		return QString();
 	}
 
@@ -467,10 +467,8 @@ public:
 
 	std::unique_ptr<BotInfo> botInfo;
 
-	QString restrictionReason() const override {
-		return _restrictionReason;
-	}
-	void setRestrictionReason(const QString &reason);
+	QString unavailableReason() const override;
+	void setUnavailableReason(const QString &reason);
 
 	int commonChatsCount() const {
 		return _commonChatsCount;
@@ -481,7 +479,7 @@ private:
 	Flags _flags;
 	FullFlags _fullFlags;
 
-	QString _restrictionReason;
+	QString _unavailableReason;
 	QString _about;
 	QString _phone;
 	ContactStatus _contactStatus = ContactStatus::PhoneUnknown;
@@ -991,10 +989,8 @@ public:
 		return _ptsWaiter.waitingForShortPoll();
 	}
 
-	QString restrictionReason() const override {
-		return _restrictionReason;
-	}
-	void setRestrictionReason(const QString &reason);
+	QString unavailableReason() const override;
+	void setUnavailableReason(const QString &reason);
 
 	MsgId availableMinId() const {
 		return _availableMinId;
@@ -1030,7 +1026,7 @@ private:
 	RestrictionFlags _restrictions;
 	TimeId _restrictedUntill;
 
-	QString _restrictionReason;
+	QString _unavailableReason;
 	QString _about;
 
 	QString _inviteLink;
diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp
index 44a862b46..9dd9d55cb 100644
--- a/Telegram/SourceFiles/data/data_session.cpp
+++ b/Telegram/SourceFiles/data/data_session.cpp
@@ -96,7 +96,7 @@ void CheckForSwitchInlineButton(not_null<HistoryItem*> item) {
 
 // We should get a full restriction in "{full}: {reason}" format and we
 // need to find an "-all" tag in {full}, otherwise ignore this restriction.
-QString ExtractRestrictionReason(const QString &restriction) {
+QString ExtractUnavailableReason(const QString &restriction) {
 	const auto fullEnd = restriction.indexOf(':');
 	if (fullEnd <= 0) {
 		return QString();
@@ -278,12 +278,9 @@ not_null<UserData*> Session::user(const MTPUser &data) {
 				result->input = MTP_inputPeerUser(data.vid, data.vaccess_hash);
 				result->inputUser = MTP_inputUser(data.vid, data.vaccess_hash);
 			}
-			if (data.is_restricted()) {
-				result->setRestrictionReason(
-					ExtractRestrictionReason(qs(data.vrestriction_reason)));
-			} else {
-				result->setRestrictionReason(QString());
-			}
+			result->setUnavailableReason(data.is_restricted()
+				? ExtractUnavailableReason(qs(data.vrestriction_reason))
+				: QString());
 		}
 		if (data.is_deleted()) {
 			if (!result->phone().isEmpty()) {
@@ -554,12 +551,9 @@ not_null<PeerData*> Session::chat(const MTPChat &data) {
 			if (channel->version < data.vversion.v) {
 				channel->version = data.vversion.v;
 			}
-			if (data.is_restricted()) {
-				channel->setRestrictionReason(
-					ExtractRestrictionReason(qs(data.vrestriction_reason)));
-			} else {
-				channel->setRestrictionReason(QString());
-			}
+			channel->setUnavailableReason(data.is_restricted()
+				? ExtractUnavailableReason(qs(data.vrestriction_reason))
+				: QString());
 			channel->setFlags(data.vflags.v);
 			//if (data.has_feed_id()) { // #feed
 			//	channel->setFeed(feed(data.vfeed_id.v));
diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp
index 4f97151e7..2312a62d0 100644
--- a/Telegram/SourceFiles/history/history_widget.cpp
+++ b/Telegram/SourceFiles/history/history_widget.cpp
@@ -406,7 +406,7 @@ HistoryWidget::HistoryWidget(
 		| UpdateFlag::UnreadMentionsChanged
 		| UpdateFlag::UnreadViewChanged
 		| UpdateFlag::MigrationChanged
-		| UpdateFlag::RestrictionReasonChanged
+		| UpdateFlag::UnavailableReasonChanged
 		| UpdateFlag::PinnedMessageChanged
 		| UpdateFlag::UserIsBlocked
 		| UpdateFlag::AdminsChanged
@@ -436,11 +436,11 @@ HistoryWidget::HistoryWidget(
 			if (update.flags & UpdateFlag::NotificationsEnabled) {
 				updateNotifyControls();
 			}
-			if (update.flags & UpdateFlag::RestrictionReasonChanged) {
-				auto restriction = _peer->restrictionReason();
-				if (!restriction.isEmpty()) {
+			if (update.flags & UpdateFlag::UnavailableReasonChanged) {
+				const auto unavailable = _peer->unavailableReason();
+				if (!unavailable.isEmpty()) {
 					this->controller()->showBackFromStack();
-					Ui::show(Box<InformBox>(restriction));
+					Ui::show(Box<InformBox>(unavailable));
 					return;
 				}
 			}
diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp
index 917b9f02c..66a615ce1 100644
--- a/Telegram/SourceFiles/mainwidget.cpp
+++ b/Telegram/SourceFiles/mainwidget.cpp
@@ -1593,10 +1593,10 @@ void MainWidget::ui_showPeerHistory(
 			peerId = peer->id;
 			if (showAtMsgId > 0) showAtMsgId = -showAtMsgId;
 		}
-		auto restriction = peer->restrictionReason();
-		if (!restriction.isEmpty()) {
+		const auto unavailable = peer->unavailableReason();
+		if (!unavailable.isEmpty()) {
 			if (params.activation != anim::activation::background) {
-				Ui::show(Box<InformBox>(restriction));
+				Ui::show(Box<InformBox>(unavailable));
 			}
 			return;
 		}
diff --git a/Telegram/SourceFiles/observer_peer.h b/Telegram/SourceFiles/observer_peer.h
index 6e889c361..22502d7e2 100644
--- a/Telegram/SourceFiles/observer_peer.h
+++ b/Telegram/SourceFiles/observer_peer.h
@@ -36,7 +36,7 @@ struct PeerUpdate {
 		NotificationsEnabled      = (1 << 4),
 		MigrationChanged          = (1 << 6),
 		ChatPinnedChanged         = (1 << 7),
-		RestrictionReasonChanged  = (1 << 8),
+		UnavailableReasonChanged  = (1 << 8),
 		UnreadViewChanged         = (1 << 9),
 		PinnedMessageChanged      = (1 << 10),