[Improvement] Permissions split
This commit is contained in:
parent
20cfd8e301
commit
e070d5f53c
5 changed files with 74 additions and 21 deletions
|
|
@ -144,6 +144,14 @@
|
|||
"ktg_group_status_admin": "is admin",
|
||||
"ktg_too_many_accounts_warning": "Warning! Using too many accounts at the same time is not recommended due to higher memory comsumption and possible crashes because of it.\n\nYou sure you want to add a new account?",
|
||||
"ktg_account_add_anyway": "Add anyway",
|
||||
"ktg_rights_chat_send_stickers": "Send stickers",
|
||||
"ktg_rights_chat_send_gif": "Send GIFs",
|
||||
"ktg_rights_chat_send_games": "Send games",
|
||||
"ktg_rights_chat_use_inline": "Use inline bots",
|
||||
"ktg_admin_log_banned_send_stickers": "Send stickers",
|
||||
"ktg_admin_log_banned_send_gif": "Send GIFs",
|
||||
"ktg_admin_log_banned_send_games": "Send games",
|
||||
"ktg_admin_log_banned_use_inline": "Use inline bots",
|
||||
"ktg_forward_go_to_chat": "Go to chat",
|
||||
"ktg_settings_forward": "Forward",
|
||||
"ktg_settings_forward_retain_selection": "Retain selection after forward",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "boxes/peers/edit_peer_permissions_box.h"
|
||||
|
||||
#include "kotato/kotato_lang.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_chat.h"
|
||||
|
|
@ -108,21 +109,24 @@ void ApplyDependencies(
|
|||
|
||||
std::vector<std::pair<ChatRestrictions, QString>> RestrictionLabels() {
|
||||
const auto langKeys = {
|
||||
tr::lng_rights_chat_send_text,
|
||||
tr::lng_rights_chat_send_media,
|
||||
tr::lng_rights_chat_send_stickers,
|
||||
tr::lng_rights_chat_send_links,
|
||||
tr::lng_rights_chat_send_polls,
|
||||
tr::lng_rights_chat_add_members,
|
||||
tr::lng_rights_group_pin,
|
||||
tr::lng_rights_group_info,
|
||||
tr::lng_rights_chat_send_text(tr::now),
|
||||
tr::lng_rights_chat_send_media(tr::now),
|
||||
ktr("ktg_rights_chat_send_stickers"),
|
||||
ktr("ktg_rights_chat_send_gif"),
|
||||
ktr("ktg_rights_chat_send_games"),
|
||||
ktr("ktg_rights_chat_use_inline"),
|
||||
tr::lng_rights_chat_send_links(tr::now),
|
||||
tr::lng_rights_chat_send_polls(tr::now),
|
||||
tr::lng_rights_chat_add_members(tr::now),
|
||||
tr::lng_rights_group_pin(tr::now),
|
||||
tr::lng_rights_group_info(tr::now),
|
||||
};
|
||||
|
||||
std::vector<std::pair<ChatRestrictions, QString>> vector;
|
||||
const auto restrictions = Data::ListOfRestrictions();
|
||||
auto i = 0;
|
||||
for (const auto &key : langKeys) {
|
||||
vector.emplace_back(restrictions[i++], key(tr::now));
|
||||
vector.emplace_back(restrictions[i++], key);
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
|
@ -163,6 +167,7 @@ auto Dependencies(ChatRestrictions)
|
|||
using Flag = ChatRestriction;
|
||||
|
||||
return {
|
||||
/*
|
||||
// stickers <-> gifs
|
||||
{ Flag::SendGifs, Flag::SendStickers },
|
||||
{ Flag::SendStickers, Flag::SendGifs },
|
||||
|
|
@ -177,10 +182,23 @@ auto Dependencies(ChatRestrictions)
|
|||
|
||||
// stickers -> send_messages
|
||||
{ Flag::SendStickers, Flag::SendMessages },
|
||||
*/
|
||||
|
||||
// embed_links -> send_messages
|
||||
{ Flag::EmbedLinks, Flag::SendMessages },
|
||||
|
||||
// send_games -> send_messages
|
||||
{ Flag::SendGames, Flag::SendMessages },
|
||||
|
||||
// send_gifs -> send_messages
|
||||
{ Flag::SendGifs, Flag::SendMessages },
|
||||
|
||||
// send_inline -> send_messages
|
||||
{ Flag::SendInline, Flag::SendMessages },
|
||||
|
||||
// send_stickers -> send_messages
|
||||
{ Flag::SendStickers, Flag::SendMessages },
|
||||
|
||||
// send_media -> send_messages
|
||||
{ Flag::SendMedia, Flag::SendMessages },
|
||||
|
||||
|
|
@ -285,11 +303,13 @@ ChatRestrictions FixDependentRestrictions(ChatRestrictions restrictions) {
|
|||
|
||||
// Fix iOS bug of saving send_inline like embed_links.
|
||||
// We copy send_stickers to send_inline.
|
||||
/*
|
||||
if (restrictions & ChatRestriction::SendStickers) {
|
||||
restrictions |= ChatRestriction::SendInline;
|
||||
} else {
|
||||
restrictions &= ~ChatRestriction::SendInline;
|
||||
}
|
||||
*/
|
||||
|
||||
// Apply the strictest.
|
||||
const auto fixOne = [&] {
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ std::vector<ChatRestrictions> ListOfRestrictions() {
|
|||
return {
|
||||
Flag::SendMessages,
|
||||
Flag::SendMedia,
|
||||
Flag::SendStickers
|
||||
| Flag::SendGifs
|
||||
| Flag::SendGames
|
||||
| Flag::SendInline,
|
||||
Flag::SendStickers,
|
||||
Flag::SendGifs,
|
||||
Flag::SendGames,
|
||||
Flag::SendInline,
|
||||
Flag::EmbedLinks,
|
||||
Flag::SendPolls,
|
||||
Flag::InviteUsers,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "history/admin_log/history_admin_log_item.h"
|
||||
|
||||
#include "kotato/kotato_lang.h"
|
||||
#include "history/admin_log/history_admin_log_inner.h"
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/history_location_manager.h"
|
||||
|
|
@ -180,6 +181,26 @@ const auto CollectChanges = [](
|
|||
+ withPrefix(minusFlags & ~plusFlags, kMinus);
|
||||
};
|
||||
|
||||
const auto CollectChangesKtg = [](auto &phraseMap, auto &ktgPhraseMap, auto plusFlags, auto minusFlags) {
|
||||
auto withPrefix = [&ktgPhraseMap, &phraseMap](auto flags, QChar prefix) {
|
||||
auto result = QString();
|
||||
for (auto &phrase : ktgPhraseMap) {
|
||||
if (flags & phrase.first) {
|
||||
result.append('\n' + (prefix + ktr(phrase.second)));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &phrase : phraseMap) {
|
||||
if (flags & phrase.first) {
|
||||
result.append('\n' + (prefix + phrase.second(tr::now)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const auto kMinus = QChar(0x2212);
|
||||
return withPrefix(plusFlags & ~minusFlags, '+') + withPrefix(minusFlags & ~plusFlags, kMinus);
|
||||
};
|
||||
|
||||
TextWithEntities GenerateAdminChangeText(
|
||||
not_null<ChannelData*> channel,
|
||||
const TextWithEntities &user,
|
||||
|
|
@ -243,17 +264,19 @@ QString GeneratePermissionsChangeText(
|
|||
{ Flag::ViewMessages, tr::lng_admin_log_banned_view_messages },
|
||||
{ Flag::SendMessages, tr::lng_admin_log_banned_send_messages },
|
||||
{ Flag::SendMedia, tr::lng_admin_log_banned_send_media },
|
||||
{ Flag::SendStickers
|
||||
| Flag::SendGifs
|
||||
| Flag::SendInline
|
||||
| Flag::SendGames, tr::lng_admin_log_banned_send_stickers },
|
||||
{ Flag::EmbedLinks, tr::lng_admin_log_banned_embed_links },
|
||||
{ Flag::SendPolls, tr::lng_admin_log_banned_send_polls },
|
||||
{ Flag::ChangeInfo, tr::lng_admin_log_admin_change_info },
|
||||
{ Flag::InviteUsers, tr::lng_admin_log_admin_invite_users },
|
||||
{ Flag::PinMessages, tr::lng_admin_log_admin_pin_messages },
|
||||
};
|
||||
return CollectChanges(phraseMap, prevRights.flags, newRights.flags);
|
||||
static auto ktgPhraseMap = std::map<Flags, QString>{
|
||||
{ Flag::SendStickers, "ktg_admin_log_banned_send_stickers" },
|
||||
{ Flag::SendGifs, "ktg_admin_log_banned_send_gif" },
|
||||
{ Flag::SendInline, "ktg_admin_log_banned_use_inline" },
|
||||
{ Flag::SendGames, "ktg_admin_log_banned_send_games" },
|
||||
};
|
||||
return CollectChangesKtg(phraseMap, ktgPhraseMap, prevRights.flags, newRights.flags);
|
||||
}
|
||||
|
||||
TextWithEntities GeneratePermissionsChangeText(
|
||||
|
|
|
|||
|
|
@ -6836,9 +6836,11 @@ bool HistoryWidget::sendExistingDocument(
|
|||
not_null<DocumentData*> document,
|
||||
Api::SendOptions options,
|
||||
std::optional<MsgId> localId) {
|
||||
const auto error = _peer
|
||||
? Data::RestrictionError(_peer, ChatRestriction::SendStickers)
|
||||
: std::nullopt;
|
||||
const auto error = !_peer
|
||||
? std::nullopt
|
||||
: document->sticker()
|
||||
? Data::RestrictionError(_peer, ChatRestriction::SendStickers)
|
||||
: Data::RestrictionError(_peer, ChatRestriction::SendGifs);
|
||||
if (error) {
|
||||
controller()->show(
|
||||
Ui::MakeInformBox(*error),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue