From 86d1ab00e06eb7ea528115e4c43fd0f30a7a3a59 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Sep 2025 17:22:24 +0400 Subject: [PATCH] Support disabling messages in conferences. --- .../calls/group/calls_group_call.cpp | 8 +++++-- .../calls/group/calls_group_messages.cpp | 2 +- .../calls/group/calls_group_messages_ui.cpp | 19 ++++++++++----- .../calls/group/calls_group_messages_ui.h | 7 ++++-- .../calls/group/calls_group_panel.cpp | 3 ++- .../calls/group/calls_group_settings.cpp | 23 +++++++++++++------ Telegram/SourceFiles/data/data_group_call.cpp | 19 +++++++++++---- 7 files changed, 58 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index b5749d0faa..93bac440cb 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -2314,7 +2314,9 @@ void GroupCall::handlePossibleCreateOrJoinResponse( const auto rtmp = data.is_rtmp_stream(); _rtmp = rtmp; setScheduledDate(scheduleDate); - setMessagesEnabled(data.is_messages_enabled()); + if (!conference()) { + setMessagesEnabled(data.is_messages_enabled()); + } if (const auto chat = _peer->asChat()) { chat->setGroupCall(input, scheduleDate, rtmp); } else if (const auto group = _peer->asChannel()) { @@ -2330,7 +2332,9 @@ void GroupCall::handlePossibleCreateOrJoinResponse( return; } setScheduledDate(data.vschedule_date().value_or_empty()); - setMessagesEnabled(data.is_messages_enabled()); + if (!conference()) { + setMessagesEnabled(data.is_messages_enabled()); + } if (const auto streamDcId = data.vstream_dc_id()) { _broadcastDcId = MTP::BareDcId(streamDcId->v); } diff --git a/Telegram/SourceFiles/calls/group/calls_group_messages.cpp b/Telegram/SourceFiles/calls/group/calls_group_messages.cpp index a73643ebfd..21befa7698 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_messages.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_messages.cpp @@ -65,7 +65,7 @@ void Messages::send(TextWithTags text) { Api::ConvertOption::SkipLocal))); const auto randomId = base::RandomValue(); - const auto from = _call->peer()->session().user(); + const auto from = _call->joinAs(); _messages.push_back({ .randomId = randomId, .peer = from, diff --git a/Telegram/SourceFiles/calls/group/calls_group_messages_ui.cpp b/Telegram/SourceFiles/calls/group/calls_group_messages_ui.cpp index 1d7fa00744..ba42893ba9 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_messages_ui.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_messages_ui.cpp @@ -125,7 +125,8 @@ struct MessagesUi::MessageView { MessagesUi::MessagesUi( not_null parent, std::shared_ptr show, - rpl::producer> messages) + rpl::producer> messages, + rpl::producer shown) : _parent(parent) , _show(std::move(show)) , _messageBg([] { @@ -135,15 +136,21 @@ MessagesUi::MessagesUi( }) , _messageBgRect(CountMessageRadius(), _messageBg.color()) , _fadeHeight(st::normalFont->height) { - setupList(std::move(messages)); + setupList(std::move(messages), std::move(shown)); } MessagesUi::~MessagesUi() = default; -void MessagesUi::setupList(rpl::producer> messages) { - std::move( - messages - ) | rpl::start_with_next([=](std::vector &&list) { +void MessagesUi::setupList( + rpl::producer> messages, + rpl::producer shown) { + rpl::combine( + std::move(messages), + std::move(shown) + ) | rpl::start_with_next([=](std::vector &&list, bool shown) { + if (!shown) { + list.clear(); + } auto from = begin(list); auto till = end(list); for (auto &entry : _views) { diff --git a/Telegram/SourceFiles/calls/group/calls_group_messages_ui.h b/Telegram/SourceFiles/calls/group/calls_group_messages_ui.h index 5d52d4cbe6..18eb86e761 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_messages_ui.h +++ b/Telegram/SourceFiles/calls/group/calls_group_messages_ui.h @@ -38,7 +38,8 @@ public: MessagesUi( not_null parent, std::shared_ptr show, - rpl::producer> messages); + rpl::producer> messages, + rpl::producer shown); ~MessagesUi(); void move(int left, int bottom, int width, int availableHeight); @@ -49,7 +50,9 @@ public: private: struct MessageView; - void setupList(rpl::producer> messages); + void setupList( + rpl::producer> messages, + rpl::producer shown); void toggleMessage(MessageView &entry, bool shown); void setContentFailed(MessageView &entry); void setContent(MessageView &entry, const TextWithEntities &text); diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index 7fbfc53c65..a9487ef838 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -241,7 +241,8 @@ Panel::Panel(not_null call, ConferencePanelMigration info) , _messages(std::make_unique( widget(), uiShow(), - _call->messages()->listValue())) + _call->messages()->listValue(), + _call->messagesEnabledValue())) , _toasts(std::make_unique(this)) , _controlsBackgroundColor([] { auto result = st::groupCallBg->c; diff --git a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp index e0a0fff5f8..31c151549b 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_settings.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_settings.cpp @@ -257,7 +257,9 @@ void SettingsBox( }; const auto peer = call->peer(); const auto state = box->lifetime().make_state(); - const auto real = peer->groupCall(); + const auto real = call->conference() + ? call->lookupReal() + : peer->groupCall(); const auto rtmp = call->rtmp(); const auto id = call->id(); const auto goodReal = (real && real->id() == id); @@ -265,17 +267,19 @@ void SettingsBox( const auto layout = box->verticalLayout(); const auto &settings = Core::App().settings(); - const auto joinMuted = goodReal ? real->joinMuted() : false; - const auto messagesEnabled = goodReal ? real->messagesEnabled() : false; + const auto joinMuted = !call->conference() + && goodReal + && real->joinMuted(); + const auto messagesEnabled = goodReal && real->messagesEnabled(); const auto canChangeJoinMuted = !rtmp && goodReal && real->canChangeJoinMuted(); const auto canChangeMessagesEnabled = !rtmp && goodReal && real->canChangeMessagesEnabled(); - const auto addCheck = peer->canManageGroupCall() && canChangeJoinMuted; - const auto addMessages = peer->canManageGroupCall() - && canChangeMessagesEnabled; + const auto addCheck = canChangeJoinMuted && peer->canManageGroupCall(); + const auto addMessages = canChangeMessagesEnabled + && (call->conference() || peer->canManageGroupCall()); const auto addDivider = [&] { layout->add(object_ptr( @@ -850,7 +854,12 @@ void SettingsBox( if (canChangeMessagesEnabled && enableMessages && enableMessages->toggled() != messagesEnabled) { - SaveCallMessagesEnabled(peer, id, enableMessages->toggled()); + const auto value = enableMessages->toggled(); + if (!call->conference()) { + SaveCallMessagesEnabled(peer, id, value); + } else if (const auto real = call->lookupReal()) { + real->setMessagesEnabledLocally(value); + } } }, box->lifetime()); box->addButton(tr::lng_box_done(), [=] { diff --git a/Telegram/SourceFiles/data/data_group_call.cpp b/Telegram/SourceFiles/data/data_group_call.cpp index 1d50a40dcf..d411ad7c1a 100644 --- a/Telegram/SourceFiles/data/data_group_call.cpp +++ b/Telegram/SourceFiles/data/data_group_call.cpp @@ -501,6 +501,7 @@ void GroupCall::applyCallFields(const MTPDgroupCall &data) { "Set from groupCall %1 -> %2" ).arg(_version ).arg(data.vversion().v)); + const auto initial = !_version; _version = data.vversion().v; if (!_version) { LOG(("API Error: Got zero version in groupCall.")); @@ -509,8 +510,20 @@ void GroupCall::applyCallFields(const MTPDgroupCall &data) { _rtmp = data.is_rtmp_stream(); _creator = data.is_creator(); _listenersHidden = data.is_listeners_hidden(); - _joinMuted = data.is_join_muted(); - _canChangeJoinMuted = data.is_can_change_join_muted(); + if (data.is_conference()) { + _canChangeJoinMuted = false; + _joinMuted = false; + const auto enabled = data.is_messages_enabled(); + _canChangeMessagesEnabled = enabled; + if (!enabled || initial) { + _messagesEnabled = enabled; + } + } else { + _canChangeJoinMuted = data.is_can_change_join_muted(); + _joinMuted = data.is_join_muted(); + _canChangeMessagesEnabled = data.is_can_change_messages_enabled(); + _messagesEnabled = data.is_messages_enabled(); + } _joinedToTop = !data.is_join_date_asc(); setServerParticipantsCount(data.vparticipants_count().v); changePeerEmptyCallFlag(); @@ -522,8 +535,6 @@ void GroupCall::applyCallFields(const MTPDgroupCall &data) { _scheduleDate = data.vschedule_date().value_or_empty(); _scheduleStartSubscribed = data.is_schedule_start_subscribed(); _unmutedVideoLimit = data.vunmuted_video_limit().v; - _messagesEnabled = data.is_messages_enabled(); - _canChangeMessagesEnabled = data.is_can_change_messages_enabled(); _allParticipantsLoaded = (_serverParticipantsCount == _participants.size()); _conferenceInviteLink = qs(data.vinvite_link().value_or_empty());