Replaced parsing of MTPChannelParticipant in AdminLog::GenerateItems.

This commit is contained in:
23rd 2021-11-24 07:25:05 +03:00 committed by John Preston
parent f255573070
commit e2fbcd4b0e

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_service.h" #include "history/history_service.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "history/history.h" #include "history/history.h"
#include "api/api_chat_participants.h"
#include "api/api_text_entities.h" #include "api/api_text_entities.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_user.h" #include "data/data_user.h"
@ -454,33 +455,34 @@ auto GenerateParticipantString(
Ui::Text::WithEntities); Ui::Text::WithEntities);
} }
auto GenerateParticipantChangeTextInner( auto GenerateParticipantChangeText(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
const MTPChannelParticipant &participant, const Api::ChatParticipant &participant,
const MTPChannelParticipant *oldParticipant) { std::optional<Api::ChatParticipant> oldParticipant = std::nullopt) {
const auto oldType = oldParticipant ? oldParticipant->type() : 0; using Type = Api::ChatParticipant::Type;
const auto oldRights = oldParticipant
? oldParticipant->rights()
: ChatAdminRightsInfo();
const auto oldRestrictions = oldParticipant
? oldParticipant->restrictions()
: ChatRestrictionsInfo();
const auto generateOther = [&](PeerId participantId) { const auto generateOther = [&](PeerId participantId) {
auto user = GenerateParticipantString( auto user = GenerateParticipantString(
&channel->session(), &channel->session(),
participantId); participantId);
if (oldType == mtpc_channelParticipantAdmin) { if (oldParticipant && oldParticipant->type() == Type::Admin) {
return GenerateAdminChangeText( return GenerateAdminChangeText(
channel, channel,
user, user,
ChatAdminRightsInfo(), ChatAdminRightsInfo(),
ChatAdminRightsInfo( oldRights);
oldParticipant } else if (oldParticipant && oldParticipant->type() == Type::Banned) {
->c_channelParticipantAdmin()
.vadmin_rights()));
} else if (oldType == mtpc_channelParticipantBanned) {
return GenerateBannedChangeText( return GenerateBannedChangeText(
participantId, participantId,
user, user,
ChatRestrictionsInfo(), ChatRestrictionsInfo(),
ChatRestrictionsInfo( oldRestrictions);
oldParticipant
->c_channelParticipantBanned()
.vbanned_rights()));
} }
return tr::lng_admin_log_invited( return tr::lng_admin_log_invited(
tr::now, tr::now,
@ -488,62 +490,62 @@ auto GenerateParticipantChangeTextInner(
user, user,
Ui::Text::WithEntities); Ui::Text::WithEntities);
}; };
return participant.match([&](const MTPDchannelParticipantCreator &data) {
auto result = [&] {
const auto &peerId = participant.id();
switch (participant.type()) {
case Api::ChatParticipant::Type::Creator: {
// No valid string here :( // No valid string here :(
return tr::lng_admin_log_transferred( return tr::lng_admin_log_transferred(
tr::now, tr::now,
lt_user, lt_user,
GenerateParticipantString( GenerateParticipantString(&channel->session(), peerId),
&channel->session(),
peerFromUser(data.vuser_id())),
Ui::Text::WithEntities); Ui::Text::WithEntities);
}, [&](const MTPDchannelParticipantAdmin &data) { }
case Api::ChatParticipant::Type::Admin: {
const auto user = GenerateParticipantString( const auto user = GenerateParticipantString(
&channel->session(), &channel->session(),
peerFromUser(data.vuser_id())); peerId);
return GenerateAdminChangeText( return GenerateAdminChangeText(
channel, channel,
user, user,
ChatAdminRightsInfo(data.vadmin_rights()), participant.rights(),
(oldType == mtpc_channelParticipantAdmin oldRights);
? ChatAdminRightsInfo( }
oldParticipant case Api::ChatParticipant::Type::Restricted:
->c_channelParticipantAdmin() case Api::ChatParticipant::Type::Banned: {
.vadmin_rights())
: ChatAdminRightsInfo()));
}, [&](const MTPDchannelParticipantBanned &data) {
const auto participantId = peerFromMTP(data.vpeer());
const auto user = GenerateParticipantString( const auto user = GenerateParticipantString(
&channel->session(), &channel->session(),
participantId); peerId);
return GenerateBannedChangeText( return GenerateBannedChangeText(
participantId, peerId,
user, user,
ChatRestrictionsInfo(data.vbanned_rights()), participant.restrictions(),
(oldType == mtpc_channelParticipantBanned oldRestrictions);
? ChatRestrictionsInfo( }
oldParticipant case Api::ChatParticipant::Type::Left:
->c_channelParticipantBanned() case Api::ChatParticipant::Type::Member:
.vbanned_rights()) return generateOther(peerId);
: ChatRestrictionsInfo())); };
}, [&](const MTPDchannelParticipantLeft &data) { }();
return generateOther(peerFromMTP(data.vpeer()));
}, [&](const auto &data) { result.entities.push_front(
return generateOther(peerFromUser(data.vuser_id())); EntityInText(EntityType::Italic, 0, result.text.size()));
}); return result;
} }
TextWithEntities GenerateParticipantChangeText( TextWithEntities GenerateParticipantChangeText(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
const MTPChannelParticipant &participant, const MTPChannelParticipant &participant,
const MTPChannelParticipant *oldParticipant = nullptr) { std::optional<MTPChannelParticipant>oldParticipant = std::nullopt) {
auto result = GenerateParticipantChangeTextInner( return GenerateParticipantChangeText(
channel, channel,
participant, Api::ChatParticipant(participant, channel),
oldParticipant); oldParticipant
result.entities.push_front( ? std::make_optional(Api::ChatParticipant(
EntityInText(EntityType::Italic, 0, result.text.size())); *oldParticipant,
return result; channel))
: std::nullopt);
} }
TextWithEntities GenerateDefaultBannedRightsChangeText( TextWithEntities GenerateDefaultBannedRightsChangeText(
@ -918,7 +920,7 @@ void GenerateItems(
GenerateParticipantChangeText( GenerateParticipantChangeText(
channel, channel,
action.vnew_participant(), action.vnew_participant(),
&action.vprev_participant())); action.vprev_participant()));
}; };
const auto createParticipantToggleAdmin = [&](const LogPromote &action) { const auto createParticipantToggleAdmin = [&](const LogPromote &action) {
@ -933,7 +935,7 @@ void GenerateItems(
GenerateParticipantChangeText( GenerateParticipantChangeText(
channel, channel,
action.vnew_participant(), action.vnew_participant(),
&action.vprev_participant())); action.vprev_participant()));
}; };
const auto createChangeStickerSet = [&](const LogSticker &action) { const auto createChangeStickerSet = [&](const LogSticker &action) {