From 5538c5eace0ec5d3ae99f55f567b88ae442c6295 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 1 Feb 2021 22:30:00 +0400 Subject: [PATCH] Add 'Invite via Link' button to Add Members box. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/boxes/boxes.style | 23 ++++++++++ Telegram/SourceFiles/boxes/peer_list_box.cpp | 14 ++++-- Telegram/SourceFiles/boxes/peer_list_box.h | 6 +++ .../boxes/peers/add_participants_box.cpp | 46 +++++++++++++++++++ .../boxes/peers/add_participants_box.h | 2 + .../boxes/peers/edit_peer_type_box.cpp | 15 +++--- .../SourceFiles/boxes/single_choice_box.h | 2 +- .../SourceFiles/calls/calls_group_panel.cpp | 4 ++ 9 files changed, 101 insertions(+), 12 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index eb1d8f846..ba9334a8e 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -827,6 +827,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_profile_delete_contact" = "Delete"; "lng_profile_set_group_photo" = "Set Photo"; "lng_profile_add_participant" = "Add Members"; +"lng_profile_add_via_link" = "Invite via Link"; "lng_profile_view_channel" = "View Channel"; "lng_profile_view_discussion" = "View discussion"; "lng_profile_join_channel" = "Join Channel"; diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 53d827c6c..1c76ebaeb 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -906,6 +906,29 @@ pollResultsShowMore: SettingsButton(defaultSettingsButton) { ripple: defaultRippleAnimation; } +inviteViaLinkButton: SettingsButton(defaultSettingsButton) { + textFg: lightButtonFg; + textFgOver: lightButtonFgOver; + textBg: windowBg; + textBgOver: windowBgOver; + + font: font(14px semibold); + + height: 20px; + padding: margins(74px, 8px, 8px, 9px); + + ripple: defaultRippleAnimation; +} +inviteViaLinkIcon: icon {{ "info/edit/group_manage_links", lightButtonFg }}; +inviteViaLinkIconPosition: point(23px, 2px); +peerListWithInviteViaLink: PeerList(peerListBox) { + padding: margins( + 0px, + 0px, + 0px, + membersMarginBottom); +} + scheduleHeight: 95px; scheduleDateTop: 38px; scheduleDateField: InputField(defaultInputField) { diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 281de0b95..08fd4104c 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -1161,11 +1161,7 @@ void PeerListContent::enterEventHook(QEvent *e) { void PeerListContent::leaveEventHook(QEvent *e) { setMouseTracking(false); - if (_mouseSelection) { - setSelected(Selected()); - _mouseSelection = false; - _lastMousePosition = std::nullopt; - } + mouseLeftGeometry(); } void PeerListContent::mouseMoveEvent(QMouseEvent *e) { @@ -1500,6 +1496,14 @@ void PeerListContent::clearSelection() { setSelected(Selected()); } +void PeerListContent::mouseLeftGeometry() { + if (_mouseSelection) { + setSelected(Selected()); + _mouseSelection = false; + _lastMousePosition = std::nullopt; + } +} + void PeerListContent::loadProfilePhotos() { if (_visibleTop >= _visibleBottom) return; diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 6a2b87786..81069bca3 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -261,6 +261,7 @@ public: virtual void peerListSetAboveWidget(object_ptr aboveWidget) = 0; virtual void peerListSetAboveSearchWidget(object_ptr aboveWidget) = 0; virtual void peerListSetBelowWidget(object_ptr belowWidget) = 0; + virtual void peerListMouseLeftGeometry() = 0; virtual void peerListSetSearchMode(PeerListSearchMode mode) = 0; virtual void peerListAppendRow(std::unique_ptr row) = 0; virtual void peerListAppendSearchRow(std::unique_ptr row) = 0; @@ -541,6 +542,8 @@ public: void setHideEmpty(bool hide); void refreshRows(); + void mouseLeftGeometry(); + void setSearchMode(PeerListSearchMode mode); void changeCheckState( not_null row, @@ -804,6 +807,9 @@ public: void peerListSetSearchMode(PeerListSearchMode mode) override { _content->setSearchMode(mode); } + void peerListMouseLeftGeometry() override { + _content->mouseLeftGeometry(); + } void peerListSortRows( Fn compare) override { _content->reorderRows([&]( diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index 9ac503df3..6a60fe641 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/add_participants_box.h" #include "boxes/peers/edit_participant_box.h" +#include "boxes/peers/edit_peer_type_box.h" #include "boxes/confirm_box.h" #include "lang/lang_keys.h" #include "data/data_channel.h" @@ -18,15 +19,19 @@ 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/widgets/buttons.h" +#include "ui/wrap/padding_wrap.h" #include "base/unixtime.h" #include "main/main_session.h" #include "mtproto/mtproto_config.h" #include "mainwidget.h" #include "mainwindow.h" #include "window/window_session_controller.h" +#include "info/profile/info_profile_icon.h" #include "apiwrap.h" #include "facades.h" // Ui::showPeerHistory #include "app.h" +#include "styles/style_boxes.h" namespace { @@ -68,6 +73,9 @@ AddParticipantsBoxController::AddParticipantsBoxController( : ContactsBoxController(&peer->session()) , _peer(peer) , _alreadyIn(std::move(alreadyIn)) { + if (needsInviteLinkButton()) { + setStyleOverrides(&st::peerListWithInviteViaLink); + } subscribeToMigration(); } @@ -166,6 +174,44 @@ void AddParticipantsBoxController::updateTitle() { ).arg(session().serverConfig().megagroupSizeMax); delegate()->peerListSetTitle(tr::lng_profile_add_participant()); delegate()->peerListSetAdditionalTitle(rpl::single(additional)); + + addInviteLinkButton(); +} + +bool AddParticipantsBoxController::needsInviteLinkButton() { + if (!_peer) { + return false; + } else if (const auto channel = _peer->asChannel()) { + return channel->canHaveInviteLink(); + } + return _peer->asChat()->canHaveInviteLink(); +} + +void AddParticipantsBoxController::addInviteLinkButton() { + if (!needsInviteLinkButton()) { + return; + } + auto button = object_ptr>( + nullptr, + object_ptr( + nullptr, + tr::lng_profile_add_via_link(), + st::inviteViaLinkButton), + style::margins(0, st::membersMarginTop, 0, 0)); + object_ptr( + button->entity(), + st::inviteViaLinkIcon, + st::inviteViaLinkIconPosition); + button->entity()->setClickedCallback([=] { + Ui::show(Box(_peer), Ui::LayerOption::KeepOther); + }); + button->entity()->events( + ) | rpl::filter([=](not_null e) { + return (e->type() == QEvent::Enter); + }) | rpl::start_with_next([=] { + delegate()->peerListMouseLeftGeometry(); + }, button->lifetime()); + delegate()->peerListSetAboveWidget(std::move(button)); } bool AddParticipantsBoxController::inviteSelectedUsers( diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.h b/Telegram/SourceFiles/boxes/peers/add_participants_box.h index 7bba41119..8098134b7 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.h @@ -44,6 +44,7 @@ protected: void prepareViewHook() override; std::unique_ptr createRow( not_null user) override; + virtual bool needsInviteLinkButton(); private: static void Start( @@ -52,6 +53,7 @@ private: base::flat_set> &&alreadyIn, bool justCreated); + void addInviteLinkButton(); bool inviteSelectedUsers(not_null box) const; void subscribeToMigration(); int alreadyInCount() const; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index bc33af502..d587ecbca 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -133,6 +133,8 @@ private: QString inviteLinkText(); not_null _peer; + bool _linkOnly = false; + MTP::Sender _api; std::optional _privacySavedValue; std::optional _usernameSavedValue; @@ -158,6 +160,7 @@ Controller::Controller( std::optional privacySavedValue, std::optional usernameSavedValue) : _peer(peer) +, _linkOnly(!privacySavedValue.has_value()) , _api(&_peer->session().mtp()) , _privacySavedValue(privacySavedValue) , _usernameSavedValue(usernameSavedValue) @@ -174,12 +177,12 @@ void Controller::createContent() { fillPrivaciesButtons(_wrap, _privacySavedValue); // Skip. - if (_privacySavedValue) { + if (!_linkOnly) { _wrap->add(object_ptr(_wrap)); } // _wrap->add(createInviteLinkBlock()); - if (_privacySavedValue) { + if (!_linkOnly) { _wrap->add(createUsernameEdit()); } @@ -198,7 +201,9 @@ void Controller::createContent() { //AddSkip(_wrap.get()); //AddDividerText(_wrap.get(), tr::lng_group_invite_manage_about()); - if (_controls.privacy) { + if (_linkOnly) { + _controls.inviteLinkWrap->show(anim::type::instant); + } else { if (_controls.privacy->value() == Privacy::NoUsername) { checkUsernameAvailability(); } @@ -209,8 +214,6 @@ void Controller::createContent() { _controls.usernameWrap->toggle( (forShowing == Privacy::HasUsername), anim::type::instant); - } else { - _controls.inviteLinkWrap->show(anim::type::instant); } } @@ -248,7 +251,7 @@ void Controller::fillPrivaciesButtons( } Unexpected("Peer type in Controller::createPrivaciesEdit."); }(); - if (!canEditUsername) { + if (!canEditUsername || _linkOnly) { return; } diff --git a/Telegram/SourceFiles/boxes/single_choice_box.h b/Telegram/SourceFiles/boxes/single_choice_box.h index 4964d3b05..b33d13575 100644 --- a/Telegram/SourceFiles/boxes/single_choice_box.h +++ b/Telegram/SourceFiles/boxes/single_choice_box.h @@ -22,7 +22,7 @@ struct SingleChoiceBoxArgs { required> title; const std::vector &options; int initialSelection = 0; - required> callback; + Fn callback; const style::Checkbox *st = nullptr; const style::Radio *radioSt = nullptr; }; diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index 9a752a35d..dae98cb5b 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -99,6 +99,10 @@ private: std::unique_ptr createRow( not_null user) override; + bool needsInviteLinkButton() override { + return false; + } + const not_null>*> _inGroup; rpl::producer> _discoveredInGroup;