Add user to group on appointing of admin.

This commit is contained in:
John Preston 2019-01-14 17:01:00 +04:00
parent 9728ddeaf9
commit 4f33be20d4
3 changed files with 54 additions and 8 deletions

View File

@ -776,6 +776,7 @@ void AddSpecialBoxSearchController::searchQuery(const QString &query) {
_requestId = 0; _requestId = 0;
_participantsLoaded = false; _participantsLoaded = false;
_chatsContactsAdded = false; _chatsContactsAdded = false;
_chatMembersAdded = false;
_globalLoaded = false; _globalLoaded = false;
if (!_query.isEmpty() && !searchParticipantsInCache()) { if (!_query.isEmpty() && !searchParticipantsInCache()) {
_timer.callOnce(AutoSearchTimeout); _timer.callOnce(AutoSearchTimeout);
@ -825,7 +826,7 @@ bool AddSpecialBoxSearchController::loadMoreRows() {
if (_globalLoaded) { if (_globalLoaded) {
return true; return true;
} }
if (_participantsLoaded) { if (_participantsLoaded || _chatMembersAdded) {
if (!_chatsContactsAdded) { if (!_chatsContactsAdded) {
addChatsContacts(); addChatsContacts();
} }
@ -833,7 +834,9 @@ bool AddSpecialBoxSearchController::loadMoreRows() {
requestGlobal(); requestGlobal();
} }
} else if (const auto chat = _peer->asChat()) { } else if (const auto chat = _peer->asChat()) {
addChatMembers(chat); if (!_chatMembersAdded) {
addChatMembers(chat);
}
} else if (!isLoading()) { } else if (!isLoading()) {
requestParticipants(); requestParticipants();
} }
@ -997,6 +1000,7 @@ void AddSpecialBoxSearchController::addChatMembers(
return; return;
} }
_chatMembersAdded = true;
const auto wordList = TextUtilities::PrepareSearchWords(_query); const auto wordList = TextUtilities::PrepareSearchWords(_query);
if (wordList.empty()) { if (wordList.empty()) {
return; return;
@ -1030,7 +1034,6 @@ void AddSpecialBoxSearchController::addChatMembers(
void AddSpecialBoxSearchController::addChatsContacts() { void AddSpecialBoxSearchController::addChatsContacts() {
_chatsContactsAdded = true; _chatsContactsAdded = true;
const auto wordList = TextUtilities::PrepareSearchWords(_query); const auto wordList = TextUtilities::PrepareSearchWords(_query);
if (wordList.empty()) { if (wordList.empty()) {
return; return;

View File

@ -173,6 +173,7 @@ private:
int _offset = 0; int _offset = 0;
bool _participantsLoaded = false; bool _participantsLoaded = false;
bool _chatsContactsAdded = false; bool _chatsContactsAdded = false;
bool _chatMembersAdded = false;
bool _globalLoaded = false; bool _globalLoaded = false;
std::map<QString, CacheEntry> _participantsCache; std::map<QString, CacheEntry> _participantsCache;
std::map<mtpRequestId, Query> _participantsQueries; std::map<mtpRequestId, Query> _participantsQueries;

View File

@ -29,6 +29,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { 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 kParticipantsFirstPageCount = 16;
constexpr auto kParticipantsPerPage = 200; constexpr auto kParticipantsPerPage = 200;
constexpr auto kSortByOnlineDelay = TimeMs(1000); constexpr auto kSortByOnlineDelay = TimeMs(1000);
@ -47,9 +51,35 @@ void RemoveAdmin(
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
channel->session().api().applyUpdates(result); channel->session().api().applyUpdates(result);
channel->applyEditAdmin(user, oldRights, newRights); channel->applyEditAdmin(user, oldRights, newRights);
onDone(); if (onDone) {
onDone();
}
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
onFail(); if (onFail) {
onFail();
}
}).send();
}
void AddChatParticipant(
not_null<ChatData*> chat,
not_null<UserData*> user,
Fn<void()> onDone,
Fn<void()> 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(); }).send();
} }
@ -58,16 +88,28 @@ void SaveChatAdmin(
not_null<UserData*> user, not_null<UserData*> user,
bool isAdmin, bool isAdmin,
Fn<void()> onDone, Fn<void()> onDone,
Fn<void()> onFail) { Fn<void()> onFail,
bool retryOnNotParticipant = true) {
chat->session().api().request(MTPmessages_EditChatAdmin( chat->session().api().request(MTPmessages_EditChatAdmin(
chat->inputChat, chat->inputChat,
user->inputUser, user->inputUser,
MTP_bool(isAdmin) MTP_bool(isAdmin)
)).done([=](const MTPBool &result) { )).done([=](const MTPBool &result) {
chat->applyEditAdmin(user, isAdmin); chat->applyEditAdmin(user, isAdmin);
onDone(); if (onDone) {
onDone();
}
}).fail([=](const RPCError &error) { }).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(); }).send();
} }