Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Oct 23, 2024
1 parent 5766473 commit ea7ad45
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 110 deletions.
51 changes: 32 additions & 19 deletions Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,25 +834,28 @@ void InnerWidget::preloadMore(Direction direction) {
// const auto minId = (direction == Direction::Up) ? 0 : _maxId;
const auto perPage = _items.empty() ? kEventsFirstPage : kEventsPerPage;

using LocalFlag = FilterValue::Flag;
const auto f = _filter.flags.value_or(LocalFlag());
auto filter = tl_chatEventLogFilters(
tl_bool(_filter.flags & FilterValue::Flag::Edit),
tl_bool(_filter.flags & FilterValue::Flag::Delete),
tl_bool(_filter.flags & FilterValue::Flag::Pinned),
tl_bool(_filter.flags & FilterValue::Flag::Join),
tl_bool(_filter.flags & FilterValue::Flag::Leave),
tl_bool(_filter.flags & FilterValue::Flag::Invites),
tl_bool(_filter.flags & FilterValue::Flag::Promote),
tl_bool(_filter.flags & FilterValue::Flag::Demote),
tl_bool(_filter.flags & FilterValue::Flag::Info),
tl_bool(_filter.flags & FilterValue::Flag::Settings),
tl_bool(_filter.flags & FilterValue::Flag::Invite),
tl_bool(_filter.flags & FilterValue::Flag::GroupCall),
tl_bool(_filter.flags & FilterValue::Flag::Topics));

auto admins = _filter.allUsers
tl_bool(f & LocalFlag::Edit),
tl_bool(f & LocalFlag::Delete),
tl_bool(f & LocalFlag::Pinned),
tl_bool(f & LocalFlag::Join),
tl_bool(f & LocalFlag::Leave),
tl_bool(f & LocalFlag::Invites),
tl_bool(f & LocalFlag::Promote),
tl_bool(f & LocalFlag::Demote),
tl_bool(f & LocalFlag::Info),
tl_bool(f & LocalFlag::Settings),
tl_bool(f & LocalFlag::Invite),
tl_bool(f & LocalFlag::GroupCall),
tl_bool(f & LocalFlag::Topics),
tl_bool(f & LocalFlag::SubExtend));

