Show channel members inside Info as well.

This commit is contained in:
John Preston 2017-11-17 20:06:20 +04:00
parent fc4c31b673
commit 4aae4f9399
4 changed files with 90 additions and 46 deletions

View File

@ -879,6 +879,8 @@ void ChannelData::applyEditAdmin(not_null<UserData*> user, const MTPChannelAdmin
void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
auto flags = Notify::PeerUpdate::Flag::BannedUsersChanged | Notify::PeerUpdate::Flag::None;
auto isKicked = (newRights.c_channelBannedRights().vflags.v & MTPDchannelBannedRights::Flag::f_view_messages);
auto isRestricted = !isKicked && (newRights.c_channelBannedRights().vflags.v != 0);
if (mgInfo) {
if (mgInfo->lastAdmins.contains(user)) { // If rights are empty - still remove admin? TODO check
mgInfo->lastAdmins.remove(user);
@ -888,8 +890,6 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
flags |= Notify::PeerUpdate::Flag::AdminsChanged;
}
}
auto isKicked = (newRights.c_channelBannedRights().vflags.v & MTPDchannelBannedRights::Flag::f_view_messages);
auto isRestricted = !isKicked && (newRights.c_channelBannedRights().vflags.v != 0);
auto it = mgInfo->lastRestricted.find(user);
if (isRestricted) {
if (it == mgInfo->lastRestricted.cend()) {
@ -927,6 +927,11 @@ void ChannelData::applyEditBanned(not_null<UserData*> user, const MTPChannelBann
Auth().data().removeMegagroupParticipant(this, user);
}
}
} else {
if (isKicked && membersCount() > 1) {
setMembersCount(membersCount() - 1);
flags |= Notify::PeerUpdate::Flag::MembersChanged;
}
}
Notify::peerUpdatedDelayed(this, flags);
}

View File

