diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 3c39adb192..fc2750c1af 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_group_call_bar.h" #include "history/view/history_view_requests_bar.h" #include "history/view/history_view_top_bar_widget.h" +#include "boxes/peers/community_box.h" #include "boxes/peers/community_pending_requests_box.h" #include "boxes/peers/edit_peer_requests_box.h" #include "boxes/choose_filter_box.h" @@ -1304,6 +1305,62 @@ void Widget::updateCommunityRequestsBubble() { }, _communityRequestsLifetime); } +void Widget::updateCommunityAddChatButton() { + _communityAddChatLifetime.destroy(); + _communityAddChatPlaceholder = nullptr; + _communityAddChat = nullptr; + + const auto channel = _openedCommunity + ? _openedCommunity->channel().get() + : nullptr; + if (!channel || !channel->canManageLinkedPeers()) { + return; + } + + auto wrap = object_ptr>( + this, + object_ptr(this)); + const auto entity = wrap->entity(); + const auto row = entity->add( + object_ptr(entity), + st::communityAddChatButtonMargin); + const auto button = MakeCommunityAddChatButton(row, [=] { + ShowChooseChatToAddBox(controller(), channel); + }); + row->resize(row->width(), st::communityAddChatButton.height); + row->widthValue() | rpl::on_next([=](int width) { + button->setFullWidth(width); + button->moveToLeft(0, 0, width); + }, row->lifetime()); + + _communityAddChat.reset(wrap.release()); + const auto raw = _communityAddChat.get(); + + _communityAddChatPlaceholder.reset(_innerList->add( + object_ptr(_innerList))); + const auto placeholder = _communityAddChatPlaceholder.get(); + placeholder->paintOn([placeholder](QPainter &p) { + p.fillRect(placeholder->rect(), st::dialogsBg); + }); + + raw->setParent(_scroll); + raw->raise(); + + const auto pinToBottom = [=] { + const auto height = raw->height(); + placeholder->resize(placeholder->width(), height); + raw->resizeToWidth(_scroll->width()); + raw->moveToLeft(0, std::max(0, _scroll->height() - height)); + }; + _scroll->sizeValue( + ) | rpl::to_empty | rpl::on_next(pinToBottom, _communityAddChatLifetime); + raw->heightValue( + ) | rpl::to_empty | rpl::on_next(pinToBottom, _communityAddChatLifetime); + pinToBottom(); + + raw->toggle(true, anim::type::instant); +} + void Widget::setupMoreChatsBar() { if (_layout == Layout::Child) { return; @@ -2157,6 +2214,7 @@ void Widget::changeOpenedCommunity( updateFrozenAccountBar(); updateTopBarSuggestions(); updateCommunityRequestsBubble(); + updateCommunityAddChatButton(); }, (community != nullptr), animated); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index c6d9d9d2f4..4c6293c8c7 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -235,6 +235,7 @@ private: void setSearchQuery(const QString &query, int cursorPosition = -1); void updateTopBarSuggestions(); void updateCommunityRequestsBubble(); + void updateCommunityAddChatButton(); void updateFrozenAccountBar(); void updateControlsVisibility(bool fast = false); void updateLockUnlockVisibility( @@ -347,6 +348,9 @@ private: base::unique_qptr> _communityRequests; base::unique_qptr _communityRequestsPlaceholder; rpl::lifetime _communityRequestsLifetime; + base::unique_qptr> _communityAddChat; + base::unique_qptr _communityAddChatPlaceholder; + rpl::lifetime _communityAddChatLifetime; rpl::event_stream _searchStateForTopBarSuggestion; rpl::event_stream<> _prepareTopBarSnapshot; rpl::event_stream _openedFolderOrForumChanges;