Allow to toggle group call members mute.

This commit is contained in:
John Preston 2020-11-27 18:51:24 +03:00
parent a6b4cdd62d
commit b8f23bda59
7 changed files with 76 additions and 11 deletions

View File

@ -1150,7 +1150,7 @@ void PeerListContent::mousePressEvent(QMouseEvent *e) {
updateRow(row, hint); updateRow(row, hint);
}; };
if (_selected.action) { if (_selected.action) {
auto actionRect = getActionRect(row, _selected.index); auto actionRect = getActiveActionRect(row, _selected.index);
if (!actionRect.isEmpty()) { if (!actionRect.isEmpty()) {
auto point = mapFromGlobal(QCursor::pos()) - actionRect.topLeft(); auto point = mapFromGlobal(QCursor::pos()) - actionRect.topLeft();
row->addActionRipple(point, std::move(updateCallback)); row->addActionRipple(point, std::move(updateCallback));
@ -1627,7 +1627,7 @@ void PeerListContent::selectByMouse(QPoint globalPosition) {
if (row->disabled()) { if (row->disabled()) {
selected = Selected(); selected = Selected();
} else { } else {
if (getActionRect(row, selected.index).contains(point)) { if (getActiveActionRect(row, selected.index).contains(point)) {
selected.action = true; selected.action = true;
} }
} }
@ -1635,9 +1635,9 @@ void PeerListContent::selectByMouse(QPoint globalPosition) {
setSelected(selected); setSelected(selected);
} }
QRect PeerListContent::getActionRect(not_null<PeerListRow*> row, RowIndex index) const { QRect PeerListContent::getActiveActionRect(not_null<PeerListRow*> row, RowIndex index) const {
auto actionSize = row->actionSize(); auto actionSize = row->actionSize();
if (actionSize.isEmpty()) { if (actionSize.isEmpty() || row->actionDisabled()) {
return QRect(); return QRect();
} }
auto actionMargins = row->actionMargins(); auto actionMargins = row->actionMargins();

View File

@ -102,6 +102,9 @@ public:
virtual QSize actionSize() const { virtual QSize actionSize() const {
return QSize(); return QSize();
} }
virtual bool actionDisabled() const {
return false;
}
virtual QMargins actionMargins() const { virtual QMargins actionMargins() const {
return QMargins(); return QMargins();
} }
@ -607,7 +610,7 @@ private:
int getRowTop(RowIndex row) const; int getRowTop(RowIndex row) const;
PeerListRow *getRow(RowIndex element); PeerListRow *getRow(RowIndex element);
RowIndex findRowIndex(not_null<PeerListRow*> row, RowIndex hint = RowIndex()); RowIndex findRowIndex(not_null<PeerListRow*> row, RowIndex hint = RowIndex());
QRect getActionRect(not_null<PeerListRow*> row, RowIndex index) const; QRect getActiveActionRect(not_null<PeerListRow*> row, RowIndex index) const;
crl::time paintRow(Painter &p, crl::time ms, RowIndex index); crl::time paintRow(Painter &p, crl::time ms, RowIndex index);

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "core/core_settings.h" #include "core/core_settings.h"
#include "data/data_changes.h" #include "data/data_changes.h"
#include "data/data_user.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "data/data_group_call.h" #include "data/data_group_call.h"
@ -395,8 +396,10 @@ void GroupCall::sendMutedUpdate() {
inputCall(), inputCall(),
MTP_inputUserSelf() MTP_inputUserSelf()
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
_updateMuteRequestId = 0;
_channel->session().api().applyUpdates(result); _channel->session().api().applyUpdates(result);
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
_updateMuteRequestId = 0;
if (error.type() == u"GROUP_CALL_FORBIDDEN"_q if (error.type() == u"GROUP_CALL_FORBIDDEN"_q
&& _state.current() == State::Joined) { && _state.current() == State::Joined) {
setState(State::Joining); setState(State::Joining);
@ -416,6 +419,24 @@ void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) {
} }
} }
void GroupCall::toggleMute(not_null<UserData*> user, bool mute) {
_api.request(MTPphone_EditGroupCallMember(
MTP_flags(mute
? MTPphone_EditGroupCallMember::Flag::f_muted
: MTPphone_EditGroupCallMember::Flag(0)),
inputCall(),
user->inputUser
)).done([=](const MTPUpdates &result) {
_channel->session().api().applyUpdates(result);
}).fail([=](const RPCError &error) {
if (error.type() == u"GROUP_CALL_FORBIDDEN"_q
&& _state.current() == State::Joined) {
setState(State::Joining);
rejoin();
}
}).send();
}
//void GroupCall::setAudioVolume(bool input, float level) { //void GroupCall::setAudioVolume(bool input, float level) {
// if (_instance) { // if (_instance) {
// if (input) { // if (input) {

View File

@ -80,6 +80,8 @@ public:
//void setAudioVolume(bool input, float level); //void setAudioVolume(bool input, float level);
void setAudioDuckingEnabled(bool enabled); void setAudioDuckingEnabled(bool enabled);
void toggleMute(not_null<UserData*> user, bool mute);
[[nodiscard]] rpl::lifetime &lifetime() { [[nodiscard]] rpl::lifetime &lifetime() {
return _lifetime; return _lifetime;
} }

View File

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/ripple_animation.h" #include "ui/effects/ripple_animation.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "facades.h"
#include "styles/style_calls.h" #include "styles/style_calls.h"
namespace Calls { namespace Calls {
@ -35,6 +36,9 @@ public:
}; };
void updateState(const Data::GroupCall::Participant *participant); void updateState(const Data::GroupCall::Participant *participant);
[[nodiscard]] State state() const {
return _state;
}
void addActionRipple(QPoint point, Fn<void()> updateCallback) override; void addActionRipple(QPoint point, Fn<void()> updateCallback) override;
void stopLastActionRipple() override; void stopLastActionRipple() override;
@ -45,6 +49,9 @@ public:
QSize actionSize() const override { QSize actionSize() const override {
return QSize(_st->width, _st->height); return QSize(_st->width, _st->height);
} }
bool actionDisabled() const override {
return peer()->isSelf() || !_channel->amCreator();
}
QMargins actionMargins() const override { QMargins actionMargins() const override {
return QMargins( return QMargins(
0, 0,
@ -70,6 +77,7 @@ private:
State state); State state);
State _state = State::Inactive; State _state = State::Inactive;
not_null<ChannelData*> _channel;
not_null<const style::IconButton*> _st; not_null<const style::IconButton*> _st;
std::unique_ptr<Ui::RippleAnimation> _actionRipple; std::unique_ptr<Ui::RippleAnimation> _actionRipple;
@ -82,6 +90,8 @@ class MembersController final
public: public:
explicit MembersController(not_null<GroupCall*> call); explicit MembersController(not_null<GroupCall*> call);
using MuteRequest = GroupMembers::MuteRequest;
Main::Session &session() const override; Main::Session &session() const override;
void prepare() override; void prepare() override;
void rowClicked(not_null<PeerListRow*> row) override; void rowClicked(not_null<PeerListRow*> row) override;
@ -94,9 +104,9 @@ public:
[[nodiscard]] rpl::producer<int> fullCountValue() const { [[nodiscard]] rpl::producer<int> fullCountValue() const {
return _fullCount.value(); return _fullCount.value();
} }
[[nodiscard]] rpl::producer<MuteRequest> toggleMuteRequests() const;
private: private:
[[nodiscard]] std::unique_ptr<PeerListRow> createSelfRow() const; [[nodiscard]] std::unique_ptr<PeerListRow> createSelfRow() const;
[[nodiscard]] std::unique_ptr<PeerListRow> createRow( [[nodiscard]] std::unique_ptr<PeerListRow> createRow(
const Data::GroupCall::Participant &participant) const; const Data::GroupCall::Participant &participant) const;
@ -114,6 +124,7 @@ private:
const base::weak_ptr<GroupCall> _call; const base::weak_ptr<GroupCall> _call;
const not_null<ChannelData*> _channel; const not_null<ChannelData*> _channel;
rpl::event_stream<MuteRequest> _toggleMuteRequests;
rpl::variable<int> _fullCount = 1; rpl::variable<int> _fullCount = 1;
Ui::BoxPointer _addBox; Ui::BoxPointer _addBox;
rpl::lifetime _lifetime; rpl::lifetime _lifetime;
@ -123,6 +134,7 @@ private:
Row::Row(not_null<ChannelData*> channel, not_null<UserData*> user) Row::Row(not_null<ChannelData*> channel, not_null<UserData*> user)
: PeerListRow(user) : PeerListRow(user)
, _state(ComputeState(channel, user)) , _state(ComputeState(channel, user))
, _channel(channel)
, _st(ComputeIconStyle(_state)) { , _st(ComputeIconStyle(_state)) {
refreshStatus(); refreshStatus();
} }
@ -384,17 +396,25 @@ void MembersController::loadMoreRows() {
} }
} }
void MembersController::rowClicked(not_null<PeerListRow*> row) { auto MembersController::toggleMuteRequests() const
Expects(row->peer()->isUser()); -> rpl::producer<GroupMembers::MuteRequest> {
return _toggleMuteRequests.events();
}
const auto user = row->peer()->asUser(); void MembersController::rowClicked(not_null<PeerListRow*> row) {
Ui::showPeerHistory(row->peer(), ShowAtUnreadMsgId);
} }
void MembersController::rowActionClicked( void MembersController::rowActionClicked(
not_null<PeerListRow*> row) { not_null<PeerListRow*> row) {
Expects(row->peer()->isUser()); Expects(row->peer()->isUser());
const auto user = row->peer()->asUser(); const auto real = static_cast<Row*>(row.get());
const auto mute = (real->state() != Row::State::Muted);
_toggleMuteRequests.fire(MuteRequest{
.user = row->peer()->asUser(),
.mute = mute,
});
} }
base::unique_qptr<Ui::PopupMenu> MembersController::rowContextMenu( base::unique_qptr<Ui::PopupMenu> MembersController::rowContextMenu(
@ -440,6 +460,12 @@ GroupMembers::GroupMembers(
}, lifetime()); }, lifetime());
} }
auto GroupMembers::toggleMuteRequests() const
-> rpl::producer<GroupMembers::MuteRequest> {
return static_cast<MembersController*>(
_listController.get())->toggleMuteRequests();
}
int GroupMembers::desiredHeight() const { int GroupMembers::desiredHeight() const {
auto desired = _header ? _header->height() : 0; auto desired = _header ? _header->height() : 0;
auto count = [this] { auto count = [this] {

View File

@ -29,7 +29,13 @@ public:
QWidget *parent, QWidget *parent,
not_null<GroupCall*> call); not_null<GroupCall*> call);
int desiredHeight() const; struct MuteRequest {
not_null<UserData*> user;
bool mute = false;
};
[[nodiscard]] int desiredHeight() const;
[[nodiscard]] rpl::producer<MuteRequest> toggleMuteRequests() const;
private: private:
using ListWidget = PeerListContent; using ListWidget = PeerListContent;

View File

@ -342,6 +342,13 @@ void GroupPanel::initWithCall(GroupCall *call) {
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
updateControlsGeometry(); updateControlsGeometry();
}, _members->lifetime()); }, _members->lifetime());
_members->toggleMuteRequests(
) | rpl::start_with_next([=](GroupMembers::MuteRequest request) {
if (_call) {
_call->toggleMute(request.user, request.mute);
}
}, _callLifetime);
} }
void GroupPanel::initLayout() { void GroupPanel::initLayout() {