diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index dc00e279c3..0bf4acff41 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -776,6 +776,7 @@ void AddSpecialBoxSearchController::searchQuery(const QString &query) { _requestId = 0; _participantsLoaded = false; _chatsContactsAdded = false; + _chatMembersAdded = false; _globalLoaded = false; if (!_query.isEmpty() && !searchParticipantsInCache()) { _timer.callOnce(AutoSearchTimeout); @@ -825,7 +826,7 @@ bool AddSpecialBoxSearchController::loadMoreRows() { if (_globalLoaded) { return true; } - if (_participantsLoaded) { + if (_participantsLoaded || _chatMembersAdded) { if (!_chatsContactsAdded) { addChatsContacts(); } @@ -833,7 +834,9 @@ bool AddSpecialBoxSearchController::loadMoreRows() { requestGlobal(); } } else if (const auto chat = _peer->asChat()) { - addChatMembers(chat); + if (!_chatMembersAdded) { + addChatMembers(chat); + } } else if (!isLoading()) { requestParticipants(); } @@ -997,6 +1000,7 @@ void AddSpecialBoxSearchController::addChatMembers( return; } + _chatMembersAdded = true; const auto wordList = TextUtilities::PrepareSearchWords(_query); if (wordList.empty()) { return; @@ -1030,7 +1034,6 @@ void AddSpecialBoxSearchController::addChatMembers( void AddSpecialBoxSearchController::addChatsContacts() { _chatsContactsAdded = true; - const auto wordList = TextUtilities::PrepareSearchWords(_query); if (wordList.empty()) { return; diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index 3fa536cb0b..dd4c1294f9 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -173,6 +173,7 @@ private: int _offset = 0; bool _participantsLoaded = false; bool _chatsContactsAdded = false; + bool _chatMembersAdded = false; bool _globalLoaded = false; std::map _participantsCache; std::map _participantsQueries; diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 1fe0e71b6e..eb1f8887aa 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -29,6 +29,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { +// How many messages from chat history server should forward to user, +// that was added to this chat. +constexpr auto kForwardMessagesOnAdd = 100; + constexpr auto kParticipantsFirstPageCount = 16; constexpr auto kParticipantsPerPage = 200; constexpr auto kSortByOnlineDelay = TimeMs(1000); @@ -47,9 +51,35 @@ void RemoveAdmin( )).done([=](const MTPUpdates &result) { channel->session().api().applyUpdates(result); channel->applyEditAdmin(user, oldRights, newRights); - onDone(); + if (onDone) { + onDone(); + } }).fail([=](const RPCError &error) { - onFail(); + if (onFail) { + onFail(); + } + }).send(); +} + +void AddChatParticipant( + not_null chat, + not_null user, + Fn onDone, + Fn onFail) { + chat->session().api().request(MTPmessages_AddChatUser( + chat->inputChat, + user->inputUser, + MTP_int(kForwardMessagesOnAdd) + )).done([=](const MTPUpdates &result) { + chat->session().api().applyUpdates(result); + if (onDone) { + onDone(); + } + }).fail([=](const RPCError &error) { + ShowAddParticipantsError(error.type(), chat, { 1, user }); + if (onFail) { + onFail(); + } }).send(); } @@ -58,16 +88,28 @@ void SaveChatAdmin( not_null user, bool isAdmin, Fn onDone, - Fn onFail) { + Fn onFail, + bool retryOnNotParticipant = true) { chat->session().api().request(MTPmessages_EditChatAdmin( chat->inputChat, user->inputUser, MTP_bool(isAdmin) )).done([=](const MTPBool &result) { chat->applyEditAdmin(user, isAdmin); - onDone(); + if (onDone) { + onDone(); + } }).fail([=](const RPCError &error) { - onFail(); + const auto &type = error.type(); + if (retryOnNotParticipant + && isAdmin + && (type == qstr("USER_NOT_PARTICIPANT"))) { + AddChatParticipant(chat, user, [=] { + SaveChatAdmin(chat, user, isAdmin, onDone, onFail, false); + }, onFail); + } else if (onFail) { + onFail(); + } }).send(); }