MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / add

Method add

Telegram/SourceFiles/api/api_chat_participants.cpp:566–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

564}
565
566void 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();

Callers 3

ApplyMegagroupAdminsFunction · 0.45
RefreshChannelAdminsFunction · 0.45
ApplyLastListFunction · 0.45

Calls 15

ChatInviteForbiddenFunction · 0.85
CollectForbiddenUsersFunction · 0.85
ShowAddParticipantsErrorFunction · 0.85
sendFunction · 0.85
asChatMethod · 0.80
afterDelayMethod · 0.80
inputChatMethod · 0.80
inputUserMethod · 0.80
apiMethod · 0.80
asChannelMethod · 0.80
inputChannelMethod · 0.80
MTP_intFunction · 0.50

Tested by

no test coverage detected