Apply self mute status locally.

This commit is contained in:
John Preston 2020-11-28 10:41:33 +03:00
parent 7983d33ad5
commit b54a2aa40b
3 changed files with 32 additions and 21 deletions

View file

@ -175,24 +175,36 @@ void GroupCall::applySelfInCallLocally() {
if (!call || call->id() != _id) { if (!call || call->id() != _id) {
return; return;
} }
const auto my = [&] {
const auto self = _channel->session().userId();
const auto now = base::unixtime::now();
using Flag = MTPDgroupCallParticipant::Flag; using Flag = MTPDgroupCallParticipant::Flag;
return MTP_groupCallParticipant( const auto &participants = call->participants();
MTP_flags((_mySsrc ? Flag(0) : Flag::f_left) const auto self = _channel->session().user();
| ((_muted.current() != MuteState::Active) const auto i = ranges::find(
? Flag::f_muted participants,
: Flag(0))), self,
MTP_int(self), &Data::GroupCall::Participant::user);
MTP_int(now), const auto date = (i != end(participants))
MTP_int(0), ? i->date
MTP_int(_mySsrc)); : base::unixtime::now();
}; const auto lastActive = (i != end(participants))
? i->lastActive
: TimeId(0);
const auto muted = (_muted.current() != MuteState::Active);
const auto cantSelfUnmute = (_muted.current() == MuteState::ForceMuted);
const auto flags = (cantSelfUnmute ? Flag(0) : Flag::f_can_self_unmute)
| (lastActive ? Flag::f_active_date : Flag(0))
| (_mySsrc ? Flag(0) : Flag::f_left)
| (muted ? Flag::f_muted : Flag(0));
call->applyUpdateChecked( call->applyUpdateChecked(
MTP_updateGroupCallParticipants( MTP_updateGroupCallParticipants(
inputCall(), inputCall(),
MTP_vector<MTPGroupCallParticipant>(1, my()), MTP_vector<MTPGroupCallParticipant>(
1,
MTP_groupCallParticipant(
MTP_flags(flags),
MTP_int(self->bareId()),
MTP_int(date),
MTP_int(lastActive),
MTP_int(_mySsrc))),
MTP_int(0)).c_updateGroupCallParticipants()); MTP_int(0)).c_updateGroupCallParticipants());
} }
@ -237,6 +249,7 @@ void GroupCall::finish(FinishType type) {
void GroupCall::setMuted(MuteState mute) { void GroupCall::setMuted(MuteState mute) {
_muted = mute; _muted = mute;
applySelfInCallLocally();
} }
void GroupCall::handleUpdate(const MTPGroupCall &call) { void GroupCall::handleUpdate(const MTPGroupCall &call) {
@ -396,9 +409,7 @@ void GroupCall::createAndStartController() {
} }
void GroupCall::myLevelUpdated(float level) { void GroupCall::myLevelUpdated(float level) {
if (level > 0.) { LOG(("Level: %1").arg(level));
}
} }
void GroupCall::sendMutedUpdate() { void GroupCall::sendMutedUpdate() {

View file

@ -198,7 +198,7 @@ void GroupCall::applyParticipantsSlice(
.date = data.vdate().v, .date = data.vdate().v,
.source = uint32(data.vsource().v), .source = uint32(data.vsource().v),
.muted = data.is_muted(), .muted = data.is_muted(),
.canSelfUnmute = data.is_can_self_unmute(), .canSelfUnmute = !data.is_muted() || data.is_can_self_unmute(),
}; };
if (i == end(_participants)) { if (i == end(_participants)) {
_participants.push_back(value); _participants.push_back(value);
@ -236,7 +236,7 @@ void GroupCall::applyParticipantsMutes(
&Participant::user); &Participant::user);
if (i != end(_participants)) { if (i != end(_participants)) {
i->muted = data.is_muted(); i->muted = data.is_muted();
i->canSelfUnmute = data.is_can_self_unmute(); i->canSelfUnmute = !i->muted || data.is_can_self_unmute();
_participantUpdates.fire({ _participantUpdates.fire({
.participant = *i, .participant = *i,
}); });

@ -1 +1 @@
Subproject commit ac86c0ee86293d6fced7dcb48a8c93657f18a7f3 Subproject commit 10d63157e4ebdf71d1ea3694bef2ab1f7d7f033c