From e12689c8c1fcefc345883c167d45c0a4fafef5c0 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 15 Jan 2021 19:05:34 +0300 Subject: [PATCH] Added handler of state changes of other participants in group calls. --- .../SourceFiles/calls/calls_group_call.cpp | 20 +++++++++++++++++++ Telegram/SourceFiles/calls/calls_group_call.h | 6 ++++++ .../SourceFiles/calls/calls_group_common.h | 7 +++++++ 3 files changed, 33 insertions(+) diff --git a/Telegram/SourceFiles/calls/calls_group_call.cpp b/Telegram/SourceFiles/calls/calls_group_call.cpp index f9693a7515..8aa4e4e3df 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -589,10 +589,25 @@ void GroupCall::handleUpdate(const MTPDupdateGroupCallParticipants &data) { return; } + const auto handleOtherParticipants = [=]( + const MTPDgroupCallParticipant &data) { + const auto user = _peer->owner().user(data.vuser_id().v); + const auto participant = LookupParticipant(_peer, _id, user); + if (!participant) { + return; + } + _otherParticipantStateValue.fire(Group::ParticipantState{ + .user = user, + .mutedByMe = data.is_muted_by_you(), + .volume = data.vvolume().value_or_empty(), + }); + }; + const auto self = _peer->session().userId(); for (const auto &participant : data.vparticipants().v) { participant.match([&](const MTPDgroupCallParticipant &data) { if (data.vuser_id().v != self) { + handleOtherParticipants(data); return; } if (data.is_left() && data.vsource().v == _mySsrc) { @@ -1030,6 +1045,11 @@ void GroupCall::pushToTalkCancel() { } } +auto GroupCall::otherParticipantStateValue() const +-> rpl::producer { + return _otherParticipantStateValue.events(); +} + //void GroupCall::setAudioVolume(bool input, float level) { // if (_instance) { // if (input) { diff --git a/Telegram/SourceFiles/calls/calls_group_call.h b/Telegram/SourceFiles/calls/calls_group_call.h index 3e5d8202ab..c038fd6c27 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.h +++ b/Telegram/SourceFiles/calls/calls_group_call.h @@ -38,6 +38,7 @@ namespace Calls { namespace Group { struct MuteRequest; struct VolumeRequest; +struct ParticipantState; } // namespace Group enum class MuteState { @@ -109,6 +110,9 @@ public: return _muted.value(); } + [[nodiscard]] auto otherParticipantStateValue() const + -> rpl::producer; + enum State { Creating, Joining, @@ -206,6 +210,8 @@ private: rpl::variable _muted = MuteState::Muted; bool _acceptFields = false; + rpl::event_stream _otherParticipantStateValue; + uint64 _id = 0; uint64 _accessHash = 0; uint32 _mySsrc = 0; diff --git a/Telegram/SourceFiles/calls/calls_group_common.h b/Telegram/SourceFiles/calls/calls_group_common.h index 1dbe7f08d6..22ac7d8560 100644 --- a/Telegram/SourceFiles/calls/calls_group_common.h +++ b/Telegram/SourceFiles/calls/calls_group_common.h @@ -26,4 +26,11 @@ struct VolumeRequest { bool locallyOnly = false; }; +struct ParticipantState { + not_null user; + std::optional volume; + bool mutedByMe = false; + bool locallyOnly = false; +}; + } // namespace Calls::Group