| 564 | } |
| 565 | |
| 566 | void ChatParticipants::add( |
| 567 | std::shared_ptr<Ui::Show> show, |
| 568 | not_null<PeerData*> peer, |
| 569 | const std::vector<not_null<UserData*>> &users, |
| 570 | bool passGroupHistory, |
| 571 | Fn<void(bool)> done) { |
| 572 | if (const auto chat = peer->asChat()) { |
| 573 | for (const auto &user : users) { |
| 574 | _api.request(MTPmessages_AddChatUser( |
| 575 | chat->inputChat(), |
| 576 | user->inputUser(), |
| 577 | MTP_int(passGroupHistory ? kForwardMessagesOnAdd : 0) |
| 578 | )).done([=](const MTPmessages_InvitedUsers &result) { |
| 579 | const auto &data = result.data(); |
| 580 | chat->session().api().applyUpdates(data.vupdates()); |
| 581 | if (done) done(true); |
| 582 | ChatInviteForbidden( |
| 583 | show, |
| 584 | chat, |
| 585 | CollectForbiddenUsers(&chat->session(), result)); |
| 586 | }).fail([=](const MTP::Error &error) { |
| 587 | const auto type = error.type(); |
| 588 | ShowAddParticipantsError(show, type, peer, user); |
| 589 | if (done) done(false); |
| 590 | }).afterDelay(kSmallDelayMs).send(); |
| 591 | } |
| 592 | } else if (const auto channel = peer->asChannel()) { |
| 593 | const auto hasBot = ranges::any_of(users, &UserData::isBot); |
| 594 | if (!peer->isMegagroup() && hasBot) { |
| 595 | ShowAddParticipantsError( |
| 596 | show, |
| 597 | u"USER_BOT"_q, |
| 598 | peer, |
| 599 | { .users = users }); |
| 600 | return; |
| 601 | } |
| 602 | auto list = QVector<MTPInputUser>(); |
| 603 | list.reserve(std::min(int(users.size()), int(kMaxUsersPerInvite))); |
| 604 | const auto send = [&] { |
| 605 | const auto callback = base::take(done); |
| 606 | _api.request(MTPchannels_InviteToChannel( |
| 607 | channel->inputChannel(), |
| 608 | MTP_vector<MTPInputUser>(list) |
| 609 | )).done([=](const MTPmessages_InvitedUsers &result) { |
| 610 | const auto &data = result.data(); |
| 611 | channel->session().api().applyUpdates(data.vupdates()); |
| 612 | requestCountDelayed(channel); |
| 613 | if (callback) callback(true); |
| 614 | ChatInviteForbidden( |
| 615 | show, |
| 616 | channel, |
| 617 | CollectForbiddenUsers(&channel->session(), result)); |
| 618 | }).fail([=](const MTP::Error &error) { |
| 619 | ShowAddParticipantsError(show, error.type(), peer, { |
| 620 | .users = users, |
| 621 | }); |
| 622 | if (callback) callback(false); |
| 623 | }).afterDelay(kSmallDelayMs).send(); |
no test coverage detected