From 0cb8f2cc8502345f5634a037adfe33bd2095c112 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 1 Feb 2021 05:02:50 +0300 Subject: [PATCH] Added ability to toggle silent broadcast from sections. Fixed #8655. --- .../history_view_compose_controls.cpp | 52 ++++++++++++++++--- .../controls/history_view_compose_controls.h | 5 ++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 85da5e24df..b75d559a64 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -50,6 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "ui/controls/emoji_button.h" #include "ui/controls/send_button.h" +#include "ui/special_buttons.h" #include "window/window_session_controller.h" #include "mainwindow.h" @@ -663,6 +664,10 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) { if (!channel->mgInfo->botStatus) { session().api().requestBots(channel); } + } else if (hasSilentBroadcastToggle()) { + _silent = std::make_unique( + _wrap.get(), + peer->asChannel()); } session().local().readDraftsWithCursors(_history); applyDraft(); @@ -1297,6 +1302,17 @@ void ComposeControls::updateFieldPlaceholder() { updateSendButtonType(); } +void ComposeControls::updateSilentBroadcast() { + if (!_silent || !_history) { + return; + } + const auto &peer = _history->peer; + if (!session().data().notifySilentPostsUnknown(peer)) { + _silent->setChecked(session().data().notifySilentPosts(peer)); + updateFieldPlaceholder(); + } +} + void ComposeControls::fieldChanged() { if (!_inlineBot && !_header->isEditingMessage() @@ -1720,14 +1736,15 @@ void ComposeControls::finishAnimating() { void ComposeControls::updateControlsGeometry(QSize size) { // _attachToggle -- _inlineResults ------ _tabbedPanel -- _fieldBarCancel - // (_attachDocument|_attachPhoto) _field _botCommandStart _tabbedSelectorToggle _send + // (_attachDocument|_attachPhoto) _field (_silent|_botCommandStart) _tabbedSelectorToggle _send const auto fieldWidth = size.width() - _attachToggle->width() - st::historySendRight - _send->width() - _tabbedSelectorToggle->width() - - (_botCommandShown ? _botCommandStart->width() : 0); + - (_botCommandShown ? _botCommandStart->width() : 0) + - (_silent ? _silent->width() : 0); { const auto oldFieldHeight = _field->height(); _field->resizeToWidth(fieldWidth); @@ -1758,6 +1775,9 @@ void ComposeControls::updateControlsGeometry(QSize size) { _tabbedSelectorToggle->moveToRight(right, buttonsTop); right += _tabbedSelectorToggle->width(); _botCommandStart->moveToRight(right, buttonsTop); + if (_silent) { + _silent->moveToRight(right, buttonsTop); + } _voiceRecordBar->resizeToWidth(size.width()); _voiceRecordBar->moveToLeft( @@ -2155,12 +2175,20 @@ void ComposeControls::initWebpageProcess() { session().changes().peerUpdates( Data::PeerUpdate::Flag::Rights + | Data::PeerUpdate::Flag::Notifications ) | rpl::filter([=](const Data::PeerUpdate &update) { return (update.peer.get() == peer); - }) | rpl::start_with_next([=] { - checkPreview(); - updateStickersByEmoji(); - updateFieldPlaceholder(); + }) | rpl::map([](const Data::PeerUpdate &update) { + return update.flags; + }) | rpl::start_with_next([=](Data::PeerUpdate::Flags flags) { + if (flags & Data::PeerUpdate::Flag::Rights) { + checkPreview(); + updateStickersByEmoji(); + updateFieldPlaceholder(); + } + if (flags & Data::PeerUpdate::Flag::Notifications) { + updateSilentBroadcast(); + } }, lifetime); base::ObservableViewer( @@ -2263,6 +2291,18 @@ bool ComposeControls::preventsClose(Fn &&continueCallback) const { return false; } +bool ComposeControls::hasSilentBroadcastToggle() const { + if (!_history) { + return false; + } + const auto &peer = _history->peer; + return peer + && peer->isChannel() + && !peer->isMegagroup() + && peer->canWrite() + && !session().data().notifySilentPostsUnknown(peer); +} + void ComposeControls::updateInlineBotQuery() { if (!_history) { return; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h index c107a3f0c0..52d49fc551 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -49,6 +49,7 @@ namespace Ui { class SendButton; class IconButton; class EmojiButton; +class SilentToggle; } // namespace Ui namespace Main { @@ -218,6 +219,7 @@ private: void checkAutocomplete(); void updateStickersByEmoji(); void updateFieldPlaceholder(); + void updateSilentBroadcast(); void editMessage(not_null item); void escape(); @@ -235,6 +237,8 @@ private: void clearInlineBot(); void inlineBotChanged(); + bool hasSilentBroadcastToggle() const; + // Look in the _field for the inline bot and query string. void updateInlineBotQuery(); @@ -279,6 +283,7 @@ private: const not_null _tabbedSelectorToggle; const not_null _field; const not_null _botCommandStart; + std::unique_ptr _silent; std::unique_ptr _inlineResults; std::unique_ptr _tabbedPanel;