Add members link in info for channel admins.

This commit is contained in:
John Preston 2017-11-10 23:19:43 +04:00
parent a6df928d45
commit dbb011fc56
8 changed files with 79 additions and 24 deletions

View File

@ -696,7 +696,8 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
| UpdateFlag::UserIsBlocked
| UpdateFlag::AdminsChanged
| UpdateFlag::MembersChanged
| UpdateFlag::UserOnlineChanged;
| UpdateFlag::UserOnlineChanged
| UpdateFlag::ChannelAmIn;
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(changes, [this](const Notify::PeerUpdate &update) {
if (update.peer == _peer) {
if (update.flags & UpdateFlag::ChannelRightsChanged) {
@ -730,7 +731,8 @@ HistoryWidget::HistoryWidget(QWidget *parent, not_null<Window::Controller*> cont
if (update.flags & (UpdateFlag::UserIsBlocked
| UpdateFlag::AdminsChanged
| UpdateFlag::MembersChanged
| UpdateFlag::UserOnlineChanged)) {
| UpdateFlag::UserOnlineChanged
| UpdateFlag::ChannelAmIn)) {
handlePeerUpdate();
}
}

View File

@ -321,7 +321,7 @@ infoNotificationsIconPosition: point(20px, 5px);
infoSharedMediaIconPosition: point(20px, 24px);
infoSharedMediaButtonIconPosition: point(20px, 3px);
infoIconPosition: point(20px, 15px);
infoChannelMembersIconPosition: point(20px, 24px);
infoLabeledOneLine: FlatLabel(defaultFlatLabel) {
maxHeight: 20px;
style: TextStyle(defaultTextStyle) {

View File

@ -262,7 +262,7 @@ void WrapWidget::createTopBar() {
}
if (_controller->section().type() == Section::Type::Profile) {
addProfileMenuButton();
addProfileNotificationsButton();
// addProfileNotificationsButton();
}
_topBar->move(0, 0);

View File

@ -21,6 +21,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/profile/info_profile_actions.h"
#include <rpl/flatten_latest.h>
#include <rpl/combine.h>
#include "data/data_peer_values.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/padding_wrap.h"
#include "ui/wrap/slide_wrap.h"
@ -42,6 +44,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/profile/info_profile_text.h"
#include "window/window_controller.h"
#include "window/window_peer_menu.h"
#include "profile/profile_channel_controllers.h"
#include "mainwidget.h"
#include "auth_session.h"
#include "messenger.h"
@ -557,8 +560,7 @@ void ActionsFiller::addLeaveChannelAction(
_wrap,
Lang::Viewer(lng_profile_leave_channel),
AmInChannelValue(channel),
[channel] { Auth().api().leaveChannel(channel); },
st::infoBlockButton);
[channel] { Auth().api().leaveChannel(channel); });
}
void ActionsFiller::addJoinChannelAction(
@ -608,10 +610,10 @@ void ActionsFiller::fillChannelActions(
using namespace rpl::mappers;
addJoinChannelAction(channel);
addLeaveChannelAction(channel);
if (!channel->amCreator()) {
addReportAction();
}
addLeaveChannelAction(channel);
}
object_ptr<Ui::RpWidget> ActionsFiller::fill() {
@ -631,12 +633,13 @@ object_ptr<Ui::RpWidget> ActionsFiller::fill() {
fillUserActions(user);
});
} else if (auto channel = _peer->asChannel()) {
if (!channel->isMegagroup()) {
if (channel->isMegagroup()) {
return { nullptr };
}
return wrapResult([=] {
fillChannelActions(channel);
});
}
}
return { nullptr };
}
@ -658,5 +661,56 @@ object_ptr<Ui::RpWidget> SetupActions(
return filler.fill();
}
object_ptr<Ui::RpWidget> SetupChannelMembers(
not_null<Controller*> controller,
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer) {
using namespace rpl::mappers;
auto channel = peer->asChannel();
if (!channel || channel->isMegagroup()) {
return { nullptr };
}
auto membersShown = rpl::combine(
MembersCountValue(channel),
Data::PeerFullFlagValue(
channel,
MTPDchannelFull::Flag::f_can_view_participants),
($1 > 0) && $2);
auto membersText = MembersCountValue(channel)
| rpl::map([](int count) {
return lng_chat_status_members(lt_count, count);
});
auto membersCallback = [controller, channel] {
using Controller = ::Profile::ParticipantsBoxController;
Controller::Start(
controller->window(),
channel,
Controller::Role::Members);
};
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
parent,
object_ptr<Ui::VerticalLayout>(parent));
result->toggleOn(std::move(membersShown));
auto members = result->entity();
members->add(object_ptr<BoxContentDivider>(members));
members->add(CreateSkipWidget(members));
AddActionButton(
members,
std::move(membersText),
rpl::single(true),
std::move(membersCallback));
object_ptr<FloatingIcon>(
members,
st::infoIconMembers,
st::infoChannelMembersIconPosition);
members->add(CreateSkipWidget(members));
return std::move(result);
}
} // namespace Profile
} // namespace Info

View File

@ -40,5 +40,10 @@ object_ptr<Ui::RpWidget> SetupActions(
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer);
object_ptr<Ui::RpWidget> SetupChannelMembers(
not_null<Controller*> controller,
not_null<Ui::RpWidget*> parent,
not_null<PeerData*> peer);
} // namespace Profile
} // namespace Info

View File

@ -102,8 +102,10 @@ object_ptr<Ui::RpWidget> InnerWidget::setupContent(
result->add(std::move(details));
}
result->add(setupSharedMedia(result.data()));
if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) {
result->add(std::move(members));
}
result->add(object_ptr<BoxContentDivider>(result));
if (auto actions = SetupActions(_controller, result.data(), _peer)) {
result->add(std::move(actions));
}

View File

@ -183,19 +183,11 @@ rpl::producer<int> MembersCountValue(
: 0;
});
} else if (auto channel = peer->asChannel()) {
return rpl::combine(
Notify::PeerUpdateValue(
return Notify::PeerUpdateValue(
channel,
Notify::PeerUpdate::Flag::MembersChanged),
Data::PeerFullFlagValue(
channel,
MTPDchannelFull::Flag::f_can_view_participants))
Notify::PeerUpdate::Flag::MembersChanged)
| rpl::map([channel] {
auto canViewCount = channel->canViewMembers()
|| !channel->isMegagroup();
return canViewCount
? qMax(channel->membersCount(), 1)
: 0;
return channel->membersCount();
});
}
Unexpected("User in MembersCountViewer().");

View File

@ -63,7 +63,7 @@ public:
}
private:
bool _infoExpanded = false;
bool _infoExpanded = true;
base::optional<QString> _membersSearch;
std::unique_ptr<PeerListState> _membersState;