Single place for joining channels, in ApiWrap.
This commit is contained in:
		
							parent
							
								
									c96cb37680
								
							
						
					
					
						commit
						3406f88fdc
					
				
					 4 changed files with 28 additions and 38 deletions
				
			
		| 
						 | 
				
			
			@ -1509,16 +1509,28 @@ void ApiWrap::stickerSetDisenabled(mtpRequestId requestId) {
 | 
			
		|||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void ApiWrap::joinChannel(ChannelData *channel) {
 | 
			
		||||
void ApiWrap::joinChannel(not_null<ChannelData*> channel) {
 | 
			
		||||
	if (channel->amIn()) {
 | 
			
		||||
		Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::ChannelAmIn);
 | 
			
		||||
		Notify::peerUpdatedDelayed(
 | 
			
		||||
			channel,
 | 
			
		||||
			Notify::PeerUpdate::Flag::ChannelAmIn);
 | 
			
		||||
	} else if (!_channelAmInRequests.contains(channel)) {
 | 
			
		||||
		auto requestId = request(MTPchannels_JoinChannel(channel->inputChannel)).done([this, channel](const MTPUpdates &result) {
 | 
			
		||||
		auto requestId = request(MTPchannels_JoinChannel(
 | 
			
		||||
			channel->inputChannel
 | 
			
		||||
		)).done([=](const MTPUpdates &result) {
 | 
			
		||||
			_channelAmInRequests.remove(channel);
 | 
			
		||||
			applyUpdates(result);
 | 
			
		||||
		}).fail([this, channel](const RPCError &error) {
 | 
			
		||||
			if (error.type() == qstr("CHANNELS_TOO_MUCH")) {
 | 
			
		||||
		}).fail([=](const RPCError &error) {
 | 
			
		||||
			if (error.type() == qstr("CHANNEL_PRIVATE")
 | 
			
		||||
				|| error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA")
 | 
			
		||||
				|| error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
 | 
			
		||||
				Ui::show(Box<InformBox>(lang(channel->isMegagroup()
 | 
			
		||||
					? lng_group_not_accessible
 | 
			
		||||
					: lng_channel_not_accessible)));
 | 
			
		||||
			} else if (error.type() == qstr("CHANNELS_TOO_MUCH")) {
 | 
			
		||||
				Ui::show(Box<InformBox>(lang(lng_join_channel_error)));
 | 
			
		||||
			} else if (error.type() == qstr("USERS_TOO_MUCH")) {
 | 
			
		||||
				Ui::show(Box<InformBox>(lang(lng_group_full)));
 | 
			
		||||
			}
 | 
			
		||||
			_channelAmInRequests.remove(channel);
 | 
			
		||||
		}).send();
 | 
			
		||||
| 
						 | 
				
			
			@ -1527,14 +1539,18 @@ void ApiWrap::joinChannel(ChannelData *channel) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ApiWrap::leaveChannel(ChannelData *channel) {
 | 
			
		||||
void ApiWrap::leaveChannel(not_null<ChannelData*> channel) {
 | 
			
		||||
	if (!channel->amIn()) {
 | 
			
		||||
		Notify::peerUpdatedDelayed(channel, Notify::PeerUpdate::Flag::ChannelAmIn);
 | 
			
		||||
		Notify::peerUpdatedDelayed(
 | 
			
		||||
			channel,
 | 
			
		||||
			Notify::PeerUpdate::Flag::ChannelAmIn);
 | 
			
		||||
	} else if (!_channelAmInRequests.contains(channel)) {
 | 
			
		||||
		auto requestId = request(MTPchannels_LeaveChannel(channel->inputChannel)).done([this, channel](const MTPUpdates &result) {
 | 
			
		||||
		auto requestId = request(MTPchannels_LeaveChannel(
 | 
			
		||||
			channel->inputChannel
 | 
			
		||||
		)).done([=](const MTPUpdates &result) {
 | 
			
		||||
			_channelAmInRequests.remove(channel);
 | 
			
		||||
			applyUpdates(result);
 | 
			
		||||
		}).fail([this, channel](const RPCError &error) {
 | 
			
		||||
		}).fail([=](const RPCError &error) {
 | 
			
		||||
			_channelAmInRequests.remove(channel);
 | 
			
		||||
		}).send();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -133,8 +133,8 @@ public:
 | 
			
		|||
	std::vector<not_null<DocumentData*>> *stickersByEmoji(
 | 
			
		||||
		not_null<EmojiPtr> emoji);
 | 
			
		||||
 | 
			
		||||
	void joinChannel(ChannelData *channel);
 | 
			
		||||
	void leaveChannel(ChannelData *channel);
 | 
			
		||||
	void joinChannel(not_null<ChannelData*> channel);
 | 
			
		||||
	void leaveChannel(not_null<ChannelData*> channel);
 | 
			
		||||
 | 
			
		||||
	void blockUser(UserData *user);
 | 
			
		||||
	void unblockUser(UserData *user);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2980,34 +2980,11 @@ void HistoryWidget::onBotStart() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
void HistoryWidget::onJoinChannel() {
 | 
			
		||||
	if (_unblockRequest) return;
 | 
			
		||||
	if (!_peer || !_peer->isChannel() || !isJoinChannel()) {
 | 
			
		||||
		updateControlsVisibility();
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_unblockRequest = MTP::send(MTPchannels_JoinChannel(_peer->asChannel()->inputChannel), rpcDone(&HistoryWidget::joinDone), rpcFail(&HistoryWidget::joinFail));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HistoryWidget::joinDone(const MTPUpdates &result, mtpRequestId req) {
 | 
			
		||||
	if (_unblockRequest == req) _unblockRequest = 0;
 | 
			
		||||
	if (App::main()) App::main()->sentUpdatesReceived(result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool HistoryWidget::joinFail(const RPCError &error, mtpRequestId req) {
 | 
			
		||||
	if (MTP::isDefaultHandledError(error)) return false;
 | 
			
		||||
 | 
			
		||||
	if (_unblockRequest == req) _unblockRequest = 0;
 | 
			
		||||
	if (error.type() == qstr("CHANNEL_PRIVATE") || error.type() == qstr("CHANNEL_PUBLIC_GROUP_NA") || error.type() == qstr("USER_BANNED_IN_CHANNEL")) {
 | 
			
		||||
		Ui::show(Box<InformBox>(lang((_peer && _peer->isMegagroup()) ? lng_group_not_accessible : lng_channel_not_accessible)));
 | 
			
		||||
		return true;
 | 
			
		||||
	} else if (error.type() == qstr("CHANNELS_TOO_MUCH")) {
 | 
			
		||||
		Ui::show(Box<InformBox>(lang(lng_join_channel_error)));
 | 
			
		||||
	} else if (error.type() == qstr("USERS_TOO_MUCH")) {
 | 
			
		||||
		Ui::show(Box<InformBox>(lang(lng_group_full)));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return false;
 | 
			
		||||
	Auth().api().joinChannel(_peer->asChannel());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HistoryWidget::onMuteUnmute() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -683,9 +683,6 @@ private:
 | 
			
		|||
	bool unblockFail(const RPCError &error, mtpRequestId req);
 | 
			
		||||
	void blockDone(PeerData *peer, const MTPBool &result);
 | 
			
		||||
 | 
			
		||||
	void joinDone(const MTPUpdates &result, mtpRequestId req);
 | 
			
		||||
	bool joinFail(const RPCError &error, mtpRequestId req);
 | 
			
		||||
 | 
			
		||||
	void countHistoryShowFrom();
 | 
			
		||||
 | 
			
		||||
	enum class TextUpdateEvent {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue