diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 46a511e1e..dadfc0f35 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -1509,16 +1509,28 @@ void ApiWrap::stickerSetDisenabled(mtpRequestId requestId) { } }; -void ApiWrap::joinChannel(ChannelData *channel) { +void ApiWrap::joinChannel(not_null 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(lang(channel->isMegagroup() + ? lng_group_not_accessible + : lng_channel_not_accessible))); + } else if (error.type() == qstr("CHANNELS_TOO_MUCH")) { Ui::show(Box(lang(lng_join_channel_error))); + } else if (error.type() == qstr("USERS_TOO_MUCH")) { + Ui::show(Box(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 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(); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index 5a1aee22f..45c36ceb2 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -133,8 +133,8 @@ public: std::vector> *stickersByEmoji( not_null emoji); - void joinChannel(ChannelData *channel); - void leaveChannel(ChannelData *channel); + void joinChannel(not_null channel); + void leaveChannel(not_null channel); void blockUser(UserData *user); void unblockUser(UserData *user); diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 5b4fa85a0..aede8d5ad 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -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(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(lang(lng_join_channel_error))); - } else if (error.type() == qstr("USERS_TOO_MUCH")) { - Ui::show(Box(lang(lng_group_full))); - } - - return false; + Auth().api().joinChannel(_peer->asChannel()); } void HistoryWidget::onMuteUnmute() { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index e7c2e9b53..a5941c9c4 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -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 {