From b6b7f5706fab7b8a461bc3b3983ce165ed704325 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 5 Jan 2021 19:19:49 +0400 Subject: [PATCH] Show small voice chat button for empty voice chats. --- .../view/history_view_group_call_tracker.cpp | 1 + .../view/history_view_top_bar_widget.cpp | 31 ++++++++++++++++++- .../view/history_view_top_bar_widget.h | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/history/view/history_view_group_call_tracker.cpp b/Telegram/SourceFiles/history/view/history_view_group_call_tracker.cpp index 5297a71ec..038dc3da5 100644 --- a/Telegram/SourceFiles/history/view/history_view_group_call_tracker.cpp +++ b/Telegram/SourceFiles/history/view/history_view_group_call_tracker.cpp @@ -321,6 +321,7 @@ rpl::producer GroupCallTracker::ContentByCall( call->fullCountValue( ) | rpl::start_with_next([=](int count) { state->current.count = count; + state->current.shown = (count > 0); consumer.put_next_copy(state->current); }, lifetime); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 0fec8df2d..a681768bf 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -525,12 +525,36 @@ void TopBarWidget::setActiveChat( _activeChat = activeChat; return; } + const auto peerChanged = (_activeChat.key.history() + != activeChat.key.history()); + _activeChat = activeChat; _sendAction = sendAction; _titlePeerText.clear(); _back->clearState(); update(); + if (peerChanged) { + _activeChatLifetime.destroy(); + if (const auto history = _activeChat.key.history()) { + session().changes().peerFlagsValue( + history->peer, + Data::PeerUpdate::Flag::GroupCall + ) | rpl::map([=] { + return history->peer->groupCall(); + }) | rpl::distinct_until_changed( + ) | rpl::map([](Data::GroupCall *call) { + return call ? call->fullCountValue() : rpl::single(-1); + }) | rpl::flatten_latest( + ) | rpl::map([](int count) { + return (count == 0); + }) | rpl::distinct_until_changed( + ) | rpl::start_with_next([=] { + updateControlsVisibility(); + updateControlsGeometry(); + }, _activeChatLifetime); + } + } updateUnreadBadge(); refreshInfoButton(); if (_menu) { @@ -722,7 +746,12 @@ void TopBarWidget::updateControlsVisibility() { _call->setVisible(historyMode && callsEnabled); const auto groupCallsEnabled = [&] { if (const auto peer = _activeChat.key.peer()) { - return peer->canManageGroupCall(); + if (peer->canManageGroupCall()) { + return true; + } else if (const auto call = peer->groupCall()) { + return (call->fullCount() == 0); + } + return false; } return false; }(); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h index 076c56f0d..0cde0340a 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.h @@ -130,6 +130,7 @@ private: const not_null _controller; ActiveChat _activeChat; QString _customTitleText; + rpl::lifetime _activeChatLifetime; int _selectedCount = 0; bool _canDelete = false;