Respected privacy setting for voice messages when they are forwarded.

This commit is contained in:
23rd 2022-07-18 23:35:16 +03:00 committed by John Preston
parent c9aec6a170
commit 505e60545e
7 changed files with 47 additions and 10 deletions

View file

@ -2857,7 +2857,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_restricted_send_public_polls" = "Sorry, public polls can't be forwarded to channels.";
"lng_restricted_send_voices" = "{user} restricted sending of voice messages to them.";
"lng_restricted_send_voice_messages" = "{user} restricted sending of voice messages to them.";
"lng_restricted_send_video_messages" = "{user} restricted sending of video messages to them.";
"lng_exceptions_list_title" = "Exceptions";
"lng_removed_list_title" = "Removed users";

View file

@ -7,6 +7,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
enum class UserRestriction {
SendVoiceMessages,
SendVideoMessages,
};
enum class ChatAdminRight {
ChangeInfo = (1 << 0),
PostMessages = (1 << 1),

View file

@ -918,6 +918,11 @@ QString MediaFile::errorTextForForward(not_null<PeerData*> peer) const {
ChatRestriction::SendMedia)) {
return *error;
}
if (const auto error = Data::RestrictionError(
peer,
UserRestriction::SendVideoMessages)) {
return *error;
}
} else {
if (const auto error = Data::RestrictionError(
peer,
@ -929,6 +934,12 @@ QString MediaFile::errorTextForForward(not_null<PeerData*> peer) const {
peer,
ChatRestriction::SendMedia)) {
return *error;
} else if (_document->isVoiceMessage()) {
if (const auto error = Data::RestrictionError(
peer,
UserRestriction::SendVoiceMessages)) {
return *error;
}
}
return QString();
}

View file

@ -1125,10 +1125,21 @@ std::optional<QString> RestrictionError(
return std::nullopt;
}
std::optional<QString> RestrictionVoicesError(not_null<PeerData*> peer) {
std::optional<QString> RestrictionError(
not_null<PeerData*> peer,
UserRestriction restriction) {
const auto user = peer->asUser();
if (user && !user->canReceiveVoices()) {
return tr::lng_restricted_send_voices(tr::now, lt_user, user->name);
const auto voice = restriction == UserRestriction::SendVoiceMessages;
if (voice
|| (restriction == UserRestriction::SendVideoMessages)) {
return (voice
? tr::lng_restricted_send_voice_messages
: tr::lng_restricted_send_video_messages)(
tr::now,
lt_user,
user->name);
}
}
return std::nullopt;
}

View file

@ -19,6 +19,7 @@ class ChatData;
class ChannelData;
enum class ChatRestriction;
enum class UserRestriction;
namespace Ui {
class EmptyUserpic;
@ -469,7 +470,9 @@ std::optional<QString> RestrictionError(
not_null<PeerData*> peer,
ChatRestriction restriction);
std::optional<QString> RestrictionVoicesError(not_null<PeerData*> peer);
std::optional<QString> RestrictionError(
not_null<PeerData*> peer,
UserRestriction restriction);
void SetTopPinnedMessageId(not_null<PeerData*> peer, MsgId messageId);
[[nodiscard]] FullMsgId ResolveTopPinnedId(

View file

@ -943,11 +943,14 @@ void HistoryWidget::initVoiceRecordBar() {
_voiceRecordBar->setStartRecordingFilter([=] {
const auto error = [&]() -> std::optional<QString> {
if (_peer) {
const auto type = ChatRestriction::SendMedia;
if (const auto error = Data::RestrictionError(_peer, type)) {
if (const auto error = Data::RestrictionError(
_peer,
ChatRestriction::SendMedia)) {
return error;
}
if (const auto error = Data::RestrictionVoicesError(_peer)) {
if (const auto error = Data::RestrictionError(
_peer,
UserRestriction::SendVoiceMessages)) {
return error;
}
}

View file

@ -1967,11 +1967,14 @@ void ComposeControls::initVoiceRecordBar() {
const auto error = [&]() -> std::optional<QString> {
const auto peer = _history ? _history->peer.get() : nullptr;
if (!peer) {
const auto type = ChatRestriction::SendMedia;
if (const auto error = Data::RestrictionError(peer, type)) {
if (const auto error = Data::RestrictionError(
peer,
ChatRestriction::SendMedia)) {
return error;
}
if (const auto error = Data::RestrictionVoicesError(peer)) {
if (const auto error = Data::RestrictionError(
peer,
UserRestriction::SendVoiceMessages)) {
return error;
}
}