Add default permissions changes to admin log.

This commit is contained in:
John Preston 2019-01-08 17:54:48 +04:00
parent eff90395b6
commit ff728e2fc1
2 changed files with 95 additions and 78 deletions

View File

@ -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_left" = "{from} left the group";
"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_banned" = "banned {user}";
"lng_admin_log_restricted" = "changed restrictions for {user} {until}";
"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_set" = "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_stickers" = "Send stickers & GIFs";
"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_post_messages" = "Post messages";
"lng_admin_log_admin_edit_messages" = "Edit messages";

View File

@ -196,8 +196,7 @@ TextWithEntities GenerateAdminChangeText(
return result;
};
TextWithEntities GenerateBannedChangeText(
const TextWithEntities &user,
QString GenerateBannedChangeText(
const MTPChatBannedRights *newRights,
const MTPChatBannedRights *prevRights) {
Expects(!newRights || newRights->type() == mtpc_chatBannedRights);
@ -206,8 +205,32 @@ TextWithEntities GenerateBannedChangeText(
using Flag = MTPDchatBannedRights::Flag;
using Flags = MTPDchatBannedRights::Flags;
auto newFlags = newRights ? newRights->c_chatBannedRights().vflags.v : MTPDchatBannedRights::Flags(0);
auto prevFlags = prevRights ? prevRights->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 : 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 indefinitely = ChannelData::IsRestrictedForever(newUntil);
if (newFlags & Flag::f_view_messages) {
@ -223,21 +246,12 @@ TextWithEntities GenerateBannedChangeText(
user,
lt_until,
TextWithEntities { untilText });
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);
const auto changes = GenerateBannedChangeText(newRights, prevRights);
if (!changes.isEmpty()) {
result.text.append('\n' + changes);
}
return result;
};
}
auto GenerateUserString(MTPint userId) {
// User name in "User name (@username)" format with entities.
@ -314,6 +328,16 @@ TextWithEntities GenerateParticipantChangeText(not_null<ChannelData*> channel, c
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
OwnedItem::OwnedItem(std::nullptr_t) {
@ -575,71 +599,61 @@ void GenerateItems(
addSimpleServiceMessage(text(lt_from, fromLinkText));
};
switch (action.type()) {
case mtpc_channelAdminLogEventActionChangeTitle:
createChangeTitle(
action.c_channelAdminLogEventActionChangeTitle());
break;
case mtpc_channelAdminLogEventActionChangeAbout:
createChangeAbout(
action.c_channelAdminLogEventActionChangeAbout());
break;
case mtpc_channelAdminLogEventActionChangeUsername:
createChangeUsername(
action.c_channelAdminLogEventActionChangeUsername());
break;
case mtpc_channelAdminLogEventActionChangePhoto:
createChangePhoto(
action.c_channelAdminLogEventActionChangePhoto());
break;
case mtpc_channelAdminLogEventActionToggleInvites:
createToggleInvites(
action.c_channelAdminLogEventActionToggleInvites());
break;
case mtpc_channelAdminLogEventActionToggleSignatures:
createToggleSignatures(
action.c_channelAdminLogEventActionToggleSignatures());
break;
case mtpc_channelAdminLogEventActionUpdatePinned:
createUpdatePinned(
action.c_channelAdminLogEventActionUpdatePinned());
break;
case mtpc_channelAdminLogEventActionEditMessage:
createEditMessage(
action.c_channelAdminLogEventActionEditMessage());
break;
case mtpc_channelAdminLogEventActionDeleteMessage:
createDeleteMessage(
action.c_channelAdminLogEventActionDeleteMessage());
break;
case mtpc_channelAdminLogEventActionParticipantJoin:
auto createDefaultBannedRights = [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &action) {
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
auto bodyReplyTo = 0;
auto bodyViaBotId = 0;
auto bodyText = GenerateDefaultBannedRightsChangeText(channel, action.vnew_banned_rights, action.vprev_banned_rights);
addPart(new HistoryMessage(history, idManager->next(), bodyFlags, bodyReplyTo, bodyViaBotId, date, peerToUser(from->id), QString(), bodyText));
};
auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) {
auto text = lng_admin_log_stopped_poll(lt_from, fromLinkText);
addSimpleServiceMessage(text);
auto detachExistingItem = false;
addPart(history->createItem(
PrepareLogMessage(action.vmessage, idManager->next(), date),
detachExistingItem));
};
action.match([&](const MTPDchannelAdminLogEventActionChangeTitle &data) {
createChangeTitle(data);
}, [&](const MTPDchannelAdminLogEventActionChangeAbout &data) {
createChangeAbout(data);
}, [&](const MTPDchannelAdminLogEventActionChangeUsername &data) {
createChangeUsername(data);
}, [&](const MTPDchannelAdminLogEventActionChangePhoto &data) {
createChangePhoto(data);
}, [&](const MTPDchannelAdminLogEventActionToggleInvites &data) {
createToggleInvites(data);
}, [&](const MTPDchannelAdminLogEventActionToggleSignatures &data) {
createToggleSignatures(data);
}, [&](const MTPDchannelAdminLogEventActionUpdatePinned &data) {
createUpdatePinned(data);
}, [&](const MTPDchannelAdminLogEventActionEditMessage &data) {
createEditMessage(data);
}, [&](const MTPDchannelAdminLogEventActionDeleteMessage &data) {
createDeleteMessage(data);
}, [&](const MTPDchannelAdminLogEventActionParticipantJoin &) {
createParticipantJoin();
break;
case mtpc_channelAdminLogEventActionParticipantLeave:
}, [&](const MTPDchannelAdminLogEventActionParticipantLeave &) {
createParticipantLeave();
break;
case mtpc_channelAdminLogEventActionParticipantInvite:
createParticipantInvite(
action.c_channelAdminLogEventActionParticipantInvite());
break;
case mtpc_channelAdminLogEventActionParticipantToggleBan:
createParticipantToggleBan(
action.c_channelAdminLogEventActionParticipantToggleBan());
break;
case mtpc_channelAdminLogEventActionParticipantToggleAdmin:
createParticipantToggleAdmin(
action.c_channelAdminLogEventActionParticipantToggleAdmin());
break;
case mtpc_channelAdminLogEventActionChangeStickerSet:
createChangeStickerSet(
action.c_channelAdminLogEventActionChangeStickerSet());
break;
case mtpc_channelAdminLogEventActionTogglePreHistoryHidden:
createTogglePreHistoryHidden(
action.c_channelAdminLogEventActionTogglePreHistoryHidden());
break;
default: Unexpected("channelAdminLogEventAction type in AdminLog::Item::Item()");
}
}, [&](const MTPDchannelAdminLogEventActionParticipantInvite &data) {
createParticipantInvite(data);
}, [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &data) {
createParticipantToggleBan(data);
}, [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &data) {
createParticipantToggleAdmin(data);
}, [&](const MTPDchannelAdminLogEventActionChangeStickerSet &data) {
createChangeStickerSet(data);
}, [&](const MTPDchannelAdminLogEventActionTogglePreHistoryHidden &data) {
createTogglePreHistoryHidden(data);
}, [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &data) {
createDefaultBannedRights(data);
}, [&](const MTPDchannelAdminLogEventActionStopPoll &data) {
createStopPoll(data);
});
}
} // namespace AdminLog