Exemple #1
0
void ApiWrap::lastParticipantsDone(ChannelData *peer, const MTPchannels_ChannelParticipants &result, mtpRequestId req) {
	bool bots = (_botsRequests.value(peer) == req), fromStart = false;
	if (bots) {
		_botsRequests.remove(peer);
	} else {
		int32 was = _participantsRequests.value(peer);
		if (was == req) {
			fromStart = true;
		} else if (was != -req) {
			return;
		}
		_participantsRequests.remove(peer);
	}

	if (!peer->mgInfo || result.type() != mtpc_channels_channelParticipants) return;

	History *h = 0;
	if (bots) {
		h = App::historyLoaded(peer->id);
		peer->mgInfo->bots.clear();
		peer->mgInfo->botStatus = -1;
	} else if (fromStart) {
		peer->mgInfo->lastAdmins.clear();
		peer->mgInfo->lastParticipants.clear();
		peer->mgInfo->lastParticipantsStatus = MegagroupInfo::LastParticipantsUpToDate;
	}

	const MTPDchannels_channelParticipants &d(result.c_channels_channelParticipants());
	const QVector<MTPChannelParticipant> &v(d.vparticipants.c_vector().v);
	App::feedUsers(d.vusers);
	bool added = false, needBotsInfos = false;
	int32 botStatus = peer->mgInfo->botStatus;
	bool keyboardBotFound = !h || !h->lastKeyboardFrom;
	for (QVector<MTPChannelParticipant>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) {
		int32 userId = 0;
		bool admin = false;

		switch (i->type()) {
		case mtpc_channelParticipant: userId = i->c_channelParticipant().vuser_id.v; break;
		case mtpc_channelParticipantSelf: userId = i->c_channelParticipantSelf().vuser_id.v; break;
		case mtpc_channelParticipantModerator: userId = i->c_channelParticipantModerator().vuser_id.v; break;
		case mtpc_channelParticipantEditor: userId = i->c_channelParticipantEditor().vuser_id.v; admin = true; break;
		case mtpc_channelParticipantKicked: userId = i->c_channelParticipantKicked().vuser_id.v; break;
		case mtpc_channelParticipantCreator: userId = i->c_channelParticipantCreator().vuser_id.v; admin = true; break;
		}
		UserData *u = App::user(userId);
		if (bots) {
			if (u->botInfo) {
				peer->mgInfo->bots.insert(u, true);
				botStatus = 2;// (botStatus > 0/* || !i.key()->botInfo->readsAllHistory*/) ? 2 : 1;
				if (!u->botInfo->inited) {
					needBotsInfos = true;
				}
			}
			if (!keyboardBotFound && u->id == h->lastKeyboardFrom) {
				keyboardBotFound = true;
			}
		} else {
			if (peer->mgInfo->lastParticipants.indexOf(u) < 0) {
				peer->mgInfo->lastParticipants.push_back(u);
				if (admin) peer->mgInfo->lastAdmins.insert(u, true);
				if (u->botInfo) {
					peer->mgInfo->bots.insert(u, true);
					if (peer->mgInfo->botStatus != 0 && peer->mgInfo->botStatus < 2) {
						peer->mgInfo->botStatus = 2;
					}
				}
				added = true;
			}
		}
	}
	if (needBotsInfos) {
		requestFullPeer(peer);
	}
	if (!keyboardBotFound) {
		h->clearLastKeyboard();
		if (App::main()) App::main()->updateBotKeyboard(h);
	}
	if (d.vcount.v > peer->count) {
		peer->count = d.vcount.v;
	} else if (v.count() > peer->count) {
		peer->count = v.count();
	}
	if (!bots && v.isEmpty()) {
		peer->count = peer->mgInfo->lastParticipants.size();
	}
	peer->mgInfo->botStatus = botStatus;
	if (App::main()) emit fullPeerUpdated(peer);
}
Exemple #2
0
void MembersBox::Inner::membersReceived(const MTPchannels_ChannelParticipants &result, mtpRequestId req) {
	clear();
	_loadingRequestId = 0;

	if (result.type() == mtpc_channels_channelParticipants) {
		const auto &d(result.c_channels_channelParticipants());
		const auto &v(d.vparticipants.c_vector().v);
		_rows.reserve(v.size());
		_datas.reserve(v.size());
		_dates.reserve(v.size());
		_roles.reserve(v.size());

		if (_filter == MembersFilter::Recent && _channel->membersCount() < d.vcount.v) {
			_channel->setMembersCount(d.vcount.v);
			if (App::main()) emit App::main()->peerUpdated(_channel);
		} else if (_filter == MembersFilter::Admins && _channel->adminsCount() < d.vcount.v) {
			_channel->setAdminsCount(d.vcount.v);
			if (App::main()) emit App::main()->peerUpdated(_channel);
		}
		App::feedUsers(d.vusers);

		for (QVector<MTPChannelParticipant>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) {
			int32 userId = 0, addedTime = 0;
			MemberRole role = MemberRole::None;
			switch (i->type()) {
			case mtpc_channelParticipant:
				userId = i->c_channelParticipant().vuser_id.v;
				addedTime = i->c_channelParticipant().vdate.v;
				break;
			case mtpc_channelParticipantSelf:
				role = MemberRole::Self;
				userId = i->c_channelParticipantSelf().vuser_id.v;
				addedTime = i->c_channelParticipantSelf().vdate.v;
				break;
			case mtpc_channelParticipantModerator:
				role = MemberRole::Moderator;
				userId = i->c_channelParticipantModerator().vuser_id.v;
				addedTime = i->c_channelParticipantModerator().vdate.v;
				break;
			case mtpc_channelParticipantEditor:
				role = MemberRole::Editor;
				userId = i->c_channelParticipantEditor().vuser_id.v;
				addedTime = i->c_channelParticipantEditor().vdate.v;
				break;
			case mtpc_channelParticipantKicked:
				userId = i->c_channelParticipantKicked().vuser_id.v;
				addedTime = i->c_channelParticipantKicked().vdate.v;
				role = MemberRole::Kicked;
				break;
			case mtpc_channelParticipantCreator:
				userId = i->c_channelParticipantCreator().vuser_id.v;
				addedTime = _channel->date;
				role = MemberRole::Creator;
				break;
			}
			if (UserData *user = App::userLoaded(userId)) {
				_rows.push_back(user);
				_dates.push_back(date(addedTime));
				_roles.push_back(role);
				_datas.push_back(0);
			}
		}

		// update admins if we got all of them
		if (_filter == MembersFilter::Admins && _channel->isMegagroup() && _rows.size() < Global::ChatSizeMax()) {
			_channel->mgInfo->lastAdmins.clear();
			for (int32 i = 0, l = _rows.size(); i != l; ++i) {
				if (_roles.at(i) == MemberRole::Creator || _roles.at(i) == MemberRole::Editor) {
					_channel->mgInfo->lastAdmins.insert(_rows.at(i));
				}
			}

			Notify::peerUpdatedDelayed(_channel, Notify::PeerUpdate::Flag::AdminsChanged);
		}
	}
	if (_rows.isEmpty()) {
		_rows.push_back(App::self());
		_dates.push_back(date(MTP_int(_channel->date)));
		_roles.push_back(MemberRole::Self);
		_datas.push_back(0);
	}

	clearSel();
	_loading = false;
	refresh();

	emit loaded();
}