From deffbcf2313f1bc37b8a2c5f012fc2e1b9a86b65 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 4 Nov 2025 16:40:53 +0400 Subject: [PATCH] Skip showing cheap messages. --- .../calls/group/calls_group_call.cpp | 2 + .../calls/group/calls_group_call.h | 2 +- .../calls/group/calls_group_messages.cpp | 123 ++++++++++++------ .../calls/group/calls_group_messages.h | 6 + .../media/stories/media_stories_header.cpp | 18 ++- 5 files changed, 100 insertions(+), 51 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 3daa89c915..7f9cbdaf51 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -1800,7 +1800,9 @@ void GroupCall::joinDone( _api.request(base::take(state.requestId)).cancel(); state.inShortPoll = true; } + _messages->setApplyingInitial(true); _peer->session().api().applyUpdates(result); + _messages->setApplyingInitial(false); for (auto &state : _subchains) { state.inShortPoll = false; } diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index f5752c4a1f..c2820cd8b7 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -694,7 +694,7 @@ private: base::flat_set _unresolvedSsrcs; rpl::event_stream _errors; std::vector> _rejoinedCallbacks; - std::unique_ptr _messages; + const std::unique_ptr _messages; bool _recordingStoppedByMe = false; bool _requestedVideoChannelsUpdateScheduled = false; diff --git a/Telegram/SourceFiles/calls/group/calls_group_messages.cpp b/Telegram/SourceFiles/calls/group/calls_group_messages.cpp index 5125c4a10b..e0a7727ee6 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_messages.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_messages.cpp @@ -164,24 +164,29 @@ void Messages::send(TextWithTags text, int stars) { _sendingIdByRandomId.emplace(randomId, localId); const auto from = _call->messagesFrom(); - _messages.push_back({ - .id = localId, - .peer = from, - .text = std::move(prepared), - .stars = stars, - .admin = (from == _call->peer()), - .mine = true, - }); - + const auto skip = skipMessage(prepared, stars); + if (skip) { + _skippedIds.emplace(localId); + } else { + _messages.push_back({ + .id = localId, + .peer = from, + .text = std::move(prepared), + .stars = stars, + .admin = (from == _call->peer()), + .mine = true, + }); + } if (!_call->conference()) { using Flag = MTPphone_SendGroupCallMessage::Flag; _api->request(MTPphone_SendGroupCallMessage( - MTP_flags(stars ? Flag::f_allow_paid_stars : Flag()), + MTP_flags(Flag::f_send_as + | (stars ? Flag::f_allow_paid_stars : Flag())), _call->inputCall(), MTP_long(randomId), serialized, MTP_long(stars), - MTPInputPeer() // send_as + from->input )).done([=]( const MTPUpdates &result, const MTP::Response &response) { @@ -209,7 +214,13 @@ void Messages::send(TextWithTags text, int stars) { } addStars(from, stars, true); - checkDestroying(true); + if (!skip) { + checkDestroying(true); + } +} + +void Messages::setApplyingInitial(bool value) { + _applyingInitial = value; } void Messages::received(const MTPDupdateGroupCallMessage &data) { @@ -300,6 +311,7 @@ void Messages::sent(uint64 randomId, MsgId realId) { const auto j = ranges::find(_messages, localId, &Message::id); if (j == end(_messages)) { + _skippedIds.emplace(realId); return; } j->id = realId; @@ -333,6 +345,8 @@ void Messages::received( checkDestroying(true); } return; + } else if (_skippedIds.contains(id)) { + return; } auto allowedEntityTypes = std::vector{ EntityType::Code, @@ -349,26 +363,42 @@ void Messages::received( } const auto author = peer->owner().peer(peerFromMTP(from)); - // Should check by sendAsPeers() list instead, but it may not be - // loaded here yet. + auto text = Ui::Text::Filtered( + Api::ParseTextWithEntities(&author->session(), message), + allowedEntityTypes); const auto mine = author->isSelf() || (author->isChannel() && author->asChannel()->amCreator()); - _messages.push_back({ - .id = id, - .date = date, - .pinFinishDate = PinFinishDate(author, date, stars), - .peer = author, - .text = Ui::Text::Filtered( - Api::ParseTextWithEntities(&author->session(), message), - allowedEntityTypes), - .stars = stars, - .admin = (author == _call->peer()), - .mine = mine, - }); - ranges::sort(_messages, ranges::less(), &Message::id); + const auto skip = skipMessage(text, stars); + if (skip) { + _skippedIds.emplace(id); + } else { + // Should check by sendAsPeers() list instead, but it may not be + // loaded here yet. + _messages.push_back({ + .id = id, + .date = date, + .pinFinishDate = PinFinishDate(author, date, stars), + .peer = author, + .text = std::move(text), + .stars = stars, + .admin = (author == _call->peer()), + .mine = mine, + }); + ranges::sort(_messages, ranges::less(), &Message::id); + } + if (!_applyingInitial) { + addStars(author, stars, mine); + } + if (!skip) { + checkDestroying(true); + } +} - addStars(author, stars, mine); - checkDestroying(true); +bool Messages::skipMessage(const TextWithEntities &text, int stars) const { + const auto real = _call->lookupReal(); + return text.empty() + && real + && (stars < real->messagesMinPrice()); } void Messages::checkDestroying(bool afterChanges) { @@ -598,23 +628,28 @@ void Messages::reactionsPaidSend() { const auto randomId = base::RandomValue(); _sendingIdByRandomId.emplace(randomId, localId); - const auto from = _call->messagesFrom(); // send.shownPeer? - _messages.push_back({ - .id = localId, - .peer = from, - .stars = int(send.count), - .admin = (from == _call->peer()), - .mine = true, - }); - + const auto from = _call->messagesFrom(); + const auto stars = int(send.count); + const auto skip = skipMessage({}, stars); + if (skip) { + _skippedIds.emplace(localId); + } else { + _messages.push_back({ + .id = localId, + .peer = from, + .stars = stars, + .admin = (from == _call->peer()), + .mine = true, + }); + } using Flag = MTPphone_SendGroupCallMessage::Flag; _api->request(MTPphone_SendGroupCallMessage( - MTP_flags(Flag::f_allow_paid_stars), + MTP_flags(Flag::f_send_as | Flag::f_allow_paid_stars), _call->inputCall(), MTP_long(randomId), MTP_textWithEntities(MTP_string(), MTP_vector()), - MTP_long(send.count), - MTPInputPeer() // send_as + MTP_long(stars), + from->input )).done([=]( const MTPUpdates &result, const MTP::Response &response) { @@ -625,8 +660,10 @@ void Messages::reactionsPaidSend() { failed(randomId, response); }).send(); - addStars(from, int(send.count), true); - checkDestroying(true); + addStars(from, stars, true); + if (!skip) { + checkDestroying(true); + } } void Messages::undoScheduledPaidOnDestroy() { diff --git a/Telegram/SourceFiles/calls/group/calls_group_messages.h b/Telegram/SourceFiles/calls/group/calls_group_messages.h index 91a3269615..3d0d2bf6ed 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_messages.h +++ b/Telegram/SourceFiles/calls/group/calls_group_messages.h @@ -80,6 +80,7 @@ public: void send(TextWithTags text, int stars); + void setApplyingInitial(bool value); void received(const MTPDupdateGroupCallMessage &data); void received(const MTPDupdateGroupCallEncryptedMessage &data); void deleted(const MTPDupdateDeleteGroupCallMessages &data); @@ -149,6 +150,9 @@ private: void sent(uint64 randomId, MsgId realId); void failed(uint64 randomId, const MTP::Response &response); + [[nodiscard]] bool skipMessage( + const TextWithEntities &text, + int stars) const; [[nodiscard]] Data::PaidReactionSend startPaidReactionSending(); void finishPaidSending(Data::PaidReactionSend send, bool success); void addStars(not_null from, int stars, bool mine); @@ -169,8 +173,10 @@ private: base::Timer _destroyTimer; std::vector _messages; + base::flat_set _skippedIds; rpl::event_stream> _changes; rpl::event_stream _idUpdates; + bool _applyingInitial = false; mtpRequestId _starsTopRequestId = 0; Paid _paid; diff --git a/Telegram/SourceFiles/media/stories/media_stories_header.cpp b/Telegram/SourceFiles/media/stories/media_stories_header.cpp index 11fbba2ef2..14365a266a 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_header.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_header.cpp @@ -553,13 +553,17 @@ void Header::setVideoStreamViewers(rpl::producer viewers) { st::groupCallMessageBadge, st::groupCallMessageBadgeMargin)); const auto context = helper.context(); - _videoStreamViewersLifetime = tr::lng_group_call_rtmp_viewers( - lt_count_decimal, - std::move(viewers) | tr::to_count() - ) | rpl::start_with_next([=](QString text) { - _date->setMarkedText( - TextWithEntities(badge).append(' ').append(text), - context); + _videoStreamViewersLifetime = std::move( + viewers + ) | rpl::start_with_next([=](int count) { + auto text = badge; + if (count) { + text.append(' ').append(tr::lng_group_call_rtmp_viewers( + tr::now, + lt_count_decimal, + count)); + } + _date->setMarkedText(text, context); }); }