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) {
// No valid string here :( auto result = [&] {
return tr::lng_admin_log_transferred( const auto &peerId = participant.id();
tr::now, switch (participant.type()) {
lt_user, case Api::ChatParticipant::Type::Creator: {
GenerateParticipantString( // No valid string here :(
return tr::lng_admin_log_transferred(
tr::now,
lt_user,
GenerateParticipantString(&channel->session(), peerId),
Ui::Text::WithEntities);
}
case Api::ChatParticipant::Type::Admin: {
const auto user = GenerateParticipantString(
&channel->session(), &channel->session(),
peerFromUser(data.vuser_id())), peerId);
Ui::Text::WithEntities); return GenerateAdminChangeText(
}, [&](const MTPDchannelParticipantAdmin &data) { channel,
const auto user = GenerateParticipantString( user,
&channel->session(), participant.rights(),
peerFromUser(data.vuser_id())); oldRights);
return GenerateAdminChangeText( }
channel, case Api::ChatParticipant::Type::Restricted:
user, case Api::ChatParticipant::Type::Banned: {
ChatAdminRightsInfo(data.vadmin_rights()), const auto user = GenerateParticipantString(
(oldType == mtpc_channelParticipantAdmin &channel->session(),
? ChatAdminRightsInfo( peerId);
oldParticipant return GenerateBannedChangeText(
->c_channelParticipantAdmin() peerId,
.vadmin_rights()) user,
: ChatAdminRightsInfo())); participant.restrictions(),
}, [&](const MTPDchannelParticipantBanned &data) { oldRestrictions);
const auto participantId = peerFromMTP(data.vpeer()); }
const auto user = GenerateParticipantString( case Api::ChatParticipant::Type::Left:
&channel->session(), case Api::ChatParticipant::Type::Member:
participantId); return generateOther(peerId);
return GenerateBannedChangeText( };
participantId, }();
user,
ChatRestrictionsInfo(data.vbanned_rights()), result.entities.push_front(
(oldType == mtpc_channelParticipantBanned EntityInText(EntityType::Italic, 0, result.text.size()));
? ChatRestrictionsInfo( return result;
oldParticipant
->c_channelParticipantBanned()
.vbanned_rights())
: ChatRestrictionsInfo()));
}, [&](const MTPDchannelParticipantLeft &data) {
return generateOther(peerFromMTP(data.vpeer()));
}, [&](const auto &data) {
return generateOther(peerFromUser(data.vuser_id()));
});
} }
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) {