mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Support legacy groups in participant boxes.
This commit is contained in:
@@ -3683,119 +3683,6 @@ void ApiWrap::addChatParticipants(
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::cancelEditChatAdmins(not_null<ChatData*> chat) {
|
||||
_chatAdminsEnabledRequests.take(
|
||||
chat
|
||||
) | requestCanceller();
|
||||
|
||||
_chatAdminsSaveRequests.take(
|
||||
chat
|
||||
) | [&](auto &&requests) {
|
||||
ranges::for_each(std::move(requests), requestCanceller());
|
||||
};
|
||||
|
||||
_chatAdminsToSave.remove(chat);
|
||||
}
|
||||
|
||||
void ApiWrap::editChatAdmins(
|
||||
not_null<ChatData*> chat,
|
||||
bool adminsEnabled,
|
||||
base::flat_set<not_null<UserData*>> &&admins) {
|
||||
cancelEditChatAdmins(chat);
|
||||
if (adminsEnabled) {
|
||||
_chatAdminsToSave.emplace(chat, std::move(admins));
|
||||
}
|
||||
|
||||
// #TODO groups
|
||||
//auto requestId = request(MTPmessages_ToggleChatAdmins(chat->inputChat, MTP_bool(adminsEnabled))).done([this, chat](const MTPUpdates &updates) {
|
||||
// _chatAdminsEnabledRequests.remove(chat);
|
||||
// applyUpdates(updates);
|
||||
// saveChatAdmins(chat);
|
||||
//}).fail([this, chat](const RPCError &error) {
|
||||
// _chatAdminsEnabledRequests.remove(chat);
|
||||
// if (error.type() == qstr("CHAT_NOT_MODIFIED")) {
|
||||
// saveChatAdmins(chat);
|
||||
// }
|
||||
//}).send();
|
||||
//_chatAdminsEnabledRequests.emplace(chat, requestId);
|
||||
}
|
||||
|
||||
void ApiWrap::saveChatAdmins(not_null<ChatData*> chat) {
|
||||
if (!_chatAdminsToSave.contains(chat)) {
|
||||
return;
|
||||
}
|
||||
auto requestId = request(MTPmessages_GetFullChat(chat->inputChat)).done([this, chat](const MTPmessages_ChatFull &result) {
|
||||
_chatAdminsEnabledRequests.remove(chat);
|
||||
processFullPeer(chat, result);
|
||||
sendSaveChatAdminsRequests(chat);
|
||||
}).fail([this, chat](const RPCError &error) {
|
||||
_chatAdminsEnabledRequests.remove(chat);
|
||||
_chatAdminsToSave.remove(chat);
|
||||
}).send();
|
||||
_chatAdminsEnabledRequests.emplace(chat, requestId);
|
||||
}
|
||||
|
||||
void ApiWrap::sendSaveChatAdminsRequests(not_null<ChatData*> chat) {
|
||||
auto editOne = [this, chat](not_null<UserData*> user, bool admin) {
|
||||
auto requestId = request(MTPmessages_EditChatAdmin(
|
||||
chat->inputChat,
|
||||
user->inputUser,
|
||||
MTP_bool(admin)))
|
||||
.done([this, chat, user, admin](
|
||||
const MTPBool &result,
|
||||
mtpRequestId requestId) {
|
||||
_chatAdminsSaveRequests[chat].remove(requestId);
|
||||
if (_chatAdminsSaveRequests[chat].empty()) {
|
||||
_chatAdminsSaveRequests.remove(chat);
|
||||
Notify::peerUpdatedDelayed(chat, Notify::PeerUpdate::Flag::AdminsChanged);
|
||||
}
|
||||
if (mtpIsTrue(result)) {
|
||||
if (admin) {
|
||||
if (chat->noParticipantInfo()) {
|
||||
requestFullPeer(chat);
|
||||
} else {
|
||||
chat->admins.insert(user);
|
||||
}
|
||||
} else {
|
||||
chat->admins.remove(user);
|
||||
}
|
||||
}
|
||||
}).fail([this, chat](
|
||||
const RPCError &error,
|
||||
mtpRequestId requestId) {
|
||||
_chatAdminsSaveRequests[chat].remove(requestId);
|
||||
if (_chatAdminsSaveRequests[chat].empty()) {
|
||||
_chatAdminsSaveRequests.remove(chat);
|
||||
}
|
||||
chat->invalidateParticipants();
|
||||
if (error.type() == qstr("USER_RESTRICTED")) {
|
||||
Ui::show(Box<InformBox>(lang(lng_cant_do_this)));
|
||||
}
|
||||
}).afterDelay(kSmallDelayMs).send();
|
||||
|
||||
_chatAdminsSaveRequests[chat].insert(requestId);
|
||||
};
|
||||
auto appointOne = [&](auto user) { editOne(user, true); };
|
||||
auto removeOne = [&](auto user) { editOne(user, false); };
|
||||
|
||||
auto admins = _chatAdminsToSave.take(chat);
|
||||
Assert(!!admins);
|
||||
|
||||
auto toRemove = chat->admins;
|
||||
auto toAppoint = std::vector<not_null<UserData*>>();
|
||||
if (!admins->empty()) {
|
||||
toAppoint.reserve(admins->size());
|
||||
for (auto user : *admins) {
|
||||
if (!toRemove.remove(user) && user->id != peerFromUser(chat->creator)) {
|
||||
toAppoint.push_back(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
ranges::for_each(toRemove, removeOne);
|
||||
ranges::for_each(toAppoint, appointOne);
|
||||
requestSendDelayed();
|
||||
}
|
||||
|
||||
void ApiWrap::requestSharedMediaCount(
|
||||
not_null<PeerData*> peer,
|
||||
Storage::SharedMediaType type) {
|
||||
|
Reference in New Issue
Block a user