mirror of
https://github.com/vale981/tdesktop
synced 2025-03-06 02:01:40 -05:00
Add user to group on appointing of admin.
This commit is contained in:
parent
9728ddeaf9
commit
4f33be20d4
3 changed files with 54 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -173,6 +173,7 @@ private:
|
|||
int _offset = 0;
|
||||
bool _participantsLoaded = false;
|
||||
bool _chatsContactsAdded = false;
|
||||
bool _chatMembersAdded = false;
|
||||
bool _globalLoaded = false;
|
||||
std::map<QString, CacheEntry> _participantsCache;
|
||||
std::map<mtpRequestId, Query> _participantsQueries;
|
||||
|
|
|
@ -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<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();
|
||||
}
|
||||
|
||||
|
@ -58,16 +88,28 @@ void SaveChatAdmin(
|
|||
not_null<UserData*> user,
|
||||
bool isAdmin,
|
||||
Fn<void()> onDone,
|
||||
Fn<void()> onFail) {
|
||||
Fn<void()> 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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue