mirror of https://github.com/procxx/kepka.git
Add default permissions changes to admin log.
This commit is contained in:
parent
eff90395b6
commit
ff728e2fc1
|
@ -1572,10 +1572,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_admin_log_participant_joined_channel" = "{from} joined the channel";
|
"lng_admin_log_participant_joined_channel" = "{from} joined the channel";
|
||||||
"lng_admin_log_participant_left" = "{from} left the group";
|
"lng_admin_log_participant_left" = "{from} left the group";
|
||||||
"lng_admin_log_participant_left_channel" = "{from} left the channel";
|
"lng_admin_log_participant_left_channel" = "{from} left the channel";
|
||||||
|
"lng_admin_log_stopped_poll" = "{from} stopped poll:";
|
||||||
"lng_admin_log_invited" = "invited {user}";
|
"lng_admin_log_invited" = "invited {user}";
|
||||||
"lng_admin_log_banned" = "banned {user}";
|
"lng_admin_log_banned" = "banned {user}";
|
||||||
"lng_admin_log_restricted" = "changed restrictions for {user} {until}";
|
"lng_admin_log_restricted" = "changed restrictions for {user} {until}";
|
||||||
"lng_admin_log_promoted" = "changed privileges for {user}";
|
"lng_admin_log_promoted" = "changed privileges for {user}";
|
||||||
|
"lng_admin_log_changed_default_permissions" = "changed default permissions";
|
||||||
"lng_admin_log_changed_stickers_group" = "{from} changed the group's {sticker_set}";
|
"lng_admin_log_changed_stickers_group" = "{from} changed the group's {sticker_set}";
|
||||||
"lng_admin_log_changed_stickers_set" = "sticker set";
|
"lng_admin_log_changed_stickers_set" = "sticker set";
|
||||||
"lng_admin_log_removed_stickers_group" = "{from} removed the group's sticker set";
|
"lng_admin_log_removed_stickers_group" = "{from} removed the group's sticker set";
|
||||||
|
@ -1587,6 +1589,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_admin_log_banned_send_media" = "Send media";
|
"lng_admin_log_banned_send_media" = "Send media";
|
||||||
"lng_admin_log_banned_send_stickers" = "Send stickers & GIFs";
|
"lng_admin_log_banned_send_stickers" = "Send stickers & GIFs";
|
||||||
"lng_admin_log_banned_embed_links" = "Embed links";
|
"lng_admin_log_banned_embed_links" = "Embed links";
|
||||||
|
"lng_admin_log_banned_send_polls" = "Send polls";
|
||||||
"lng_admin_log_admin_change_info" = "Change info";
|
"lng_admin_log_admin_change_info" = "Change info";
|
||||||
"lng_admin_log_admin_post_messages" = "Post messages";
|
"lng_admin_log_admin_post_messages" = "Post messages";
|
||||||
"lng_admin_log_admin_edit_messages" = "Edit messages";
|
"lng_admin_log_admin_edit_messages" = "Edit messages";
|
||||||
|
|
|
@ -196,8 +196,7 @@ TextWithEntities GenerateAdminChangeText(
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
TextWithEntities GenerateBannedChangeText(
|
QString GenerateBannedChangeText(
|
||||||
const TextWithEntities &user,
|
|
||||||
const MTPChatBannedRights *newRights,
|
const MTPChatBannedRights *newRights,
|
||||||
const MTPChatBannedRights *prevRights) {
|
const MTPChatBannedRights *prevRights) {
|
||||||
Expects(!newRights || newRights->type() == mtpc_chatBannedRights);
|
Expects(!newRights || newRights->type() == mtpc_chatBannedRights);
|
||||||
|
@ -206,8 +205,32 @@ TextWithEntities GenerateBannedChangeText(
|
||||||
using Flag = MTPDchatBannedRights::Flag;
|
using Flag = MTPDchatBannedRights::Flag;
|
||||||
using Flags = MTPDchatBannedRights::Flags;
|
using Flags = MTPDchatBannedRights::Flags;
|
||||||
|
|
||||||
auto newFlags = newRights ? newRights->c_chatBannedRights().vflags.v : MTPDchatBannedRights::Flags(0);
|
auto newFlags = newRights ? newRights->c_chatBannedRights().vflags.v : Flags(0);
|
||||||
auto prevFlags = prevRights ? prevRights->c_chatBannedRights().vflags.v : MTPDchatBannedRights::Flags(0);
|
auto prevFlags = prevRights ? prevRights->c_chatBannedRights().vflags.v : Flags(0);
|
||||||
|
static auto phraseMap = std::map<Flags, LangKey>{
|
||||||
|
{ Flag::f_view_messages, lng_admin_log_banned_view_messages },
|
||||||
|
{ Flag::f_send_messages, lng_admin_log_banned_send_messages },
|
||||||
|
{ Flag::f_send_media, lng_admin_log_banned_send_media },
|
||||||
|
{ Flag::f_send_stickers | Flag::f_send_gifs | Flag::f_send_inline | Flag::f_send_games, lng_admin_log_banned_send_stickers },
|
||||||
|
{ Flag::f_embed_links, lng_admin_log_banned_embed_links },
|
||||||
|
{ Flag::f_send_media, lng_admin_log_banned_send_polls },
|
||||||
|
{ Flag::f_change_info, lng_admin_log_admin_change_info },
|
||||||
|
{ Flag::f_invite_users, lng_admin_log_admin_invite_users },
|
||||||
|
{ Flag::f_pin_messages, lng_admin_log_admin_pin_messages },
|
||||||
|
};
|
||||||
|
return CollectChanges(phraseMap, prevFlags, newFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextWithEntities GenerateBannedChangeText(
|
||||||
|
const TextWithEntities &user,
|
||||||
|
const MTPChatBannedRights *newRights,
|
||||||
|
const MTPChatBannedRights *prevRights) {
|
||||||
|
Expects(!newRights || newRights->type() == mtpc_chatBannedRights);
|
||||||
|
|
||||||
|
using Flag = MTPDchatBannedRights::Flag;
|
||||||
|
using Flags = MTPDchatBannedRights::Flags;
|
||||||
|
|
||||||
|
auto newFlags = newRights ? newRights->c_chatBannedRights().vflags.v : Flags(0);
|
||||||
auto newUntil = newRights ? newRights->c_chatBannedRights().vuntil_date.v : TimeId(0);
|
auto newUntil = newRights ? newRights->c_chatBannedRights().vuntil_date.v : TimeId(0);
|
||||||
auto indefinitely = ChannelData::IsRestrictedForever(newUntil);
|
auto indefinitely = ChannelData::IsRestrictedForever(newUntil);
|
||||||
if (newFlags & Flag::f_view_messages) {
|
if (newFlags & Flag::f_view_messages) {
|
||||||
|
@ -223,21 +246,12 @@ TextWithEntities GenerateBannedChangeText(
|
||||||
user,
|
user,
|
||||||
lt_until,
|
lt_until,
|
||||||
TextWithEntities { untilText });
|
TextWithEntities { untilText });
|
||||||
|
const auto changes = GenerateBannedChangeText(newRights, prevRights);
|
||||||
static auto phraseMap = std::map<Flags, LangKey> {
|
|
||||||
{ Flag::f_view_messages, lng_admin_log_banned_view_messages },
|
|
||||||
{ Flag::f_send_messages, lng_admin_log_banned_send_messages },
|
|
||||||
{ Flag::f_send_media, lng_admin_log_banned_send_media },
|
|
||||||
{ Flag::f_send_stickers | Flag::f_send_gifs | Flag::f_send_inline | Flag::f_send_games, lng_admin_log_banned_send_stickers },
|
|
||||||
{ Flag::f_embed_links, lng_admin_log_banned_embed_links },
|
|
||||||
};
|
|
||||||
auto changes = CollectChanges(phraseMap, prevFlags, newFlags);
|
|
||||||
if (!changes.isEmpty()) {
|
if (!changes.isEmpty()) {
|
||||||
result.text.append('\n' + changes);
|
result.text.append('\n' + changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
}
|
||||||
|
|
||||||
auto GenerateUserString(MTPint userId) {
|
auto GenerateUserString(MTPint userId) {
|
||||||
// User name in "User name (@username)" format with entities.
|
// User name in "User name (@username)" format with entities.
|
||||||
|
@ -314,6 +328,16 @@ TextWithEntities GenerateParticipantChangeText(not_null<ChannelData*> channel, c
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextWithEntities GenerateDefaultBannedRightsChangeText(not_null<ChannelData*> channel, const MTPChatBannedRights &rights, const MTPChatBannedRights &oldRights) {
|
||||||
|
auto result = TextWithEntities{ lang(lng_admin_log_changed_default_permissions) };
|
||||||
|
const auto changes = GenerateBannedChangeText(&rights, &oldRights);
|
||||||
|
if (!changes.isEmpty()) {
|
||||||
|
result.text.append('\n' + changes);
|
||||||
|
}
|
||||||
|
result.entities.push_front(EntityInText(EntityInTextItalic, 0, result.text.size()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
OwnedItem::OwnedItem(std::nullptr_t) {
|
OwnedItem::OwnedItem(std::nullptr_t) {
|
||||||
|
@ -575,71 +599,61 @@ void GenerateItems(
|
||||||
addSimpleServiceMessage(text(lt_from, fromLinkText));
|
addSimpleServiceMessage(text(lt_from, fromLinkText));
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (action.type()) {
|
auto createDefaultBannedRights = [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &action) {
|
||||||
case mtpc_channelAdminLogEventActionChangeTitle:
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
||||||
createChangeTitle(
|
auto bodyReplyTo = 0;
|
||||||
action.c_channelAdminLogEventActionChangeTitle());
|
auto bodyViaBotId = 0;
|
||||||
break;
|
auto bodyText = GenerateDefaultBannedRightsChangeText(channel, action.vnew_banned_rights, action.vprev_banned_rights);
|
||||||
case mtpc_channelAdminLogEventActionChangeAbout:
|
addPart(new HistoryMessage(history, idManager->next(), bodyFlags, bodyReplyTo, bodyViaBotId, date, peerToUser(from->id), QString(), bodyText));
|
||||||
createChangeAbout(
|
};
|
||||||
action.c_channelAdminLogEventActionChangeAbout());
|
|
||||||
break;
|
auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) {
|
||||||
case mtpc_channelAdminLogEventActionChangeUsername:
|
auto text = lng_admin_log_stopped_poll(lt_from, fromLinkText);
|
||||||
createChangeUsername(
|
addSimpleServiceMessage(text);
|
||||||
action.c_channelAdminLogEventActionChangeUsername());
|
|
||||||
break;
|
auto detachExistingItem = false;
|
||||||
case mtpc_channelAdminLogEventActionChangePhoto:
|
addPart(history->createItem(
|
||||||
createChangePhoto(
|
PrepareLogMessage(action.vmessage, idManager->next(), date),
|
||||||
action.c_channelAdminLogEventActionChangePhoto());
|
detachExistingItem));
|
||||||
break;
|
};
|
||||||
case mtpc_channelAdminLogEventActionToggleInvites:
|
|
||||||
createToggleInvites(
|
action.match([&](const MTPDchannelAdminLogEventActionChangeTitle &data) {
|
||||||
action.c_channelAdminLogEventActionToggleInvites());
|
createChangeTitle(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionChangeAbout &data) {
|
||||||
case mtpc_channelAdminLogEventActionToggleSignatures:
|
createChangeAbout(data);
|
||||||
createToggleSignatures(
|
}, [&](const MTPDchannelAdminLogEventActionChangeUsername &data) {
|
||||||
action.c_channelAdminLogEventActionToggleSignatures());
|
createChangeUsername(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionChangePhoto &data) {
|
||||||
case mtpc_channelAdminLogEventActionUpdatePinned:
|
createChangePhoto(data);
|
||||||
createUpdatePinned(
|
}, [&](const MTPDchannelAdminLogEventActionToggleInvites &data) {
|
||||||
action.c_channelAdminLogEventActionUpdatePinned());
|
createToggleInvites(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionToggleSignatures &data) {
|
||||||
case mtpc_channelAdminLogEventActionEditMessage:
|
createToggleSignatures(data);
|
||||||
createEditMessage(
|
}, [&](const MTPDchannelAdminLogEventActionUpdatePinned &data) {
|
||||||
action.c_channelAdminLogEventActionEditMessage());
|
createUpdatePinned(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionEditMessage &data) {
|
||||||
case mtpc_channelAdminLogEventActionDeleteMessage:
|
createEditMessage(data);
|
||||||
createDeleteMessage(
|
}, [&](const MTPDchannelAdminLogEventActionDeleteMessage &data) {
|
||||||
action.c_channelAdminLogEventActionDeleteMessage());
|
createDeleteMessage(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionParticipantJoin &) {
|
||||||
case mtpc_channelAdminLogEventActionParticipantJoin:
|
|
||||||
createParticipantJoin();
|
createParticipantJoin();
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionParticipantLeave &) {
|
||||||
case mtpc_channelAdminLogEventActionParticipantLeave:
|
|
||||||
createParticipantLeave();
|
createParticipantLeave();
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionParticipantInvite &data) {
|
||||||
case mtpc_channelAdminLogEventActionParticipantInvite:
|
createParticipantInvite(data);
|
||||||
createParticipantInvite(
|
}, [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &data) {
|
||||||
action.c_channelAdminLogEventActionParticipantInvite());
|
createParticipantToggleBan(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &data) {
|
||||||
case mtpc_channelAdminLogEventActionParticipantToggleBan:
|
createParticipantToggleAdmin(data);
|
||||||
createParticipantToggleBan(
|
}, [&](const MTPDchannelAdminLogEventActionChangeStickerSet &data) {
|
||||||
action.c_channelAdminLogEventActionParticipantToggleBan());
|
createChangeStickerSet(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionTogglePreHistoryHidden &data) {
|
||||||
case mtpc_channelAdminLogEventActionParticipantToggleAdmin:
|
createTogglePreHistoryHidden(data);
|
||||||
createParticipantToggleAdmin(
|
}, [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &data) {
|
||||||
action.c_channelAdminLogEventActionParticipantToggleAdmin());
|
createDefaultBannedRights(data);
|
||||||
break;
|
}, [&](const MTPDchannelAdminLogEventActionStopPoll &data) {
|
||||||
case mtpc_channelAdminLogEventActionChangeStickerSet:
|
createStopPoll(data);
|
||||||
createChangeStickerSet(
|
});
|
||||||
action.c_channelAdminLogEventActionChangeStickerSet());
|
|
||||||
break;
|
|
||||||
case mtpc_channelAdminLogEventActionTogglePreHistoryHidden:
|
|
||||||
createTogglePreHistoryHidden(
|
|
||||||
action.c_channelAdminLogEventActionTogglePreHistoryHidden());
|
|
||||||
break;
|
|
||||||
default: Unexpected("channelAdminLogEventAction type in AdminLog::Item::Item()");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AdminLog
|
} // namespace AdminLog
|
||||||
|
|
Loading…
Reference in New Issue