2017-06-18 13:08:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-06-18 13:08:49 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-06-18 13:08:49 +00:00
|
|
|
*/
|
2018-01-09 17:08:31 +00:00
|
|
|
#include "history/admin_log/history_admin_log_item.h"
|
2017-06-18 13:08:49 +00:00
|
|
|
|
2018-01-10 13:13:33 +00:00
|
|
|
#include "history/admin_log/history_admin_log_inner.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
2019-06-14 16:04:45 +00:00
|
|
|
#include "history/history_location_manager.h"
|
2017-06-22 15:11:41 +00:00
|
|
|
#include "history/history_service.h"
|
|
|
|
#include "history/history_message.h"
|
2018-01-13 12:45:11 +00:00
|
|
|
#include "history/history.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_channel.h"
|
|
|
|
#include "data/data_user.h"
|
2018-01-17 16:21:01 +00:00
|
|
|
#include "data/data_session.h"
|
2017-06-18 13:08:49 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-06-18 16:53:27 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2017-08-19 16:46:17 +00:00
|
|
|
#include "boxes/sticker_set_box.h"
|
2019-07-10 17:28:33 +00:00
|
|
|
#include "base/unixtime.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2019-06-24 15:09:37 +00:00
|
|
|
#include "mainwindow.h" // App::wnd()->sessionController
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2017-06-18 13:08:49 +00:00
|
|
|
|
|
|
|
namespace AdminLog {
|
|
|
|
namespace {
|
|
|
|
|
2017-06-20 16:03:18 +00:00
|
|
|
TextWithEntities PrepareText(const QString &value, const QString &emptyValue) {
|
2017-07-06 11:37:42 +00:00
|
|
|
auto result = TextWithEntities { TextUtilities::Clean(value) };
|
2017-06-20 16:03:18 +00:00
|
|
|
if (result.text.isEmpty()) {
|
|
|
|
result.text = emptyValue;
|
|
|
|
if (!emptyValue.isEmpty()) {
|
2019-04-08 15:10:06 +00:00
|
|
|
result.entities.push_back({
|
|
|
|
EntityType::Italic,
|
|
|
|
0,
|
|
|
|
emptyValue.size() });
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-07-06 11:37:42 +00:00
|
|
|
TextUtilities::ParseEntities(result, TextParseLinks | TextParseMentions | TextParseHashtags | TextParseBotCommands);
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-12-17 08:16:06 +00:00
|
|
|
MTPMessage PrepareLogMessage(
|
|
|
|
const MTPMessage &message,
|
|
|
|
MsgId newId,
|
|
|
|
TimeId newDate) {
|
|
|
|
return message.match([&](const MTPDmessageEmpty &) {
|
|
|
|
return MTP_messageEmpty(MTP_int(newId));
|
|
|
|
}, [&](const MTPDmessageService &message) {
|
|
|
|
const auto removeFlags = MTPDmessageService::Flag::f_out
|
2017-12-03 14:38:05 +00:00
|
|
|
| MTPDmessageService::Flag::f_post
|
|
|
|
/* | MTPDmessageService::Flag::f_reply_to_msg_id*/;
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto flags = message.vflags().v & ~removeFlags;
|
|
|
|
const auto fromId = message.vfrom_id();
|
2017-12-03 14:38:05 +00:00
|
|
|
return MTP_messageService(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(newId),
|
2019-07-05 13:38:38 +00:00
|
|
|
MTP_int(message.vfrom_id().value_or_empty()),
|
|
|
|
message.vto_id(),
|
|
|
|
MTP_int(0), // reply_to_msg_id
|
2017-12-03 14:38:05 +00:00
|
|
|
MTP_int(newDate),
|
2019-07-05 13:38:38 +00:00
|
|
|
message.vaction());
|
2018-12-17 08:16:06 +00:00
|
|
|
}, [&](const MTPDmessage &message) {
|
|
|
|
const auto removeFlags = MTPDmessage::Flag::f_out
|
2017-12-03 14:38:05 +00:00
|
|
|
| MTPDmessage::Flag::f_post
|
|
|
|
| MTPDmessage::Flag::f_reply_to_msg_id
|
|
|
|
| MTPDmessage::Flag::f_edit_date
|
2019-08-08 10:15:59 +00:00
|
|
|
| MTPDmessage::Flag::f_grouped_id
|
|
|
|
//| MTPDmessage::Flag::f_reactions
|
|
|
|
| MTPDmessage::Flag::f_restriction_reason;
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto flags = message.vflags().v & ~removeFlags;
|
|
|
|
const auto fwdFrom = message.vfwd_from();
|
|
|
|
const auto media = message.vmedia();
|
|
|
|
const auto markup = message.vreply_markup();
|
|
|
|
const auto entities = message.ventities();
|
2017-12-03 14:38:05 +00:00
|
|
|
return MTP_message(
|
|
|
|
MTP_flags(flags),
|
|
|
|
MTP_int(newId),
|
2019-07-05 13:38:38 +00:00
|
|
|
MTP_int(message.vfrom_id().value_or_empty()),
|
|
|
|
message.vto_id(),
|
|
|
|
fwdFrom ? *fwdFrom : MTPMessageFwdHeader(),
|
|
|
|
MTP_int(message.vvia_bot_id().value_or_empty()),
|
|
|
|
MTP_int(0), // reply_to_msg_id
|
2017-12-03 14:38:05 +00:00
|
|
|
MTP_int(newDate),
|
2019-07-05 13:38:38 +00:00
|
|
|
message.vmessage(),
|
|
|
|
media ? *media : MTPMessageMedia(),
|
|
|
|
markup ? *markup : MTPReplyMarkup(),
|
|
|
|
entities ? *entities : MTPVector<MTPMessageEntity>(),
|
|
|
|
MTP_int(message.vviews().value_or_empty()),
|
|
|
|
MTP_int(0), // edit_date
|
|
|
|
MTP_string(),
|
2019-08-08 10:15:59 +00:00
|
|
|
MTP_long(0), // grouped_id
|
|
|
|
//MTPMessageReactions(),
|
|
|
|
MTPVector<MTPRestrictionReason>());
|
2018-12-17 08:16:06 +00:00
|
|
|
});
|
2017-06-18 13:08:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 16:03:18 +00:00
|
|
|
bool MediaCanHaveCaption(const MTPMessage &message) {
|
2017-06-18 13:08:49 +00:00
|
|
|
if (message.type() != mtpc_message) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto &data = message.c_message();
|
|
|
|
const auto media = data.vmedia();
|
|
|
|
const auto mediaType = media ? media->type() : mtpc_messageMediaEmpty;
|
2017-06-18 13:08:49 +00:00
|
|
|
return (mediaType == mtpc_messageMediaDocument || mediaType == mtpc_messageMediaPhoto);
|
|
|
|
}
|
|
|
|
|
2017-06-20 16:03:18 +00:00
|
|
|
TextWithEntities ExtractEditedText(const MTPMessage &message) {
|
|
|
|
if (message.type() != mtpc_message) {
|
|
|
|
return TextWithEntities();
|
|
|
|
}
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto &data = message.c_message();
|
|
|
|
return {
|
|
|
|
TextUtilities::Clean(qs(data.vmessage())),
|
|
|
|
TextUtilities::EntitiesFromMTP(data.ventities().value_or_empty())
|
|
|
|
};
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto CollectChanges = [](auto &phraseMap, auto plusFlags, auto minusFlags) {
|
|
|
|
auto withPrefix = [&phraseMap](auto flags, QChar prefix) {
|
|
|
|
auto result = QString();
|
|
|
|
for (auto &phrase : phraseMap) {
|
|
|
|
if (flags & phrase.first) {
|
2019-06-19 15:09:03 +00:00
|
|
|
result.append('\n' + (prefix + phrase.second(tr::now)));
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
const auto kMinus = QChar(0x2212);
|
|
|
|
return withPrefix(plusFlags & ~minusFlags, '+') + withPrefix(minusFlags & ~plusFlags, kMinus);
|
|
|
|
};
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
TextWithEntities GenerateAdminChangeText(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const TextWithEntities &user,
|
|
|
|
const MTPChatAdminRights *newRights,
|
|
|
|
const MTPChatAdminRights *prevRights) {
|
|
|
|
Expects(!newRights || newRights->type() == mtpc_chatAdminRights);
|
|
|
|
Expects(!prevRights || prevRights->type() == mtpc_chatAdminRights);
|
|
|
|
|
2019-01-03 14:39:19 +00:00
|
|
|
using Flag = MTPDchatAdminRights::Flag;
|
|
|
|
using Flags = MTPDchatAdminRights::Flags;
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
auto newFlags = newRights ? newRights->c_chatAdminRights().vflags().v : MTPDchatAdminRights::Flags(0);
|
|
|
|
auto prevFlags = prevRights ? prevRights->c_chatAdminRights().vflags().v : MTPDchatAdminRights::Flags(0);
|
2019-06-18 16:53:27 +00:00
|
|
|
auto result = tr::lng_admin_log_promoted(tr::now, lt_user, user, Ui::Text::WithEntities);
|
2017-06-20 16:03:18 +00:00
|
|
|
|
|
|
|
auto useInviteLinkPhrase = channel->isMegagroup() && channel->anyoneCanAddMembers();
|
2019-06-19 15:09:03 +00:00
|
|
|
auto invitePhrase = useInviteLinkPhrase
|
|
|
|
? tr::lng_admin_log_admin_invite_link
|
|
|
|
: tr::lng_admin_log_admin_invite_users;
|
|
|
|
static auto phraseMap = std::map<Flags, tr::phrase<>> {
|
|
|
|
{ Flag::f_change_info, tr::lng_admin_log_admin_change_info },
|
|
|
|
{ Flag::f_post_messages, tr::lng_admin_log_admin_post_messages },
|
|
|
|
{ Flag::f_edit_messages, tr::lng_admin_log_admin_edit_messages },
|
|
|
|
{ Flag::f_delete_messages, tr::lng_admin_log_admin_delete_messages },
|
|
|
|
{ Flag::f_ban_users, tr::lng_admin_log_admin_ban_users },
|
2019-01-03 14:39:19 +00:00
|
|
|
{ Flag::f_invite_users, invitePhrase },
|
2019-06-19 15:09:03 +00:00
|
|
|
{ Flag::f_pin_messages, tr::lng_admin_log_admin_pin_messages },
|
|
|
|
{ Flag::f_add_admins, tr::lng_admin_log_admin_add_admins },
|
2017-06-20 16:03:18 +00:00
|
|
|
};
|
2019-01-03 14:39:19 +00:00
|
|
|
phraseMap[Flag::f_invite_users] = invitePhrase;
|
2017-06-20 16:03:18 +00:00
|
|
|
|
2017-08-15 15:25:14 +00:00
|
|
|
if (!channel->isMegagroup()) {
|
|
|
|
// Don't display "Ban users" changes in channels.
|
|
|
|
newFlags &= ~Flag::f_ban_users;
|
|
|
|
prevFlags &= ~Flag::f_ban_users;
|
|
|
|
}
|
|
|
|
|
2017-06-20 16:03:18 +00:00
|
|
|
auto changes = CollectChanges(phraseMap, newFlags, prevFlags);
|
|
|
|
if (!changes.isEmpty()) {
|
|
|
|
result.text.append('\n' + changes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2019-01-08 13:54:48 +00:00
|
|
|
QString GenerateBannedChangeText(
|
|
|
|
const MTPChatBannedRights *newRights,
|
|
|
|
const MTPChatBannedRights *prevRights) {
|
|
|
|
Expects(!newRights || newRights->type() == mtpc_chatBannedRights);
|
|
|
|
Expects(!prevRights || prevRights->type() == mtpc_chatBannedRights);
|
|
|
|
|
|
|
|
using Flag = MTPDchatBannedRights::Flag;
|
|
|
|
using Flags = MTPDchatBannedRights::Flags;
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
auto newFlags = newRights ? newRights->c_chatBannedRights().vflags().v : Flags(0);
|
|
|
|
auto prevFlags = prevRights ? prevRights->c_chatBannedRights().vflags().v : Flags(0);
|
2019-06-19 15:09:03 +00:00
|
|
|
static auto phraseMap = std::map<Flags, tr::phrase<>>{
|
|
|
|
{ Flag::f_view_messages, tr::lng_admin_log_banned_view_messages },
|
|
|
|
{ Flag::f_send_messages, tr::lng_admin_log_banned_send_messages },
|
|
|
|
{ Flag::f_send_media, tr::lng_admin_log_banned_send_media },
|
|
|
|
{ Flag::f_send_stickers | Flag::f_send_gifs | Flag::f_send_inline | Flag::f_send_games, tr::lng_admin_log_banned_send_stickers },
|
|
|
|
{ Flag::f_embed_links, tr::lng_admin_log_banned_embed_links },
|
|
|
|
{ Flag::f_send_polls, tr::lng_admin_log_banned_send_polls },
|
|
|
|
{ Flag::f_change_info, tr::lng_admin_log_admin_change_info },
|
|
|
|
{ Flag::f_invite_users, tr::lng_admin_log_admin_invite_users },
|
|
|
|
{ Flag::f_pin_messages, tr::lng_admin_log_admin_pin_messages },
|
2019-01-08 13:54:48 +00:00
|
|
|
};
|
|
|
|
return CollectChanges(phraseMap, prevFlags, newFlags);
|
|
|
|
}
|
|
|
|
|
2019-01-04 11:09:48 +00:00
|
|
|
TextWithEntities GenerateBannedChangeText(
|
|
|
|
const TextWithEntities &user,
|
|
|
|
const MTPChatBannedRights *newRights,
|
|
|
|
const MTPChatBannedRights *prevRights) {
|
|
|
|
Expects(!newRights || newRights->type() == mtpc_chatBannedRights);
|
|
|
|
|
2019-01-03 14:39:19 +00:00
|
|
|
using Flag = MTPDchatBannedRights::Flag;
|
|
|
|
using Flags = MTPDchatBannedRights::Flags;
|
2017-06-20 16:03:18 +00:00
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
auto newFlags = newRights ? newRights->c_chatBannedRights().vflags().v : Flags(0);
|
|
|
|
auto newUntil = newRights ? newRights->c_chatBannedRights().vuntil_date().v : TimeId(0);
|
2018-02-03 19:52:35 +00:00
|
|
|
auto indefinitely = ChannelData::IsRestrictedForever(newUntil);
|
2017-06-20 16:03:18 +00:00
|
|
|
if (newFlags & Flag::f_view_messages) {
|
2019-06-18 16:53:27 +00:00
|
|
|
return tr::lng_admin_log_banned(tr::now, lt_user, user, Ui::Text::WithEntities);
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
2018-02-03 19:52:35 +00:00
|
|
|
auto untilText = indefinitely
|
2019-06-18 16:53:27 +00:00
|
|
|
? tr::lng_admin_log_restricted_forever(tr::now)
|
|
|
|
: tr::lng_admin_log_restricted_until(
|
|
|
|
tr::now,
|
2018-02-03 19:52:35 +00:00
|
|
|
lt_date,
|
2019-07-10 17:28:33 +00:00
|
|
|
langDateTime(base::unixtime::parse(newUntil)));
|
2019-06-18 16:53:27 +00:00
|
|
|
auto result = tr::lng_admin_log_restricted(
|
|
|
|
tr::now,
|
2018-03-21 22:26:19 +00:00
|
|
|
lt_user,
|
|
|
|
user,
|
|
|
|
lt_until,
|
2019-06-18 16:53:27 +00:00
|
|
|
TextWithEntities { untilText },
|
|
|
|
Ui::Text::WithEntities);
|
2019-01-08 13:54:48 +00:00
|
|
|
const auto changes = GenerateBannedChangeText(newRights, prevRights);
|
2017-06-20 16:03:18 +00:00
|
|
|
if (!changes.isEmpty()) {
|
|
|
|
result.text.append('\n' + changes);
|
|
|
|
}
|
|
|
|
return result;
|
2019-01-08 13:54:48 +00:00
|
|
|
}
|
2017-06-20 16:03:18 +00:00
|
|
|
|
|
|
|
auto GenerateUserString(MTPint userId) {
|
|
|
|
// User name in "User name (@username)" format with entities.
|
2019-01-18 12:27:37 +00:00
|
|
|
auto user = Auth().data().user(userId.v);
|
2017-06-20 16:03:18 +00:00
|
|
|
auto name = TextWithEntities { App::peerName(user) };
|
2017-09-26 11:49:16 +00:00
|
|
|
auto entityData = QString::number(user->id)
|
|
|
|
+ '.'
|
|
|
|
+ QString::number(user->accessHash());
|
2019-04-08 15:10:06 +00:00
|
|
|
name.entities.push_back({
|
|
|
|
EntityType::MentionName,
|
2017-09-26 11:49:16 +00:00
|
|
|
0,
|
|
|
|
name.text.size(),
|
2019-04-08 15:10:06 +00:00
|
|
|
entityData });
|
2017-06-20 16:03:18 +00:00
|
|
|
auto username = user->userName();
|
|
|
|
if (username.isEmpty()) {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
auto mention = TextWithEntities { '@' + username };
|
2019-04-08 15:10:06 +00:00
|
|
|
mention.entities.push_back({
|
|
|
|
EntityType::Mention,
|
|
|
|
0,
|
|
|
|
mention.text.size() });
|
2019-06-18 16:53:27 +00:00
|
|
|
return tr::lng_admin_log_user_with_username(
|
|
|
|
tr::now,
|
|
|
|
lt_name,
|
|
|
|
name,
|
|
|
|
lt_mention,
|
|
|
|
mention,
|
|
|
|
Ui::Text::WithEntities);
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 19:54:05 +00:00
|
|
|
auto GenerateParticipantChangeTextInner(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
const MTPChannelParticipant &participant,
|
|
|
|
const MTPChannelParticipant *oldParticipant) {
|
2019-01-10 11:15:13 +00:00
|
|
|
const auto oldType = oldParticipant ? oldParticipant->type() : 0;
|
|
|
|
return participant.match([&](const MTPDchannelParticipantCreator &data) {
|
2017-11-20 19:54:05 +00:00
|
|
|
// No valid string here :(
|
2019-06-24 13:08:19 +00:00
|
|
|
return tr::lng_admin_log_transferred(
|
2019-06-18 16:53:27 +00:00
|
|
|
tr::now,
|
2017-11-20 19:54:05 +00:00
|
|
|
lt_user,
|
2019-07-05 13:38:38 +00:00
|
|
|
GenerateUserString(data.vuser_id()),
|
2019-06-18 16:53:27 +00:00
|
|
|
Ui::Text::WithEntities);
|
2017-11-20 19:54:05 +00:00
|
|
|
}, [&](const MTPDchannelParticipantAdmin &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto user = GenerateUserString(data.vuser_id());
|
2017-11-20 19:54:05 +00:00
|
|
|
return GenerateAdminChangeText(
|
|
|
|
channel,
|
|
|
|
user,
|
2019-07-05 13:38:38 +00:00
|
|
|
&data.vadmin_rights(),
|
2017-11-20 19:54:05 +00:00
|
|
|
(oldType == mtpc_channelParticipantAdmin)
|
2019-07-05 13:38:38 +00:00
|
|
|
? &oldParticipant->c_channelParticipantAdmin().vadmin_rights()
|
2017-11-20 19:54:05 +00:00
|
|
|
: nullptr);
|
|
|
|
}, [&](const MTPDchannelParticipantBanned &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto user = GenerateUserString(data.vuser_id());
|
2017-11-20 19:54:05 +00:00
|
|
|
return GenerateBannedChangeText(
|
|
|
|
user,
|
2019-07-05 13:38:38 +00:00
|
|
|
&data.vbanned_rights(),
|
2017-11-20 19:54:05 +00:00
|
|
|
(oldType == mtpc_channelParticipantBanned)
|
2019-07-05 13:38:38 +00:00
|
|
|
? &oldParticipant->c_channelParticipantBanned().vbanned_rights()
|
2017-11-20 19:54:05 +00:00
|
|
|
: nullptr);
|
2017-11-21 11:59:18 +00:00
|
|
|
}, [&](const auto &data) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto user = GenerateUserString(data.vuser_id());
|
2017-06-20 16:03:18 +00:00
|
|
|
if (oldType == mtpc_channelParticipantAdmin) {
|
2017-11-20 19:54:05 +00:00
|
|
|
return GenerateAdminChangeText(
|
|
|
|
channel,
|
|
|
|
user,
|
|
|
|
nullptr,
|
2019-07-05 13:38:38 +00:00
|
|
|
&oldParticipant->c_channelParticipantAdmin().vadmin_rights());
|
2017-06-20 16:03:18 +00:00
|
|
|
} else if (oldType == mtpc_channelParticipantBanned) {
|
2017-11-20 19:54:05 +00:00
|
|
|
return GenerateBannedChangeText(
|
|
|
|
user,
|
|
|
|
nullptr,
|
2019-07-05 13:38:38 +00:00
|
|
|
&oldParticipant->c_channelParticipantBanned().vbanned_rights());
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
2019-06-18 16:53:27 +00:00
|
|
|
return tr::lng_admin_log_invited(tr::now, lt_user, user, Ui::Text::WithEntities);
|
2017-11-20 19:54:05 +00:00
|
|
|
});
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
TextWithEntities GenerateParticipantChangeText(not_null<ChannelData*> channel, const MTPChannelParticipant &participant, const MTPChannelParticipant *oldParticipant = nullptr) {
|
2017-06-20 16:03:18 +00:00
|
|
|
auto result = GenerateParticipantChangeTextInner(channel, participant, oldParticipant);
|
2019-04-08 15:10:06 +00:00
|
|
|
result.entities.push_front(EntityInText(EntityType::Italic, 0, result.text.size()));
|
2017-06-20 16:03:18 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-08 13:54:48 +00:00
|
|
|
TextWithEntities GenerateDefaultBannedRightsChangeText(not_null<ChannelData*> channel, const MTPChatBannedRights &rights, const MTPChatBannedRights &oldRights) {
|
2019-06-19 15:09:03 +00:00
|
|
|
auto result = TextWithEntities{ tr::lng_admin_log_changed_default_permissions(tr::now) };
|
2019-01-08 13:54:48 +00:00
|
|
|
const auto changes = GenerateBannedChangeText(&rights, &oldRights);
|
|
|
|
if (!changes.isEmpty()) {
|
|
|
|
result.text.append('\n' + changes);
|
|
|
|
}
|
2019-04-08 15:10:06 +00:00
|
|
|
result.entities.push_front(EntityInText(EntityType::Italic, 0, result.text.size()));
|
2019-01-08 13:54:48 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-18 13:08:49 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-10-05 16:02:33 +00:00
|
|
|
OwnedItem::OwnedItem(std::nullptr_t) {
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
OwnedItem::OwnedItem(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
2018-01-11 19:33:26 +00:00
|
|
|
not_null<HistoryItem*> data)
|
2018-01-10 13:13:33 +00:00
|
|
|
: _data(data)
|
2018-01-17 16:21:01 +00:00
|
|
|
, _view(_data->createView(delegate)) {
|
2018-01-10 13:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OwnedItem::OwnedItem(OwnedItem &&other)
|
|
|
|
: _data(base::take(other._data))
|
|
|
|
, _view(base::take(other._view)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnedItem &OwnedItem::operator=(OwnedItem &&other) {
|
|
|
|
_data = base::take(other._data);
|
|
|
|
_view = base::take(other._view);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnedItem::~OwnedItem() {
|
|
|
|
_view = nullptr;
|
|
|
|
if (_data) {
|
|
|
|
_data->destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 22:26:19 +00:00
|
|
|
void OwnedItem::refreshView(
|
|
|
|
not_null<HistoryView::ElementDelegate*> delegate) {
|
|
|
|
_view = _data->createView(delegate);
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
void GenerateItems(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate,
|
2018-01-11 19:33:26 +00:00
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDchannelAdminLogEvent &event,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(OwnedItem item)> callback) {
|
2017-06-21 23:54:38 +00:00
|
|
|
Expects(history->peer->isChannel());
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
auto id = event.vid().v;
|
|
|
|
auto from = Auth().data().user(event.vuser_id().v);
|
2017-06-21 23:54:38 +00:00
|
|
|
auto channel = history->peer->asChannel();
|
2019-07-05 13:38:38 +00:00
|
|
|
auto &action = event.vaction();
|
|
|
|
auto date = event.vdate().v;
|
2018-01-11 19:33:26 +00:00
|
|
|
auto addPart = [&](not_null<HistoryItem*> item) {
|
2018-01-17 16:21:01 +00:00
|
|
|
return callback(OwnedItem(delegate, item));
|
2017-06-21 23:54:38 +00:00
|
|
|
};
|
2017-06-18 13:08:49 +00:00
|
|
|
|
|
|
|
using Flag = MTPDmessage::Flag;
|
2017-06-21 23:54:38 +00:00
|
|
|
auto fromName = App::peerName(from);
|
2017-07-05 18:11:31 +00:00
|
|
|
auto fromLink = from->createOpenLink();
|
2017-06-18 13:08:49 +00:00
|
|
|
auto fromLinkText = textcmdLink(1, fromName);
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto addSimpleServiceMessage = [&](const QString &text, PhotoData *photo = nullptr) {
|
2017-06-18 13:08:49 +00:00
|
|
|
auto message = HistoryService::PreparedText { text };
|
|
|
|
message.links.push_back(fromLink);
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeServiceMessage(
|
|
|
|
history,
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
date,
|
|
|
|
message,
|
|
|
|
MTPDmessage::Flags(0),
|
|
|
|
peerToUser(from->id),
|
|
|
|
photo));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createChangeTitle = [&](const MTPDchannelAdminLogEventActionChangeTitle &action) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
|
|
|
? tr::lng_action_changed_title
|
|
|
|
: tr::lng_admin_log_changed_title_channel)(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText,
|
|
|
|
lt_title,
|
2019-07-05 13:38:38 +00:00
|
|
|
qs(action.vnew_value()));
|
2017-06-18 13:08:49 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createChangeAbout = [&](const MTPDchannelAdminLogEventActionChangeAbout &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto newValue = qs(action.vnew_value());
|
|
|
|
auto oldValue = qs(action.vprev_value());
|
2017-06-21 23:54:38 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
2019-06-19 16:39:25 +00:00
|
|
|
? (newValue.isEmpty()
|
|
|
|
? tr::lng_admin_log_removed_description_group
|
|
|
|
: tr::lng_admin_log_changed_description_group)
|
|
|
|
: (newValue.isEmpty()
|
|
|
|
? tr::lng_admin_log_removed_description_channel
|
|
|
|
: tr::lng_admin_log_changed_description_channel)
|
|
|
|
)(tr::now, lt_from, fromLinkText);
|
2017-06-18 13:08:49 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
|
|
|
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
2019-09-06 07:53:44 +00:00
|
|
|
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyReplyTo = 0;
|
|
|
|
auto bodyViaBotId = 0;
|
|
|
|
auto newDescription = PrepareText(newValue, QString());
|
2019-08-09 19:19:23 +00:00
|
|
|
auto body = history->owner().makeMessage(
|
|
|
|
history,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
bodyFlags,
|
|
|
|
bodyClientFlags,
|
|
|
|
bodyReplyTo,
|
|
|
|
bodyViaBotId,
|
|
|
|
date,
|
|
|
|
peerToUser(from->id),
|
|
|
|
QString(),
|
|
|
|
newDescription);
|
2017-06-18 13:08:49 +00:00
|
|
|
if (!oldValue.isEmpty()) {
|
|
|
|
auto oldDescription = PrepareText(oldValue, QString());
|
2019-06-19 15:09:03 +00:00
|
|
|
body->addLogEntryOriginal(id, tr::lng_admin_log_previous_description(tr::now), oldDescription);
|
2017-06-18 13:08:49 +00:00
|
|
|
}
|
|
|
|
addPart(body);
|
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createChangeUsername = [&](const MTPDchannelAdminLogEventActionChangeUsername &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto newValue = qs(action.vnew_value());
|
|
|
|
auto oldValue = qs(action.vprev_value());
|
2017-06-21 23:54:38 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
2019-06-19 16:39:25 +00:00
|
|
|
? (newValue.isEmpty()
|
|
|
|
? tr::lng_admin_log_removed_link_group
|
|
|
|
: tr::lng_admin_log_changed_link_group)
|
|
|
|
: (newValue.isEmpty()
|
|
|
|
? tr::lng_admin_log_removed_link_channel
|
|
|
|
: tr::lng_admin_log_changed_link_channel)
|
|
|
|
)(tr::now, lt_from, fromLinkText);
|
2017-06-18 13:08:49 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
|
|
|
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
2019-09-06 07:53:44 +00:00
|
|
|
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyReplyTo = 0;
|
|
|
|
auto bodyViaBotId = 0;
|
2019-01-21 13:42:21 +00:00
|
|
|
auto newLink = newValue.isEmpty() ? TextWithEntities() : PrepareText(Core::App().createInternalLinkFull(newValue), QString());
|
2019-08-09 19:19:23 +00:00
|
|
|
auto body = history->owner().makeMessage(
|
|
|
|
history,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
bodyFlags,
|
|
|
|
bodyClientFlags,
|
|
|
|
bodyReplyTo,
|
|
|
|
bodyViaBotId,
|
|
|
|
date,
|
|
|
|
peerToUser(from->id),
|
|
|
|
QString(),
|
|
|
|
newLink);
|
2017-06-18 13:08:49 +00:00
|
|
|
if (!oldValue.isEmpty()) {
|
2019-01-21 13:42:21 +00:00
|
|
|
auto oldLink = PrepareText(Core::App().createInternalLinkFull(oldValue), QString());
|
2019-06-19 15:09:03 +00:00
|
|
|
body->addLogEntryOriginal(id, tr::lng_admin_log_previous_link(tr::now), oldLink);
|
2017-06-18 13:08:49 +00:00
|
|
|
}
|
|
|
|
addPart(body);
|
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createChangePhoto = [&](const MTPDchannelAdminLogEventActionChangePhoto &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
action.vnew_photo().match([&](const MTPDphoto &data) {
|
2019-03-22 14:19:43 +00:00
|
|
|
auto photo = Auth().data().processPhoto(data);
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
|
|
|
? tr::lng_admin_log_changed_photo_group
|
|
|
|
: tr::lng_admin_log_changed_photo_channel)(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText);
|
2017-06-30 10:35:35 +00:00
|
|
|
addSimpleServiceMessage(text, photo);
|
2019-03-22 14:19:43 +00:00
|
|
|
}, [&](const MTPDphotoEmpty &data) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
|
|
|
? tr::lng_admin_log_removed_photo_group
|
|
|
|
: tr::lng_admin_log_removed_photo_channel)(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText);
|
2017-06-30 10:35:35 +00:00
|
|
|
addSimpleServiceMessage(text);
|
2019-03-22 14:19:43 +00:00
|
|
|
});
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createToggleInvites = [&](const MTPDchannelAdminLogEventActionToggleInvites &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto enabled = (action.vnew_value().type() == mtpc_boolTrue);
|
2017-11-20 19:54:05 +00:00
|
|
|
auto text = (enabled
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_admin_log_invites_enabled
|
|
|
|
: tr::lng_admin_log_invites_disabled);
|
|
|
|
addSimpleServiceMessage(text(tr::now, lt_from, fromLinkText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createToggleSignatures = [&](const MTPDchannelAdminLogEventActionToggleSignatures &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto enabled = (action.vnew_value().type() == mtpc_boolTrue);
|
2017-11-20 19:54:05 +00:00
|
|
|
auto text = (enabled
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_admin_log_signatures_enabled
|
|
|
|
: tr::lng_admin_log_signatures_disabled);
|
|
|
|
addSimpleServiceMessage(text(tr::now, lt_from, fromLinkText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createUpdatePinned = [&](const MTPDchannelAdminLogEventActionUpdatePinned &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (action.vmessage().type() == mtpc_messageEmpty) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_admin_log_unpinned_message(tr::now, lt_from, fromLinkText);
|
2017-06-28 15:22:56 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_admin_log_pinned_message(tr::now, lt_from, fromLinkText);
|
2017-06-28 15:22:56 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
|
|
|
|
auto detachExistingItem = false;
|
2018-01-14 16:02:25 +00:00
|
|
|
addPart(history->createItem(
|
|
|
|
PrepareLogMessage(
|
2019-07-05 13:38:38 +00:00
|
|
|
action.vmessage(),
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2018-02-03 19:52:35 +00:00
|
|
|
date),
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2018-01-14 16:02:25 +00:00
|
|
|
detachExistingItem));
|
2017-06-28 15:22:56 +00:00
|
|
|
}
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createEditMessage = [&](const MTPDchannelAdminLogEventActionEditMessage &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto newValue = ExtractEditedText(action.vnew_message());
|
|
|
|
auto canHaveCaption = MediaCanHaveCaption(action.vnew_message());
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = (!canHaveCaption
|
|
|
|
? tr::lng_admin_log_edited_message
|
|
|
|
: newValue.text.isEmpty()
|
|
|
|
? tr::lng_admin_log_removed_caption
|
|
|
|
: tr::lng_admin_log_edited_caption)(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText);
|
2017-06-18 13:08:49 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
|
2019-07-05 13:38:38 +00:00
|
|
|
auto oldValue = ExtractEditedText(action.vprev_message());
|
2017-06-18 13:08:49 +00:00
|
|
|
auto detachExistingItem = false;
|
2018-01-14 16:02:25 +00:00
|
|
|
auto body = history->createItem(
|
|
|
|
PrepareLogMessage(
|
2019-07-05 13:38:38 +00:00
|
|
|
action.vnew_message(),
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2018-02-03 19:52:35 +00:00
|
|
|
date),
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2018-01-14 16:02:25 +00:00
|
|
|
detachExistingItem);
|
2017-06-24 17:21:01 +00:00
|
|
|
if (oldValue.text.isEmpty()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
oldValue = PrepareText(QString(), tr::lng_admin_log_empty_text(tr::now));
|
2017-06-20 16:03:18 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
|
|
|
|
body->addLogEntryOriginal(
|
|
|
|
id,
|
|
|
|
(canHaveCaption
|
|
|
|
? tr::lng_admin_log_previous_caption
|
|
|
|
: tr::lng_admin_log_previous_message)(tr::now),
|
|
|
|
oldValue);
|
2017-06-20 16:03:18 +00:00
|
|
|
addPart(body);
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createDeleteMessage = [&](const MTPDchannelAdminLogEventActionDeleteMessage &action) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_admin_log_deleted_message(tr::now, lt_from, fromLinkText);
|
2017-06-18 13:08:49 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
|
|
|
|
auto detachExistingItem = false;
|
2018-01-14 16:02:25 +00:00
|
|
|
addPart(history->createItem(
|
2019-08-08 14:13:26 +00:00
|
|
|
PrepareLogMessage(action.vmessage(), history->nextNonHistoryEntryId(), date),
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2018-01-14 16:02:25 +00:00
|
|
|
detachExistingItem));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createParticipantJoin = [&]() {
|
2017-11-20 19:54:05 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_admin_log_participant_joined
|
|
|
|
: tr::lng_admin_log_participant_joined_channel);
|
|
|
|
addSimpleServiceMessage(text(tr::now, lt_from, fromLinkText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createParticipantLeave = [&]() {
|
2017-11-20 19:54:05 +00:00
|
|
|
auto text = (channel->isMegagroup()
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_admin_log_participant_left
|
|
|
|
: tr::lng_admin_log_participant_left_channel);
|
|
|
|
addSimpleServiceMessage(text(tr::now, lt_from, fromLinkText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createParticipantInvite = [&](const MTPDchannelAdminLogEventActionParticipantInvite &action) {
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
2019-09-06 07:53:44 +00:00
|
|
|
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyReplyTo = 0;
|
|
|
|
auto bodyViaBotId = 0;
|
2019-07-05 13:38:38 +00:00
|
|
|
auto bodyText = GenerateParticipantChangeText(channel, action.vparticipant());
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeMessage(
|
|
|
|
history,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
bodyFlags,
|
|
|
|
bodyClientFlags,
|
|
|
|
bodyReplyTo,
|
|
|
|
bodyViaBotId,
|
|
|
|
date,
|
|
|
|
peerToUser(from->id),
|
|
|
|
QString(),
|
|
|
|
bodyText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createParticipantToggleBan = [&](const MTPDchannelAdminLogEventActionParticipantToggleBan &action) {
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
2019-09-06 07:53:44 +00:00
|
|
|
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyReplyTo = 0;
|
|
|
|
auto bodyViaBotId = 0;
|
2019-07-05 13:38:38 +00:00
|
|
|
auto bodyText = GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant());
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeMessage(
|
|
|
|
history,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
bodyFlags,
|
|
|
|
bodyClientFlags,
|
|
|
|
bodyReplyTo,
|
|
|
|
bodyViaBotId,
|
|
|
|
date,
|
|
|
|
peerToUser(from->id),
|
|
|
|
QString(),
|
|
|
|
bodyText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-06-21 23:54:38 +00:00
|
|
|
auto createParticipantToggleAdmin = [&](const MTPDchannelAdminLogEventActionParticipantToggleAdmin &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
if (action.vnew_participant().type() == mtpc_channelParticipantAdmin
|
|
|
|
&& action.vprev_participant().type() == mtpc_channelParticipantCreator) {
|
2019-06-24 13:08:19 +00:00
|
|
|
// In case of ownership transfer we show that message in
|
|
|
|
// the "User > Creator" part and skip the "Creator > Admin" part.
|
|
|
|
return;
|
|
|
|
}
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
2019-09-06 07:53:44 +00:00
|
|
|
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
2017-06-18 13:08:49 +00:00
|
|
|
auto bodyReplyTo = 0;
|
|
|
|
auto bodyViaBotId = 0;
|
2019-07-05 13:38:38 +00:00
|
|
|
auto bodyText = GenerateParticipantChangeText(channel, action.vnew_participant(), &action.vprev_participant());
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeMessage(
|
|
|
|
history,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
bodyFlags,
|
|
|
|
bodyClientFlags,
|
|
|
|
bodyReplyTo,
|
|
|
|
bodyViaBotId,
|
|
|
|
date,
|
|
|
|
peerToUser(from->id),
|
|
|
|
QString(),
|
|
|
|
bodyText));
|
2017-06-18 13:08:49 +00:00
|
|
|
};
|
|
|
|
|
2017-08-01 10:50:49 +00:00
|
|
|
auto createChangeStickerSet = [&](const MTPDchannelAdminLogEventActionChangeStickerSet &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto set = action.vnew_stickerset();
|
2017-08-19 16:46:17 +00:00
|
|
|
auto removed = (set.type() == mtpc_inputStickerSetEmpty);
|
|
|
|
if (removed) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_admin_log_removed_stickers_group(tr::now, lt_from, fromLinkText);
|
2017-08-19 16:46:17 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_admin_log_changed_stickers_group(
|
|
|
|
tr::now,
|
2017-08-19 16:46:17 +00:00
|
|
|
lt_from,
|
|
|
|
fromLinkText,
|
|
|
|
lt_sticker_set,
|
2019-06-19 15:09:03 +00:00
|
|
|
textcmdLink(2, tr::lng_admin_log_changed_stickers_set(tr::now)));
|
2017-12-18 09:07:18 +00:00
|
|
|
auto setLink = std::make_shared<LambdaClickHandler>([set] {
|
2019-06-24 15:09:37 +00:00
|
|
|
Ui::show(Box<StickerSetBox>(
|
|
|
|
App::wnd()->sessionController(),
|
|
|
|
set));
|
2017-08-19 16:46:17 +00:00
|
|
|
});
|
|
|
|
auto message = HistoryService::PreparedText { text };
|
|
|
|
message.links.push_back(fromLink);
|
|
|
|
message.links.push_back(setLink);
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeServiceMessage(
|
|
|
|
history,
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
date,
|
|
|
|
message,
|
|
|
|
MTPDmessage::Flags(0),
|
|
|
|
peerToUser(from->id)));
|
2017-08-19 16:46:17 +00:00
|
|
|
}
|
2017-08-01 10:50:49 +00:00
|
|
|
};
|
|
|
|
|
2017-11-20 19:54:05 +00:00
|
|
|
auto createTogglePreHistoryHidden = [&](const MTPDchannelAdminLogEventActionTogglePreHistoryHidden &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
auto hidden = (action.vnew_value().type() == mtpc_boolTrue);
|
2017-11-20 19:54:05 +00:00
|
|
|
auto text = (hidden
|
2019-06-19 16:39:25 +00:00
|
|
|
? tr::lng_admin_log_history_made_hidden
|
|
|
|
: tr::lng_admin_log_history_made_visible);
|
|
|
|
addSimpleServiceMessage(text(tr::now, lt_from, fromLinkText));
|
2017-11-20 19:54:05 +00:00
|
|
|
};
|
|
|
|
|
2019-01-08 13:54:48 +00:00
|
|
|
auto createDefaultBannedRights = [&](const MTPDchannelAdminLogEventActionDefaultBannedRights &action) {
|
|
|
|
auto bodyFlags = Flag::f_entities | Flag::f_from_id;
|
2019-09-06 07:53:44 +00:00
|
|
|
auto bodyClientFlags = MTPDmessage_ClientFlag::f_admin_log_entry;
|
2019-01-08 13:54:48 +00:00
|
|
|
auto bodyReplyTo = 0;
|
|
|
|
auto bodyViaBotId = 0;
|
2019-07-05 13:38:38 +00:00
|
|
|
auto bodyText = GenerateDefaultBannedRightsChangeText(channel, action.vnew_banned_rights(), action.vprev_banned_rights());
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeMessage(
|
|
|
|
history,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
bodyFlags,
|
|
|
|
bodyClientFlags,
|
|
|
|
bodyReplyTo,
|
|
|
|
bodyViaBotId,
|
|
|
|
date,
|
|
|
|
peerToUser(from->id),
|
|
|
|
QString(),
|
|
|
|
bodyText));
|
2019-01-08 13:54:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto createStopPoll = [&](const MTPDchannelAdminLogEventActionStopPoll &action) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = tr::lng_admin_log_stopped_poll(tr::now, lt_from, fromLinkText);
|
2019-01-08 13:54:48 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
|
|
|
|
auto detachExistingItem = false;
|
|
|
|
addPart(history->createItem(
|
2019-08-08 14:13:26 +00:00
|
|
|
PrepareLogMessage(action.vmessage(), history->nextNonHistoryEntryId(), date),
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2019-01-08 13:54:48 +00:00
|
|
|
detachExistingItem));
|
|
|
|
};
|
|
|
|
|
2019-05-24 12:05:52 +00:00
|
|
|
auto createChangeLinkedChat = [&](const MTPDchannelAdminLogEventActionChangeLinkedChat &action) {
|
|
|
|
const auto broadcast = channel->isBroadcast();
|
2019-07-05 13:38:38 +00:00
|
|
|
const auto was = history->owner().channelLoaded(action.vprev_value().v);
|
|
|
|
const auto now = history->owner().channelLoaded(action.vnew_value().v);
|
2019-05-24 12:05:52 +00:00
|
|
|
if (!now) {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = (broadcast
|
|
|
|
? tr::lng_admin_log_removed_linked_chat
|
|
|
|
: tr::lng_admin_log_removed_linked_channel)(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText);
|
2019-05-24 12:05:52 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
} else {
|
2019-06-19 16:39:25 +00:00
|
|
|
auto text = (broadcast
|
|
|
|
? tr::lng_admin_log_changed_linked_chat
|
|
|
|
: tr::lng_admin_log_changed_linked_channel)(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText,
|
|
|
|
lt_chat,
|
|
|
|
textcmdLink(2, now->name));
|
2019-05-24 12:05:52 +00:00
|
|
|
auto chatLink = std::make_shared<LambdaClickHandler>([=] {
|
|
|
|
Ui::showPeerHistory(now, ShowAtUnreadMsgId);
|
|
|
|
});
|
|
|
|
auto message = HistoryService::PreparedText{ text };
|
|
|
|
message.links.push_back(fromLink);
|
|
|
|
message.links.push_back(chatLink);
|
2019-08-09 19:19:23 +00:00
|
|
|
addPart(history->owner().makeServiceMessage(
|
|
|
|
history,
|
2019-09-06 07:53:44 +00:00
|
|
|
MTPDmessage_ClientFlag::f_admin_log_entry,
|
2019-08-08 14:13:26 +00:00
|
|
|
history->nextNonHistoryEntryId(),
|
2019-08-09 19:19:23 +00:00
|
|
|
date,
|
|
|
|
message,
|
|
|
|
MTPDmessage::Flags(0),
|
|
|
|
peerToUser(from->id)));
|
2019-05-24 12:05:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-06 15:42:15 +00:00
|
|
|
auto createChangeLocation = [&](const MTPDchannelAdminLogEventActionChangeLocation &action) {
|
2019-07-05 13:38:38 +00:00
|
|
|
action.vnew_value().match([&](const MTPDchannelLocation &data) {
|
|
|
|
const auto address = qs(data.vaddress());
|
|
|
|
const auto link = data.vgeo_point().match([&](const MTPDgeoPoint &data) {
|
2019-06-14 16:04:45 +00:00
|
|
|
return textcmdLink(
|
2019-06-21 12:27:46 +00:00
|
|
|
LocationClickHandler::Url(Data::LocationPoint(data)),
|
2019-06-14 16:04:45 +00:00
|
|
|
address);
|
|
|
|
}, [&](const MTPDgeoPointEmpty &) {
|
|
|
|
return address;
|
|
|
|
});
|
2019-06-19 16:39:25 +00:00
|
|
|
const auto text = tr::lng_admin_log_changed_location_chat(
|
|
|
|
tr::now,
|
2019-06-14 16:04:45 +00:00
|
|
|
lt_from,
|
|
|
|
fromLinkText,
|
|
|
|
lt_address,
|
|
|
|
link);
|
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
}, [&](const MTPDchannelLocationEmpty &) {
|
2019-06-19 16:39:25 +00:00
|
|
|
const auto text = tr::lng_admin_log_removed_location_chat(tr::now, lt_from, fromLinkText);
|
2019-06-14 16:04:45 +00:00
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
});
|
2019-06-06 15:42:15 +00:00
|
|
|
};
|
|
|
|
|
2019-07-15 13:57:49 +00:00
|
|
|
auto createToggleSlowMode = [&](const MTPDchannelAdminLogEventActionToggleSlowMode &action) {
|
|
|
|
if (const auto seconds = action.vnew_value().v) {
|
|
|
|
const auto duration = (seconds >= 60)
|
|
|
|
? tr::lng_admin_log_slow_mode_minutes(tr::now, lt_count, seconds / 60)
|
|
|
|
: tr::lng_admin_log_slow_mode_seconds(tr::now, lt_count, seconds);
|
|
|
|
const auto text = tr::lng_admin_log_changed_slow_mode(
|
|
|
|
tr::now,
|
|
|
|
lt_from,
|
|
|
|
fromLinkText,
|
|
|
|
lt_duration,
|
|
|
|
duration);
|
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
} else {
|
|
|
|
const auto text = tr::lng_admin_log_removed_slow_mode(tr::now, lt_from, fromLinkText);
|
|
|
|
addSimpleServiceMessage(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-08 13:54:48 +00:00
|
|
|
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 &) {
|
2017-11-20 19:54:05 +00:00
|
|
|
createParticipantJoin();
|
2019-01-08 13:54:48 +00:00
|
|
|
}, [&](const MTPDchannelAdminLogEventActionParticipantLeave &) {
|
2017-11-20 19:54:05 +00:00
|
|
|
createParticipantLeave();
|
2019-01-08 13:54:48 +00:00
|
|
|
}, [&](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);
|
2019-05-20 14:57:25 +00:00
|
|
|
}, [&](const MTPDchannelAdminLogEventActionChangeLinkedChat &data) {
|
2019-05-24 12:05:52 +00:00
|
|
|
createChangeLinkedChat(data);
|
2019-06-06 15:42:15 +00:00
|
|
|
}, [&](const MTPDchannelAdminLogEventActionChangeLocation &data) {
|
|
|
|
createChangeLocation(data);
|
2019-07-15 13:57:49 +00:00
|
|
|
}, [&](const MTPDchannelAdminLogEventActionToggleSlowMode &data) {
|
|
|
|
createToggleSlowMode(data);
|
2019-01-08 13:54:48 +00:00
|
|
|
});
|
2017-06-18 13:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace AdminLog
|