Pass already-members when adding members to channel.

This commit is contained in:
John Preston 2017-11-19 18:41:52 +04:00
parent 68bc8d0231
commit f1f955b7ac
7 changed files with 101 additions and 31 deletions

View File

@ -810,6 +810,35 @@ void ApiWrap::unblockParticipant(PeerData *peer, UserData *user) {
}
}
void ApiWrap::requestChannelMembersForAdd(
not_null<ChannelData*> channel,
base::lambda<void(const MTPchannels_ChannelParticipants&)> callback) {
_channelMembersForAddCallback = std::move(callback);
if (_channelMembersForAdd == channel) {
return;
}
request(base::take(_channelMembersForAddRequestId)).cancel();
auto requestData = MTPchannels_GetParticipants(
channel->inputChannel,
MTP_channelParticipantsRecent(),
MTP_int(0),
MTP_int(Global::ChatSizeMax()));
_channelMembersForAdd = channel;
_channelMembersForAddRequestId = request(
std::move(requestData)
).done([this](const MTPchannels_ChannelParticipants &result) {
base::take(_channelMembersForAddRequestId);
base::take(_channelMembersForAdd);
base::take(_channelMembersForAddCallback)(result);
}).fail([this](const RPCError &error) {
base::take(_channelMembersForAddRequestId);
base::take(_channelMembersForAdd);
base::take(_channelMembersForAddCallback);
}).send();
}
void ApiWrap::scheduleStickerSetRequest(uint64 setId, uint64 access) {
if (!_stickerSetRequests.contains(setId)) {
_stickerSetRequests.insert(setId, qMakePair(access, 0));

View File

@ -65,6 +65,9 @@ public:
void requestBots(ChannelData *channel);
void requestParticipantsCountDelayed(ChannelData *channel);
void requestChannelMembersForAdd(
not_null<ChannelData*> channel,
base::lambda<void(const MTPchannels_ChannelParticipants&)> callback);
void processFullPeer(PeerData *peer, const MTPmessages_ChatFull &result);
void processFullPeer(UserData *user, const MTPUserFull &result);
@ -212,6 +215,10 @@ private:
PeerRequests _botsRequests;
base::DelayedCallTimer _participantsCountRequestTimer;
ChannelData *_channelMembersForAdd = nullptr;
mtpRequestId _channelMembersForAddRequestId = 0;
base::lambda<void(const MTPchannels_ChannelParticipants&)> _channelMembersForAddCallback;
typedef QPair<PeerData*, UserData*> KickRequest;
typedef QMap<KickRequest, mtpRequestId> KickRequests;
KickRequests _kickRequests;

View File

@ -604,7 +604,6 @@ void SetupChannelBox::prepare() {
AddParticipantsBoxController::Start(_channel);
}
});
updateMaxHeight();
}

View File

@ -695,13 +695,7 @@ void SetupAddChannelMember(
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, {});
}
Window::PeerMenuAddChannelMembers(channel);
});
parent->widthValue()
| rpl::start_with_next([add](int newWidth) {

View File

@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include "media/player/media_player_float.h"
#include <rpl/merge.h>
#include "data/data_document.h"
#include "history/history_media.h"
#include "media/media_clip_reader.h"
@ -55,13 +56,9 @@ Float::Float(
prepareShadow();
// #TODO rpl::merge
Auth().data().itemLayoutChanged()
| rpl::start_with_next([this](auto item) {
if (_item == item) {
repaintItem();
}
}, lifetime());
Auth().data().itemRepaintRequest()
rpl::merge(
Auth().data().itemLayoutChanged(),
Auth().data().itemRepaintRequest())
| rpl::start_with_next([this](auto item) {
if (_item == item) {
repaintItem();

View File

@ -33,6 +33,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "observer_peer.h"
#include "styles/style_boxes.h"
#include "window/window_controller.h"
#include <range/v3/view/transform.hpp>
#include <range/v3/view/filter.hpp>
namespace Window {
namespace {
@ -45,21 +47,6 @@ void AddChatMembers(not_null<ChatData*> chat) {
}
}
void AddChannelMembers(not_null<ChannelData*> channel) {
if (channel->isMegagroup()) {
auto &participants = channel->mgInfo->lastParticipants;
AddParticipantsBoxController::Start(
channel,
{ participants.cbegin(), participants.cend() });
} else if (channel->membersCount() >= Global::ChatSizeMax()) {
Ui::show(
Box<MaxInviteBox>(channel),
LayerOption::KeepOther);
} else {
AddParticipantsBoxController::Start(channel, { });
}
}
class Filler {
public:
Filler(
@ -389,7 +376,7 @@ void Filler::addChannelActions(not_null<ChannelData*> channel) {
if (channel->canAddMembers()) {
_addAction(
lang(lng_channel_add_members),
[channel] { AddChannelMembers(channel); });
[channel] { PeerMenuAddChannelMembers(channel); });
}
}
if (channel->amIn()) {
@ -499,6 +486,62 @@ void PeerMenuShareContactBox(not_null<UserData*> user) {
}));
}
void PeerMenuAddChannelMembers(not_null<ChannelData*> channel) {
if (channel->isMegagroup()) {
auto &participants = channel->mgInfo->lastParticipants;
AddParticipantsBoxController::Start(
channel,
{ participants.cbegin(), participants.cend() });
return;
} else if (channel->membersCount() >= Global::ChatSizeMax()) {
Ui::show(
Box<MaxInviteBox>(channel),
LayerOption::KeepOther);
return;
}
auto callback = [channel](const MTPchannels_ChannelParticipants &result) {
Expects(result.type() == mtpc_channels_channelParticipants);
auto &participants = result.c_channels_channelParticipants();
App::feedUsers(participants.vusers);
auto applyToParticipant = [](
const MTPChannelParticipant &p,
auto &&method) {
switch (p.type()) {
case mtpc_channelParticipant:
return method(p.c_channelParticipant());
case mtpc_channelParticipantSelf:
return method(p.c_channelParticipantSelf());
case mtpc_channelParticipantAdmin:
return method(p.c_channelParticipantAdmin());
case mtpc_channelParticipantCreator:
return method(p.c_channelParticipantCreator());
case mtpc_channelParticipantBanned:
return method(p.c_channelParticipantBanned());
default: Unexpected("Type in PeerMenuAddChannelMembers()");
}
};
auto already = (
participants.vparticipants.v
) | ranges::view::transform([&](auto &&participant) {
return applyToParticipant(participant, [](auto &&data) {
return data.vuser_id.v;
});
}) | ranges::view::transform([](UserId userId) {
return App::userLoaded(userId);
}) | ranges::view::filter([](UserData *user) {
return (user != nullptr);
}) | ranges::to_vector;
AddParticipantsBoxController::Start(
channel,
{ already.begin(), already.end() });
};
Auth().api().requestChannelMembersForAdd(channel, callback);
}
void FillPeerMenu(
not_null<Controller*> controller,
not_null<PeerData*> peer,

View File

@ -43,5 +43,6 @@ void FillPeerMenu(
void PeerMenuDeleteContact(not_null<UserData*> user);
void PeerMenuShareContactBox(not_null<UserData*> user);
void PeerMenuAddContact(not_null<UserData*> user);
void PeerMenuAddChannelMembers(not_null<ChannelData*> channel);
} // namespace Window