| 5109 | } |
| 5110 | |
| 5111 | void ApiWrap::requestBotCommonGroups( |
| 5112 | not_null<UserData*> bot, |
| 5113 | Fn<void()> done) { |
| 5114 | if (_botCommonGroupsRequests.contains(bot)) { |
| 5115 | return; |
| 5116 | } |
| 5117 | _botCommonGroupsRequests.emplace(bot, done); |
| 5118 | const auto finish = [=](std::vector<not_null<PeerData*>> list) { |
| 5119 | _botCommonGroups.emplace(bot, std::move(list)); |
| 5120 | if (const auto callback = _botCommonGroupsRequests.take(bot)) { |
| 5121 | (*callback)(); |
| 5122 | } |
| 5123 | }; |
| 5124 | const auto limit = 100; |
| 5125 | request(MTPmessages_GetCommonChats( |
| 5126 | bot->inputUser(), |
| 5127 | MTP_long(0), // max_id |
| 5128 | MTP_int(limit) |
| 5129 | )).done([=](const MTPmessages_Chats &result) { |
| 5130 | const auto chats = result.match([](const auto &data) { |
| 5131 | return &data.vchats().v; |
| 5132 | }); |
| 5133 | auto &owner = session().data(); |
| 5134 | auto list = std::vector<not_null<PeerData*>>(); |
| 5135 | list.reserve(chats->size()); |
| 5136 | for (const auto &chat : *chats) { |
| 5137 | if (const auto peer = owner.processChat(chat)) { |
| 5138 | list.push_back(peer); |
| 5139 | } |
| 5140 | } |
| 5141 | finish(std::move(list)); |
| 5142 | }).fail([=] { |
| 5143 | finish({}); |
| 5144 | }).send(); |
| 5145 | } |
| 5146 | |
| 5147 | void ApiWrap::saveSelfBio(const QString &text) { |
| 5148 | if (_bio.requestId) { |