@ -37,6 +37,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "boxes/report_box.h"
#include "lang/lang_keys.h"
#include "info/info_controller.h"
#include "info/info_memento.h"
#include "info/info_top_bar_override.h"
#include "info/profile/info_profile_icon.h"
#include "info/profile/info_profile_values.h"
@ -44,7 +45,6 @@ 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"
@ -668,6 +668,33 @@ object_ptr<Ui::RpWidget> SetupActions(
return filler.fill();
}
void SetupAddChannelMember(
not_null<Ui::RpWidget*> parent,
not_null<ChannelData*> channel) {
auto add = Ui::CreateChild<Ui::IconButton>(
parent.get(),
st::infoMembersAddMember);
add->showOn(CanAddMemberValue(channel));
add->addClickHandler([channel] {
if (channel->membersCount() >= Global::ChatSizeMax()) {
Ui::show(
Box<MaxInviteBox>(channel),
LayerOption::KeepOther);
} else {
AddParticipantsBoxController::Start(channel, {});
}
});
parent->widthValue()
| rpl::start_with_next([add](int newWidth) {
auto availableWidth = newWidth
- st::infoMembersButtonPosition.x();
add->moveToLeft(
availableWidth - add->width(),
st::infoMembersButtonPosition.y(),
newWidth);
}, add->lifetime());
}
object_ptr<Ui::RpWidget> SetupChannelMembers(
not_null<Controller*> controller,
not_null<Ui::RpWidget*> parent,
@ -690,11 +717,9 @@ object_ptr<Ui::RpWidget> SetupChannelMembers(
return lng_chat_status_members(lt_count, count);
});
auto membersCallback = [controller, channel] {
using Controller = ::Profile::ParticipantsBoxController;
Controller::Start(
controller->window(),
channel,
Controller::Role::Members);
controller->window()->showSection(Info::Memento(
channel->id,
Section::Type::Members));
};
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
@ -705,11 +730,14 @@ object_ptr<Ui::RpWidget> SetupChannelMembers(
auto members = result->entity();
members->add(object_ptr<BoxContentDivider>(members));
members->add(CreateSkipWidget(members));
AddActionButton(
auto button = AddActionButton(
members,
std::move(membersText),
rpl::single(true),
std::move(membersCallback));
std::move(membersCallback))->entity();
SetupAddChannelMember(button, channel);
object_ptr<FloatingIcon>(
members,
st::infoIconMembers,

View File

@ -47,7 +47,7 @@ namespace Info {
namespace Profile {
namespace {
constexpr auto kEnableSearchMembersAfterCount = 20;
constexpr auto kEnableSearchMembersAfterCount = 1;
} // namespace

View File

@ -74,6 +74,9 @@ void ParticipantsBoxController::setupSortByOnline() {
}
void ParticipantsBoxController::setupListChangeViewers() {
if (!_channel->isMegagroup()) {
return;
}
Auth().data().megagroupParticipantAdded(_channel)
| rpl::start_with_next([this](not_null<UserData*> user) {
if (delegate()->peerListFullRowsCount() > 0) {
@ -108,6 +111,7 @@ void ParticipantsBoxController::sortByOnlineDelayed() {
void ParticipantsBoxController::sortByOnline() {
if (_role != Role::Profile
|| !_channel->isMegagroup()
|| _channel->membersCount() > Global::ChatSizeMax()) {
_onlineCount = 0;
return;
@ -194,6 +198,7 @@ void ParticipantsBoxController::Start(
void ParticipantsBoxController::addNewItem() {
Expects(_role != Role::Profile);
if (_role == Role::Members) {
if (_channel->membersCount() >= Global::ChatSizeMax()) {
Ui::show(
@ -263,34 +268,35 @@ std::unique_ptr<PeerListState> ParticipantsBoxController::saveState() {
my->searchState = search->saveState();
}
auto weak = result.get();
Auth().data().megagroupParticipantAdded(_channel)
| rpl::start_with_next([weak](not_null<UserData*> user) {
if (!weak->list.empty()) {
if (weak->list[0] == user) {
return;
if (_channel->isMegagroup()) {
auto weak = result.get();
Auth().data().megagroupParticipantAdded(_channel)
| rpl::start_with_next([weak](not_null<UserData*> user) {
if (!weak->list.empty()) {
if (weak->list[0] == user) {
return;
}
}
}
auto pos = base::find(weak->list, user);
if (pos == weak->list.cend()) {
weak->list.push_back(user);
}
base::stable_partition(weak->list, [user](not_null<PeerData*> peer) {
return (peer == user);
});
}, my->lifetime);
Auth().data().megagroupParticipantRemoved(_channel)
| rpl::start_with_next([weak](not_null<UserData*> user) {
weak->list.erase(std::remove(
weak->list.begin(),
weak->list.end(),
user), weak->list.end());
weak->filterResults.erase(std::remove(
weak->filterResults.begin(),
weak->filterResults.end(),
user), weak->filterResults.end());
}, my->lifetime);
auto pos = base::find(weak->list, user);
if (pos == weak->list.cend()) {
weak->list.push_back(user);
}
base::stable_partition(weak->list, [user](not_null<PeerData*> peer) {
return (peer == user);
});
}, my->lifetime);
Auth().data().megagroupParticipantRemoved(_channel)
| rpl::start_with_next([weak](not_null<UserData*> user) {
weak->list.erase(std::remove(
weak->list.begin(),
weak->list.end(),
user), weak->list.end());
weak->filterResults.erase(std::remove(
weak->filterResults.begin(),
weak->filterResults.end(),
user), weak->filterResults.end());
}, my->lifetime);
}
result->controllerState = std::move(my);
return result;
}
@ -619,15 +625,20 @@ Ui::PopupMenu *ParticipantsBoxController::rowContextMenu(
});
}
if (canRestrictUser(user)) {
auto isGroup = _channel->isMegagroup();
if (isGroup) {
result->addAction(
lang(lng_context_restrict_user),
[weak = base::make_weak_unique(this), user]{
if (weak) {
weak->showRestricted(user);
}
});
}
result->addAction(
lang(lng_context_restrict_user),
[weak = base::make_weak_unique(this), user]{
if (weak) {
weak->showRestricted(user);
}
});
result->addAction(
lang(lng_context_remove_from_group),
lang(isGroup
? lng_context_remove_from_group
: lng_profile_kick),
[weak = base::make_weak_unique(this), user] {
if (weak) {
weak->kickMember(user);