auto admins = !_filter.admins
? QVector<TLint53>()
: ranges::views::all(
_filter.admins
*_filter.admins
) | ranges::views::transform([](not_null<UserData*> user) {
return tl_int53(peerToUser(user->id).bare);
}) | ranges::to<QVector<TLint53>>();
Expand Down Expand Up @@ -1635,15 +1638,25 @@ void InnerWidget::suggestRestrictParticipant(
if (type == id_chatMemberStatusBanned) {
editRestrictions(
false,
ChatRestrictionsInfo(data.vstatus()));
ChatRestrictionsInfo(data.vstatus()),
user->owner().userLoaded(
UserId(data.vinviter_user_id())),
data.vjoined_chat_date().v);
} else {
const auto hasAdminRights =
(type == id_chatMemberStatusAdministrator)
|| (type == id_chatMemberStatusCreator);
editRestrictions(hasAdminRights, ChatRestrictionsInfo());
editRestrictions(
hasAdminRights,
ChatRestrictionsInfo(),
(hasAdminRights
? nullptr
: user->owner().userLoaded(
UserId(data.vinviter_user_id()))),
hasAdminRights ? 0 : data.vjoined_chat_date().v);
}
}).fail([=] {
editRestrictions(false, ChatRestrictionsInfo());
editRestrictions(false, {}, nullptr, 0);
}).send();
#if 0 // goodToRemove
_api.request(MTPchannels_GetParticipant(
Expand Down
25 changes: 13 additions & 12 deletions Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,7 @@ Tdb::TLmessage PrepareLogMessage(
Tdb::tl_bool(false), // is_outgoing
message.data().vis_pinned(),
Tdb::tl_bool(false), // is_from_offline
Tdb::tl_bool(false), // can_be_edited
Tdb::tl_bool(false), // can_be_forwarded
Tdb::tl_bool(false), // can_be_replied_in_another_chat
Tdb::tl_bool(false), // can_be_saved
Tdb::tl_bool(false), // can_be_deleted_only_for_self
Tdb::tl_bool(false), // can_be_deleted_for_all_users
Tdb::tl_bool(false), // can_get_added_reactions
Tdb::tl_bool(false), // can_get_statistics
Tdb::tl_bool(false), // can_get_message_thread
Tdb::tl_bool(false), // can_get_read_date
Tdb::tl_bool(false), // can_get_viewers
message.data().vcan_get_media_timestamp_links(),
Tdb::tl_bool(false), // can_report_reactions
message.data().vhas_timestamped_media(),
Tdb::tl_bool(false), // is_channel_post
Tdb::tl_bool(false), // is_topic_message
Expand All @@ -240,6 +228,7 @@ Tdb::TLmessage PrepareLogMessage(
message.data().vauthor_signature(),
Tdb::tl_int64(0), // media_album_id
Tdb::tl_int64(0), // effect_id
message.data().vhas_sensitive_content(),
Tdb::tl_string(), // restriction_reason
message.data().vcontent(),
message.data().vreply_markup()
Expand Down Expand Up @@ -1022,6 +1011,8 @@ void GenerateItems(
using LogChangeProfilePeerColor = TLDchatEventProfileAccentColorChanged;
using LogChangeWallpaper = TLDchatEventBackgroundChanged;
using LogChangeEmojiStatus = TLDchatEventEmojiStatusChanged;
using LogToggleSignatureProfiles = TLDchatEventShowMessageSenderToggled;
using LogParticipantSubExtend = TLDchatEventMemberSubscriptionExtended;

const auto session = &history->session();
const auto id = event.vid().v;
Expand Down Expand Up @@ -2618,7 +2609,10 @@ void GenerateItems(
};

const auto createToggleSignatureProfiles = [&](const LogToggleSignatureProfiles &action) {
const auto enabled = action.vshow_message_sender().v;
#if 0 // mtp
const auto enabled = (action.vnew_value().type() == mtpc_boolTrue);
#endif
const auto text = (enabled
? tr::lng_admin_log_signature_profiles_enabled
: tr::lng_admin_log_signature_profiles_disabled)(
Expand All @@ -2631,7 +2625,14 @@ void GenerateItems(

const auto createParticipantSubExtend = [&](const LogParticipantSubExtend &action) {
const auto participant = Api::ChatParticipant(
#if 0 // mtp
action.vnew_participant(),
#endif
tl_chatMember(
peerToSender(peerFromUser(action.vuser_id())),
tl_int53(0), // inviter_user_id
tl_int32(0), // joined_chat_date
action.vnew_status()),
channel);
if (!participant.subscriptionDate()) {
return;
Expand Down
177 changes: 152 additions & 25 deletions Telegram/SourceFiles/history/history_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4293,7 +4293,10 @@ void HistoryItem::createServiceFromTdb(const TLmessageContent &content) {
const auto payment = Get<HistoryServicePayment>();
const auto id = fullId();
const auto owner = &history()->owner();
payment->amount = Ui::FillAmountAndCurrency(amount, currency);
payment->amount = AmountAndStarCurrency(
&_history->session(),
amount,
currency);
payment->invoiceLink = std::make_shared<LambdaClickHandler>([=](
ClickContext context) {
using namespace Payments;
Expand Down Expand Up @@ -4989,16 +4992,82 @@ void HistoryItem::setServiceMessageByContent(
const auto peer = isSelf ? history()->peer : _from;
const auto amount = data.vamount().v;
const auto currency = data.vcurrency().v;
const auto session = &history()->session();
const auto cost = AmountAndStarCurrency(session, amount, currency);
prepared.links.push_back(peer->createOpenLink());
prepared.text = (isSelf
? tr::lng_action_gift_received_me
: tr::lng_action_gift_received)(
prepared.text = isSelf
? tr::lng_action_gift_sent(
tr::now,
lt_cost,
cost,
Ui::Text::WithEntities)
: tr::lng_action_gift_received(
tr::now,
lt_user,
Ui::Text::Link(peer->name(), 1), // Link 1.
Ui::Text::Link(peer->shortName(), 1), // Link 1.
lt_cost,
{ Ui::FillAmountAndCurrency(amount, currency) },
cost,
Ui::Text::WithEntities);
}, [&](const TLDmessageGiftedStars &data) {
const auto isSelf = (_from->id == _from->session().userPeerId());
const auto peer = isSelf ? history()->peer : _from;
const auto amount = data.vamount().v;
const auto currency = data.vcurrency().v;
const auto session = &history()->session();
const auto cost = AmountAndStarCurrency(session, amount, currency);
prepared.links.push_back(peer->createOpenLink());
prepared.text = isSelf
? tr::lng_action_gift_sent(
tr::now,
lt_cost,
cost,
Ui::Text::WithEntities)
: tr::lng_action_gift_received(
tr::now,
lt_user,
Ui::Text::Link(peer->shortName(), 1), // Link 1.
lt_cost,
cost,
Ui::Text::WithEntities);
}, [&](const TLDmessageGiveawayPrizeStars &action) {
prepared.text = {
(action.vis_unclaimed().v
? tr::lng_prize_unclaimed_about
: tr::lng_prize_about)(
tr::now,
lt_channel,
_from->owner().peer(
peerFromChat(action.vboosted_chat_id()))->name()),
};
}, [&](const TLDmessageGift &action) {
const auto isSelf = _from->isSelf();
const auto peer = isSelf ? _history->peer : _from;
const auto stars = action.vgift().data().vstar_count().v;
const auto cost = TextWithEntities{
tr::lng_action_gift_for_stars(tr::now, lt_count, stars),
};
const auto anonymous = _from->isServiceUser();
if (anonymous) {
prepared.text = tr::lng_action_gift_received_anonymous(
tr::now,
lt_cost,
cost,
Ui::Text::WithEntities);
} else {
prepared.links.push_back(peer->createOpenLink());
prepared.text = isSelf
? tr::lng_action_gift_sent(tr::now,
lt_cost,
cost,
Ui::Text::WithEntities)
: tr::lng_action_gift_received(
tr::now,
lt_user,
Ui::Text::Link(peer->shortName(), 1), // Link 1.
lt_cost,
cost,
Ui::Text::WithEntities);
}
}, [&](const TLDmessagePremiumGiftCode &action) {
if (const auto creator = action.vcreator_id()) {
prepared.text = {
Expand All @@ -5015,21 +5084,27 @@ void HistoryItem::setServiceMessageByContent(
} else {
const auto isSelf = (_from->id == _from->session().userPeerId());
const auto peer = isSelf ? _history->peer : _from;
const auto session = &history()->session();
const auto cost = AmountAndStarCurrency(
session,
action.vamount().v,
action.vcurrency().v);
prepared.links.push_back(peer->createOpenLink());
prepared.text = (isSelf
? tr::lng_action_gift_received_me
: tr::lng_action_gift_received)(
prepared.text = isSelf
? tr::lng_action_gift_sent(
tr::now,
lt_cost,
cost,
Ui::Text::WithEntities)
: tr::lng_action_gift_received(
tr::now,
lt_user,
Ui::Text::Link(peer->name(), 1), // Link 1.
Ui::Text::Link(peer->shortName(), 1), // Link 1.
lt_cost,
{ Ui::FillAmountAndCurrency(
action.vamount().v,
action.vcurrency().v) },
cost,
Ui::Text::WithEntities);

}
}, [&](const TLDmessagePremiumGiveawayCreated &data) {
}, [&](const TLDmessageGiveawayCreated &data) {
prepared.links.push_back(fromLink());
prepared.text = tr::lng_action_giveaway_started(
tr::now,
Expand Down Expand Up @@ -5195,10 +5270,57 @@ void HistoryItem::applyContent(const TLmessageContent &content) {
_media = std::make_unique<Data::MediaGiftBox>(
this,
_from,
data.vmonth_count().v,
Data::GiftCode{
.message = Api::FormattedTextFromTdb(data.vtext()),
.count = data.vmonth_count().v,
.type = Data::GiftType::Premium,
},
(data.vsticker()
? _history->owner().processDocument(*data.vsticker()).get()
: nullptr));
}, [&](const TLDmessageGiftedStars &data) {
_media = std::make_unique<Data::MediaGiftBox>(
this,
_from,
Data::GiftType::Credits,
data.vstar_count().v,
(data.vsticker()
? _history->owner().processDocument(*data.vsticker()).get()
: nullptr));
}, [&](const TLDmessageGiveawayPrizeStars &data) {
_media = std::make_unique<Data::MediaGiftBox>(
this,
_from,
Data::GiftCode{
.slug = data.vtransaction_id().v,
.channel = history()->owner().channel(
peerToChannel(peerFromTdbChat(data.vboosted_chat_id()))),
.giveawayMsgId = data.vgiveaway_message_id().v,
.count = int(data.vstar_count().v),
.type = Data::GiftType::Credits,
.viaGiveaway = true,
.unclaimed = data.vis_unclaimed().v,
},
(data.vsticker()
? _history->owner().processDocument(*data.vsticker()).get()
: nullptr));
}, [&](const TLDmessageGift &data) {
const auto &gift = data.vgift().data();
const auto document = history()->owner().processDocument(
gift.vsticker());
using Fields = Data::GiftCode;
_media = std::make_unique<Data::MediaGiftBox>(this, _from, Fields{
.document = document->sticker() ? document.get() : nullptr,
.message = Api::FormattedTextFromTdb(data.vtext()),
.convertStars = int(data.vsell_star_count().v),
.limitedCount = gift.vtotal_count().v,
.limitedLeft = gift.vremaining_count().v,
.count = int(gift.vstar_count().v),
.type = Data::GiftType::StarGift,
.anonymous = data.vis_private().v,
.converted = data.vwas_converted().v,
.saved = data.vis_saved().v,
}, _history->owner().processDocument(gift.vsticker()));
}, [&](const TLDmessagePremiumGiftCode &data) {
const auto boostedId = data.vcreator_id()
? peerToChannel(peerFromSender(*data.vcreator_id()))
Expand All @@ -5208,10 +5330,12 @@ void HistoryItem::applyContent(const TLmessageContent &content) {
_from,
Data::GiftCode{
.slug = data.vcode().v,
.message = Api::FormattedTextFromTdb(data.vtext()),
.channel = (boostedId
? _history->owner().channel(boostedId).get()
: nullptr),
.months = data.vmonth_count().v,
.count = data.vmonth_count().v,
.type = Data::GiftType::Premium,
.viaGiveaway = data.vis_from_giveaway().v,
.unclaimed = data.vis_unclaimed().v,
},
Expand Down Expand Up @@ -5311,8 +5435,8 @@ void HistoryItem::setContent(const TLmessageContent &content) {
|| TLDmessageDice::Is<T>()
|| TLDmessagePoll::Is<T>()
|| TLDmessageCall::Is<T>()
|| TLDmessagePremiumGiveaway::Is<T>()
|| TLDmessagePremiumGiveawayWinners::Is<T>()) {
|| TLDmessageGiveaway::Is<T>()
|| TLDmessageGiveawayWinners::Is<T>()) {
setMedia(content);
} else if constexpr (TLDmessageInvoice::Is<T>()) {
setMedia(content);
Expand Down Expand Up @@ -5355,8 +5479,11 @@ void HistoryItem::setContent(const TLmessageContent &content) {
|| TLDmessageProximityAlertTriggered::Is<T>()
|| TLDmessageChatJoinByRequest::Is<T>()
|| TLDmessageGiftedPremium::Is<T>()
|| TLDmessagePremiumGiveawayCreated::Is<T>()
|| TLDmessagePremiumGiveawayCompleted::Is<T>()
|| TLDmessageGiftedStars::Is<T>()
|| TLDmessageGiveawayPrizeStars::Is<T>()
|| TLDmessageGift::Is<T>()
|| TLDmessageGiveawayCreated::Is<T>()
|| TLDmessageGiveawayCompleted::Is<T>()
|| TLDmessagePremiumGiftCode::Is<T>()
|| TLDmessageForumTopicCreated::Is<T>()
|| TLDmessageForumTopicEdited::Is<T>()
Expand Down Expand Up @@ -5553,18 +5680,18 @@ std::unique_ptr<Data::Media> HistoryItem::CreateMedia(
peerFromTdbChat(data.vstory_sender_chat_id()),
data.vstory_id().v,
}, data.vvia_mention().v);
}, [&](const TLDmessagePremiumGiveawayCreated &data) -> Result {
}, [&](const TLDmessageGiveawayCreated &data) -> Result {
return Result();
}, [&](const TLDmessagePremiumGiveaway &data) -> Result {
}, [&](const TLDmessageGiveaway &data) -> Result {
return std::make_unique<Data::MediaGiveawayStart>(
item,
Data::ComputeGiveawayStartData(item, data),
(data.vsticker()
? owner.processDocument(*data.vsticker()).get()
: nullptr));
}, [&](const TLDmessagePremiumGiveawayCompleted &data) -> Result {
}, [&](const TLDmessageGiveawayCompleted &data) -> Result {
return Result();
}, [&](const TLDmessagePremiumGiveawayWinners &data) -> Result {
}, [&](const TLDmessageGiveawayWinners &data) -> Result {
return std::make_unique<Data::MediaGiveawayResults>(
item,
Data::ComputeGiveawayResultsData(item, data));
Expand Down
Loading

0 comments on commit ea7ad45

Please sign in to comment.