From e7b3416da8f190d89edfbdeba36e9f7f9bec4943 Mon Sep 17 00:00:00 2001
From: 23rd <23rd@vivaldi.net>
Date: Sun, 31 Jul 2022 09:46:33 +0300
Subject: [PATCH] Allowed to forward voice messages without full user info.

---
 Telegram/SourceFiles/boxes/share_box.cpp | 12 +++++++++++-
 Telegram/SourceFiles/data/data_user.cpp  |  6 +++---
 Telegram/SourceFiles/data/data_user.h    |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp
index 1aaab01eb..6193a097d 100644
--- a/Telegram/SourceFiles/boxes/share_box.cpp
+++ b/Telegram/SourceFiles/boxes/share_box.cpp
@@ -1377,7 +1377,17 @@ void FastShareMessage(
 						}
 					}
 					finish();
-				}).fail([=] {
+				}).fail([=](const MTP::Error &error) {
+					if (error.type() == u"VOICE_MESSAGES_FORBIDDEN"_q) {
+						if (show->valid()) {
+							Ui::Toast::Show(
+								show->toastParent(),
+								tr::lng_restricted_send_voice_messages(
+									tr::now,
+									lt_user,
+									peer->name));
+						}
+					}
 					finish();
 				}).afterRequest(history->sendRequestId).send();
 				return history->sendRequestId;
diff --git a/Telegram/SourceFiles/data/data_user.cpp b/Telegram/SourceFiles/data/data_user.cpp
index db6709b12..bf637c74f 100644
--- a/Telegram/SourceFiles/data/data_user.cpp
+++ b/Telegram/SourceFiles/data/data_user.cpp
@@ -258,7 +258,7 @@ bool UserData::canReceiveGifts() const {
 }
 
 bool UserData::canReceiveVoices() const {
-	return flags() & UserDataFlag::CanReceiveVoices;
+	return !(flags() & UserDataFlag::VoiceMessagesForbidden);
 }
 
 bool UserData::canShareThisContactFast() const {
@@ -332,8 +332,8 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
 		| (canReceiveGifts ? Flag::CanReceiveGifts : Flag())
 		| (update.is_can_pin_message() ? Flag::CanPinMessages : Flag())
 		| (update.is_blocked() ? Flag::Blocked : Flag())
-		| (!update.is_voice_messages_forbidden()
-			? Flag::CanReceiveVoices
+		| (update.is_voice_messages_forbidden()
+			? Flag::VoiceMessagesForbidden
 			: Flag()));
 	user->setIsBlocked(update.is_blocked());
 	user->setCallsStatus(update.is_phone_calls_private()
diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h
index 945894829..3693b0f06 100644
--- a/Telegram/SourceFiles/data/data_user.h
+++ b/Telegram/SourceFiles/data/data_user.h
@@ -52,7 +52,7 @@ enum class UserDataFlag {
 	Self = (1 << 13),
 	Premium = (1 << 14),
 	CanReceiveGifts = (1 << 15),
-	CanReceiveVoices = (1 << 16),
+	VoiceMessagesForbidden = (1 << 16),
 };
 inline constexpr bool is_flag_type(UserDataFlag) { return true; };
 using UserDataFlags = base::flags<UserDataFlag>;