mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-02 23:55:12 +00:00
Support separate message type group restrictions.
This commit is contained in:
@@ -462,7 +462,7 @@ QString PeerData::computeUnavailableReason() const {
|
||||
// This is duplicated in CanPinMessagesValue().
|
||||
bool PeerData::canPinMessages() const {
|
||||
if (const auto user = asUser()) {
|
||||
return user->flags() & UserDataFlag::CanPinMessages;
|
||||
return !user->amRestricted(ChatRestriction::PinMessages);
|
||||
} else if (const auto chat = asChat()) {
|
||||
return chat->amIn()
|
||||
&& !chat->amRestricted(ChatRestriction::PinMessages);
|
||||
@@ -881,18 +881,6 @@ Data::ForumTopic *PeerData::forumTopicFor(MsgId rootId) const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool PeerData::canWrite(bool checkForForum) const {
|
||||
if (const auto user = asUser()) {
|
||||
return user->canWrite();
|
||||
} else if (const auto channel = asChannel()) {
|
||||
return channel->canWrite(checkForForum);
|
||||
} else if (const auto chat = asChat()) {
|
||||
return chat->canWrite();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PeerData::allowsForwarding() const {
|
||||
if (const auto user = asUser()) {
|
||||
return true;
|
||||
@@ -920,10 +908,26 @@ Data::RestrictionCheckResult PeerData::amRestricted(
|
||||
return chat->hasAdminRights();
|
||||
}
|
||||
};
|
||||
if (const auto channel = asChannel()) {
|
||||
if (const auto user = asUser()) {
|
||||
return (right == ChatRestriction::SendVoiceMessages
|
||||
|| right == ChatRestriction::SendVideoMessages)
|
||||
? ((user->flags() & UserDataFlag::VoiceMessagesForbidden)
|
||||
? Result::Explicit()
|
||||
: Result::Allowed())
|
||||
: (right == ChatRestriction::SendPolls)
|
||||
? ((!user->isBot() || user->isSupport())
|
||||
? Result::Explicit()
|
||||
: Result::Allowed())
|
||||
: (right == ChatRestriction::PinMessages)
|
||||
? ((user->flags() & UserDataFlag::CanPinMessages)
|
||||
? Result::Allowed()
|
||||
: Result::Explicit())
|
||||
: Result::Allowed();
|
||||
} else if (const auto channel = asChannel()) {
|
||||
const auto defaultRestrictions = channel->defaultRestrictions()
|
||||
| (channel->isPublic()
|
||||
? (ChatRestriction::PinMessages | ChatRestriction::ChangeInfo)
|
||||
? (ChatRestriction::PinMessages
|
||||
| ChatRestriction::ChangeInfo)
|
||||
: ChatRestrictions(0));
|
||||
return (channel->amCreator() || allowByAdminRights(right, channel))
|
||||
? Result::Allowed()
|
||||
@@ -1010,19 +1014,6 @@ int PeerData::slowmodeSecondsLeft() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PeerData::canSendPolls() const {
|
||||
if (const auto user = asUser()) {
|
||||
return user->isBot()
|
||||
&& !user->isRepliesChat()
|
||||
&& !user->isSupport();
|
||||
} else if (const auto chat = asChat()) {
|
||||
return chat->canSendPolls();
|
||||
} else if (const auto channel = asChannel()) {
|
||||
return channel->canSendPolls();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PeerData::canManageGroupCall() const {
|
||||
if (const auto chat = asChat()) {
|
||||
return chat->amCreator()
|
||||
@@ -1109,95 +1100,6 @@ void PeerData::setMessagesTTL(TimeId period) {
|
||||
|
||||
namespace Data {
|
||||
|
||||
std::optional<QString> RestrictionError(
|
||||
not_null<PeerData*> peer,
|
||||
ChatRestriction restriction) {
|
||||
using Flag = ChatRestriction;
|
||||
if (const auto restricted = peer->amRestricted(restriction)) {
|
||||
const auto all = restricted.isWithEveryone();
|
||||
const auto channel = peer->asChannel();
|
||||
if (!all && channel) {
|
||||
auto restrictedUntil = channel->restrictedUntil();
|
||||
if (restrictedUntil > 0 && !ChannelData::IsRestrictedForever(restrictedUntil)) {
|
||||
auto restrictedUntilDateTime = base::unixtime::parse(channel->restrictedUntil());
|
||||
auto date = QLocale().toString(restrictedUntilDateTime.date(), QLocale::ShortFormat);
|
||||
auto time = QLocale().toString(restrictedUntilDateTime.time(), QLocale::ShortFormat);
|
||||
|
||||
switch (restriction) {
|
||||
case Flag::SendPolls:
|
||||
return tr::lng_restricted_send_polls_until(
|
||||
tr::now, lt_date, date, lt_time, time);
|
||||
case Flag::SendMessages:
|
||||
return tr::lng_restricted_send_message_until(
|
||||
tr::now, lt_date, date, lt_time, time);
|
||||
case Flag::SendMedia:
|
||||
return tr::lng_restricted_send_media_until(
|
||||
tr::now, lt_date, date, lt_time, time);
|
||||
case Flag::SendStickers:
|
||||
return tr::lng_restricted_send_stickers_until(
|
||||
tr::now, lt_date, date, lt_time, time);
|
||||
case Flag::SendGifs:
|
||||
return tr::lng_restricted_send_gifs_until(
|
||||
tr::now, lt_date, date, lt_time, time);
|
||||
case Flag::SendInline:
|
||||
case Flag::SendGames:
|
||||
return tr::lng_restricted_send_inline_until(
|
||||
tr::now, lt_date, date, lt_time, time);
|
||||
}
|
||||
Unexpected("Restriction in Data::RestrictionErrorKey.");
|
||||
}
|
||||
}
|
||||
switch (restriction) {
|
||||
case Flag::SendPolls:
|
||||
return all
|
||||
? tr::lng_restricted_send_polls_all(tr::now)
|
||||
: tr::lng_restricted_send_polls(tr::now);
|
||||
case Flag::SendMessages:
|
||||
return all
|
||||
? tr::lng_restricted_send_message_all(tr::now)
|
||||
: tr::lng_restricted_send_message(tr::now);
|
||||
case Flag::SendMedia:
|
||||
return all
|
||||
? tr::lng_restricted_send_media_all(tr::now)
|
||||
: tr::lng_restricted_send_media(tr::now);
|
||||
case Flag::SendStickers:
|
||||
return all
|
||||
? tr::lng_restricted_send_stickers_all(tr::now)
|
||||
: tr::lng_restricted_send_stickers(tr::now);
|
||||
case Flag::SendGifs:
|
||||
return all
|
||||
? tr::lng_restricted_send_gifs_all(tr::now)
|
||||
: tr::lng_restricted_send_gifs(tr::now);
|
||||
case Flag::SendInline:
|
||||
case Flag::SendGames:
|
||||
return all
|
||||
? tr::lng_restricted_send_inline_all(tr::now)
|
||||
: tr::lng_restricted_send_inline(tr::now);
|
||||
}
|
||||
Unexpected("Restriction in Data::RestrictionErrorKey.");
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<QString> RestrictionError(
|
||||
not_null<PeerData*> peer,
|
||||
UserRestriction restriction) {
|
||||
const auto user = peer->asUser();
|
||||
if (user && !user->canReceiveVoices()) {
|
||||
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;
|
||||
}
|
||||
|
||||
void SetTopPinnedMessageId(
|
||||
not_null<PeerData*> peer,
|
||||
MsgId messageId) {
|
||||
|
Reference in New Issue
Block a user