mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Track three-state muted value.
This commit is contained in:
parent
c8dd486410
commit
d18b29efb8
4 changed files with 59 additions and 18 deletions
|
@ -148,7 +148,7 @@ void GroupCall::rejoin() {
|
||||||
QJsonDocument::Compact);
|
QJsonDocument::Compact);
|
||||||
const auto muted = _muted.current();
|
const auto muted = _muted.current();
|
||||||
_api.request(MTPphone_JoinGroupCall(
|
_api.request(MTPphone_JoinGroupCall(
|
||||||
MTP_flags(muted
|
MTP_flags((muted != MuteState::Active)
|
||||||
? MTPphone_JoinGroupCall::Flag::f_muted
|
? MTPphone_JoinGroupCall::Flag::f_muted
|
||||||
: MTPphone_JoinGroupCall::Flag(0)),
|
: MTPphone_JoinGroupCall::Flag(0)),
|
||||||
inputCall(),
|
inputCall(),
|
||||||
|
@ -181,7 +181,9 @@ void GroupCall::applySelfInCallLocally() {
|
||||||
using Flag = MTPDgroupCallParticipant::Flag;
|
using Flag = MTPDgroupCallParticipant::Flag;
|
||||||
return MTP_groupCallParticipant(
|
return MTP_groupCallParticipant(
|
||||||
MTP_flags((_mySsrc ? Flag(0) : Flag::f_left)
|
MTP_flags((_mySsrc ? Flag(0) : Flag::f_left)
|
||||||
| (_muted.current() ? Flag::f_muted : Flag(0))),
|
| ((_muted.current() != MuteState::Active)
|
||||||
|
? Flag::f_muted
|
||||||
|
: Flag(0))),
|
||||||
MTP_int(self),
|
MTP_int(self),
|
||||||
MTP_int(now),
|
MTP_int(now),
|
||||||
MTP_int(0),
|
MTP_int(0),
|
||||||
|
@ -233,7 +235,7 @@ void GroupCall::finish(FinishType type) {
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupCall::setMuted(bool mute) {
|
void GroupCall::setMuted(MuteState mute) {
|
||||||
_muted = mute;
|
_muted = mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,6 +336,11 @@ void GroupCall::handleUpdate(const MTPDupdateGroupCallParticipants &data) {
|
||||||
_mySsrc = 0;
|
_mySsrc = 0;
|
||||||
hangup();
|
hangup();
|
||||||
}
|
}
|
||||||
|
if (data.is_muted() && !data.is_can_self_unmute()) {
|
||||||
|
setMuted(MuteState::ForceMuted);
|
||||||
|
} else if (muted() == MuteState::ForceMuted) {
|
||||||
|
setMuted(MuteState::Muted);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,11 +384,11 @@ void GroupCall::createAndStartController() {
|
||||||
std::move(descriptor));
|
std::move(descriptor));
|
||||||
|
|
||||||
_muted.value(
|
_muted.value(
|
||||||
) | rpl::start_with_next([=](bool muted) {
|
) | rpl::start_with_next([=](MuteState state) {
|
||||||
if (_instance) {
|
if (_instance) {
|
||||||
_instance->setIsMuted(muted);
|
_instance->setIsMuted(state != MuteState::Active);
|
||||||
}
|
}
|
||||||
if (_mySsrc) {
|
if (_mySsrc && state != MuteState::ForceMuted) {
|
||||||
sendMutedUpdate();
|
sendMutedUpdate();
|
||||||
}
|
}
|
||||||
}, _lifetime);
|
}, _lifetime);
|
||||||
|
@ -397,7 +404,7 @@ void GroupCall::myLevelUpdated(float level) {
|
||||||
void GroupCall::sendMutedUpdate() {
|
void GroupCall::sendMutedUpdate() {
|
||||||
_api.request(_updateMuteRequestId).cancel();
|
_api.request(_updateMuteRequestId).cancel();
|
||||||
_updateMuteRequestId = _api.request(MTPphone_EditGroupCallMember(
|
_updateMuteRequestId = _api.request(MTPphone_EditGroupCallMember(
|
||||||
MTP_flags(_muted.current()
|
MTP_flags((_muted.current() != MuteState::Active)
|
||||||
? MTPphone_EditGroupCallMember::Flag::f_muted
|
? MTPphone_EditGroupCallMember::Flag::f_muted
|
||||||
: MTPphone_EditGroupCallMember::Flag(0)),
|
: MTPphone_EditGroupCallMember::Flag(0)),
|
||||||
inputCall(),
|
inputCall(),
|
||||||
|
|
|
@ -19,6 +19,12 @@ class GroupInstanceImpl;
|
||||||
|
|
||||||
namespace Calls {
|
namespace Calls {
|
||||||
|
|
||||||
|
enum class MuteState {
|
||||||
|
Active,
|
||||||
|
Muted,
|
||||||
|
ForceMuted,
|
||||||
|
};
|
||||||
|
|
||||||
class GroupCall final : public base::has_weak_ptr {
|
class GroupCall final : public base::has_weak_ptr {
|
||||||
public:
|
public:
|
||||||
class Delegate {
|
class Delegate {
|
||||||
|
@ -49,11 +55,11 @@ public:
|
||||||
void handleUpdate(const MTPGroupCall &call);
|
void handleUpdate(const MTPGroupCall &call);
|
||||||
void handleUpdate(const MTPDupdateGroupCallParticipants &data);
|
void handleUpdate(const MTPDupdateGroupCallParticipants &data);
|
||||||
|
|
||||||
void setMuted(bool mute);
|
void setMuted(MuteState mute);
|
||||||
[[nodiscard]] bool muted() const {
|
[[nodiscard]] MuteState muted() const {
|
||||||
return _muted.current();
|
return _muted.current();
|
||||||
}
|
}
|
||||||
[[nodiscard]] rpl::producer<bool> mutedValue() const {
|
[[nodiscard]] rpl::producer<MuteState> mutedValue() const {
|
||||||
return _muted.value();
|
return _muted.value();
|
||||||
}
|
}
|
||||||
[[nodiscard]] bool joined() const {
|
[[nodiscard]] bool joined() const {
|
||||||
|
@ -113,7 +119,7 @@ private:
|
||||||
MTP::Sender _api;
|
MTP::Sender _api;
|
||||||
rpl::variable<State> _state = State::Creating;
|
rpl::variable<State> _state = State::Creating;
|
||||||
|
|
||||||
rpl::variable<bool> _muted = true;
|
rpl::variable<MuteState> _muted = MuteState::Muted;
|
||||||
bool _acceptFields = false;
|
bool _acceptFields = false;
|
||||||
|
|
||||||
uint64 _id = 0;
|
uint64 _id = 0;
|
||||||
|
|
|
@ -297,9 +297,20 @@ void GroupPanel::initWidget() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupPanel::initControls() {
|
void GroupPanel::initControls() {
|
||||||
|
_call->mutedValue(
|
||||||
|
) | rpl::start_with_next([=](MuteState state) {
|
||||||
|
if (state == MuteState::ForceMuted) {
|
||||||
|
_mute->clearState();
|
||||||
|
}
|
||||||
|
_mute->setAttribute(
|
||||||
|
Qt::WA_TransparentForMouseEvents,
|
||||||
|
(state == MuteState::ForceMuted));
|
||||||
|
}, _mute->lifetime());
|
||||||
_mute->setClickedCallback([=] {
|
_mute->setClickedCallback([=] {
|
||||||
if (_call) {
|
if (_call && _call->muted() != MuteState::ForceMuted) {
|
||||||
_call->setMuted(!_call->muted());
|
_call->setMuted((_call->muted() == MuteState::Active)
|
||||||
|
? MuteState::Muted
|
||||||
|
: MuteState::Active);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_hangup->setClickedCallback([=] {
|
_hangup->setClickedCallback([=] {
|
||||||
|
@ -326,9 +337,9 @@ void GroupPanel::initWithCall(GroupCall *call) {
|
||||||
_hangup->setText(tr::lng_box_leave());
|
_hangup->setText(tr::lng_box_leave());
|
||||||
|
|
||||||
_call->mutedValue(
|
_call->mutedValue(
|
||||||
) | rpl::start_with_next([=](bool mute) {
|
) | rpl::start_with_next([=](MuteState state) {
|
||||||
_mute->setProgress(mute ? 1. : 0.);
|
_mute->setProgress((state != MuteState::Active) ? 1. : 0.);
|
||||||
_mute->setText(mute
|
_mute->setText((state != MuteState::Active)
|
||||||
? tr::lng_call_unmute_audio()
|
? tr::lng_call_unmute_audio()
|
||||||
: tr::lng_call_mute_audio());
|
: tr::lng_call_mute_audio());
|
||||||
}, _callLifetime);
|
}, _callLifetime);
|
||||||
|
|
|
@ -115,13 +115,18 @@ void TopBar::initControls() {
|
||||||
if (const auto call = _call.get()) {
|
if (const auto call = _call.get()) {
|
||||||
call->setMuted(!call->muted());
|
call->setMuted(!call->muted());
|
||||||
} else if (const auto group = _groupCall.get()) {
|
} else if (const auto group = _groupCall.get()) {
|
||||||
group->setMuted(!group->muted());
|
if (group->muted() != MuteState::ForceMuted) {
|
||||||
|
group->setMuted((group->muted() == MuteState::Active)
|
||||||
|
? MuteState::Muted
|
||||||
|
: MuteState::Active);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
using namespace rpl::mappers;
|
||||||
auto muted = _call
|
auto muted = _call
|
||||||
? _call->mutedValue()
|
? _call->mutedValue()
|
||||||
: _groupCall->mutedValue();
|
: (_groupCall->mutedValue() | rpl::map(_1 != MuteState::Active));
|
||||||
std::move(
|
std::move(
|
||||||
muted
|
muted
|
||||||
) | rpl::start_with_next([=](bool muted) {
|
) | rpl::start_with_next([=](bool muted) {
|
||||||
|
@ -129,6 +134,18 @@ void TopBar::initControls() {
|
||||||
update();
|
update();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
if (_groupCall) {
|
||||||
|
_groupCall->mutedValue(
|
||||||
|
) | rpl::start_with_next([=](MuteState state) {
|
||||||
|
if (state == MuteState::ForceMuted) {
|
||||||
|
_mute->clearState();
|
||||||
|
}
|
||||||
|
_mute->setAttribute(
|
||||||
|
Qt::WA_TransparentForMouseEvents,
|
||||||
|
(state == MuteState::ForceMuted));
|
||||||
|
}, _mute->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
if (const auto call = _call.get()) {
|
if (const auto call = _call.get()) {
|
||||||
call->user()->session().changes().peerUpdates(
|
call->user()->session().changes().peerUpdates(
|
||||||
Data::PeerUpdate::Flag::Name
|
Data::PeerUpdate::Flag::Name
|
||||||
|
|
Loading…
Add table
Reference in a new issue