diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 522ede9e66..c1f448c29e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1299,8 +1299,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_participant_filter" = "Search"; "lng_participant_invite" = "Invite"; +"lng_participant_invite_history" = "Show the last 100 messages"; +"lng_participant_invite_sure" = "Are you sure you want to add **{user}** to **{group}**?"; +"lng_participant_invite_sure_many#one" = "Are you sure you want to add {count} member to **{group}**?"; +"lng_participant_invite_sure_many#other" = "Are you sure you want to add {count} members to **{group}**?"; "lng_participant_invite_sorry#one" = "Sorry, you can only add the first {count} member to a channel personally.\n\nFrom now on, people will need to join via your invite link."; "lng_participant_invite_sorry#other" = "Sorry, you can only add the first {count} members to a channel personally.\n\nFrom now on, people will need to join via your invite link."; + "lng_create_group_back" = "Back"; "lng_create_group_next" = "Next"; "lng_create_group_create" = "Create"; diff --git a/Telegram/SourceFiles/api/api_chat_participants.cpp b/Telegram/SourceFiles/api/api_chat_participants.cpp index c1fbc1797d..1974740835 100644 --- a/Telegram/SourceFiles/api/api_chat_participants.cpp +++ b/Telegram/SourceFiles/api/api_chat_participants.cpp @@ -462,13 +462,14 @@ void ChatParticipants::requestCountDelayed( void ChatParticipants::add( not_null peer, const std::vector> &users, + bool passGroupHistory, Fn done) { if (const auto chat = peer->asChat()) { for (const auto &user : users) { _api.request(MTPmessages_AddChatUser( chat->inputChat, user->inputUser, - MTP_int(kForwardMessagesOnAdd) + MTP_int(passGroupHistory ? kForwardMessagesOnAdd : 0) )).done([=](const MTPUpdates &result) { chat->session().api().applyUpdates(result); if (done) done(true); diff --git a/Telegram/SourceFiles/api/api_chat_participants.h b/Telegram/SourceFiles/api/api_chat_participants.h index 70e5eafa59..644a8bfec9 100644 --- a/Telegram/SourceFiles/api/api_chat_participants.h +++ b/Telegram/SourceFiles/api/api_chat_participants.h @@ -95,6 +95,7 @@ public: void add( not_null peer, const std::vector> &users, + bool passGroupHistory = true, Fn done = nullptr); void requestSelf(not_null channel); diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index c8d39858e9..22be3088f2 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -21,7 +21,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_changes.h" #include "history/history.h" #include "dialogs/dialogs_indexed_list.h" +#include "ui/text/text_utilities.h" // Ui::Text::RichLangValue #include "ui/widgets/buttons.h" +#include "ui/widgets/checkbox.h" #include "ui/wrap/padding_wrap.h" #include "base/unixtime.h" #include "main/main_session.h" @@ -30,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_icon.h" #include "apiwrap.h" #include "styles/style_boxes.h" +#include "styles/style_layers.h" namespace { @@ -223,8 +226,9 @@ void AddParticipantsBoxController::addInviteLinkButton() { delegate()->peerListSetAboveWidget(std::move(button)); } -bool AddParticipantsBoxController::inviteSelectedUsers( - not_null box) const { +void AddParticipantsBoxController::inviteSelectedUsers( + not_null box, + Fn done) const { Expects(_peer != nullptr); const auto rows = box->collectSelectedRows(); @@ -237,10 +241,52 @@ bool AddParticipantsBoxController::inviteSelectedUsers( return not_null(peer->asUser()); }) | ranges::to_vector; if (users.empty()) { - return false; + return; } - _peer->session().api().chatParticipants().add(_peer, users); - return true; + const auto request = [=](bool checked) { + _peer->session().api().chatParticipants().add(_peer, users, checked); + }; + if (_peer->isChannel()) { + request(false); + return done(); + } + Ui::BoxShow(box).showBox(Box([=](not_null box) { + auto checkbox = object_ptr( + box.get(), + tr::lng_participant_invite_history(), + true, + st::defaultBoxCheckbox); + const auto weak = Ui::MakeWeak(checkbox.data()); + + auto text = (users.size() == 1) + ? tr::lng_participant_invite_sure( + tr::now, + lt_user, + { users.front()->name }, + lt_group, + { _peer->name }, + Ui::Text::RichLangValue) + : tr::lng_participant_invite_sure_many( + tr::now, + lt_count, + int(users.size()), + lt_group, + { _peer->name }, + Ui::Text::RichLangValue); + Ui::ConfirmBox(box, { + .text = std::move(text), + .confirmed = crl::guard(weak, [=](Fn &&close) { + request(weak->checked()); + done(); + close(); + }), + .confirmText = tr::lng_participant_invite(), + }); + + auto padding = st::boxPadding; + padding.setTop(padding.bottom()); + box->addRow(std::move(checkbox), std::move(padding)); + })); } void AddParticipantsBoxController::Start( @@ -250,12 +296,12 @@ void AddParticipantsBoxController::Start( const auto weak = controller.get(); auto initBox = [=](not_null box) { box->addButton(tr::lng_participant_invite(), [=] { - if (weak->inviteSelectedUsers(box)) { + weak->inviteSelectedUsers(box, [=] { navigation->parentController()->showPeerHistory( chat, Window::SectionShow::Way::ClearStack, ShowAtTheEndMsgId); - } + }); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; @@ -275,7 +321,7 @@ void AddParticipantsBoxController::Start( const auto weak = controller.get(); auto initBox = [=](not_null box) { box->addButton(tr::lng_participant_invite(), [=] { - if (weak->inviteSelectedUsers(box)) { + weak->inviteSelectedUsers(box, [=] { if (channel->isMegagroup()) { navigation->parentController()->showPeerHistory( channel, @@ -284,7 +330,7 @@ void AddParticipantsBoxController::Start( } else { box->closeBox(); } - } + }); }); box->addButton( justCreated ? tr::lng_create_group_skip() : tr::lng_cancel(), diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index b9939c1414..a1c59c6973 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -59,7 +59,9 @@ private: QPointer showBox(object_ptr box) const; void addInviteLinkButton(); - bool inviteSelectedUsers(not_null box) const; + void inviteSelectedUsers( + not_null box, + Fn done) const; void subscribeToMigration(); int alreadyInCount() const; bool isAlreadyIn(not_null user) const; diff --git a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp index 516d069451..9b02b95545 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_invite_controller.cpp @@ -225,6 +225,7 @@ object_ptr PrepareInviteBox( peer->session().api().chatParticipants().add( peer, nonMembers, + true, [=](bool) { invite(users); finish(); }); }; const auto inviteWithConfirmation = [=](