diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 803808420..0653486a2 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -894,6 +894,8 @@ PRIVATE media/view/media_view_playback_progress.cpp media/view/media_view_playback_progress.h media/view/media_view_open_common.h + menu/menu_mute.cpp + menu/menu_mute.h menu/menu_send.cpp menu/menu_send.h mtproto/config_loader.cpp diff --git a/Telegram/Resources/icons/menu/silent.png b/Telegram/Resources/icons/menu/silent.png new file mode 100644 index 000000000..16602a7c5 Binary files /dev/null and b/Telegram/Resources/icons/menu/silent.png differ diff --git a/Telegram/Resources/icons/menu/silent@2x.png b/Telegram/Resources/icons/menu/silent@2x.png new file mode 100644 index 000000000..6d6dabab1 Binary files /dev/null and b/Telegram/Resources/icons/menu/silent@2x.png differ diff --git a/Telegram/Resources/icons/menu/silent@3x.png b/Telegram/Resources/icons/menu/silent@3x.png new file mode 100644 index 000000000..e4f4f943c Binary files /dev/null and b/Telegram/Resources/icons/menu/silent@3x.png differ diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index efeaaaec2..b67ace8b1 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -892,6 +892,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_change_phone_code_description" = "We've sent an SMS with a confirmation code to your phone {phone}."; "lng_change_phone_success" = "Your phone number has been changed."; +"lng_mute_menu_mute" = "Mute"; +"lng_mute_menu_unmute" = "Unmute"; +"lng_mute_menu_duration_hours#one" = "Mute for {count} hour"; +"lng_mute_menu_duration_hours#other" = "Mute for {count} hours"; +"lng_mute_menu_duration" = "Mute for..."; +"lng_mute_menu_duration_forever" = "Mute forever"; +"lng_mute_menu_duration_unmute" = "Unmute"; +"lng_mute_menu_sound_on" = "Sound On"; +"lng_mute_menu_sound_off" = "Sound Off"; +"lng_mute_box_title" = "Mute notifications for..."; +"lng_mute_box_no_notifications" = "No notifications"; +"lng_mute_box_silent_notifications" = "Silent notifications"; + "lng_mute_duration_hours#one" = "For {count} hour"; "lng_mute_duration_hours#other" = "For {count} hours"; "lng_mute_duration_days#one" = "For {count} day"; diff --git a/Telegram/SourceFiles/menu/menu_mute.cpp b/Telegram/SourceFiles/menu/menu_mute.cpp new file mode 100644 index 000000000..db1b2f73d --- /dev/null +++ b/Telegram/SourceFiles/menu/menu_mute.cpp @@ -0,0 +1,125 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "menu/menu_mute.h" + +#include "data/data_peer.h" +#include "data/data_session.h" +#include "info/profile/info_profile_values.h" +#include "lang/lang_keys.h" +#include "ui/effects/animation_value.h" +#include "ui/widgets/menu/menu_action.h" +#include "ui/widgets/popup_menu.h" +#include "styles/style_menu_icons.h" + +namespace MuteMenu { + +namespace { + +class MuteItem final : public Ui::Menu::Action { +public: + MuteItem( + not_null parent, + const style::Menu &st, + not_null peer); + +protected: + void paintEvent(QPaintEvent *e) override; + +private: + const QPoint _itemIconPosition; + Ui::Animations::Simple _animation; + bool _isMuted = false; + +}; + +MuteItem::MuteItem( + not_null parent, + const style::Menu &st, + not_null peer) +: Ui::Menu::Action( + parent, + st, + Ui::CreateChild(parent.get()), + nullptr, + nullptr) +, _itemIconPosition(st.itemIconPosition) +, _isMuted(peer->owner().notifyIsMuted(peer)) { + + Info::Profile::NotificationsEnabledValue( + peer + ) | rpl::start_with_next([=](bool isUnmuted) { + const auto isMuted = !isUnmuted; + action()->setText(isMuted + ? tr::lng_mute_menu_duration_unmute(tr::now) + : tr::lng_mute_menu_duration_forever(tr::now)); + if (isMuted == _isMuted) { + return; + } + _isMuted = isMuted; + _animation.start( + [=] { update(); }, + isMuted ? 0. : 1., + isMuted ? 1. : 0., + st::defaultPopupMenu.showDuration); + }, lifetime()); + + setClickedCallback([=] { + peer->owner().updateNotifySettings( + peer, + _isMuted ? 0 : Data::NotifySettings::kDefaultMutePeriod); + }); +} + +void MuteItem::paintEvent(QPaintEvent *e) { + Painter p(this); + + const auto progress = _animation.value(_isMuted ? 1. : 0.); + const auto color = anim::color( + st::settingsIconBg1, + st::settingsIconBg2, + progress); + p.setPen(color); + Action::paintText(p); + + const auto &icon = _isMuted ? st::menuIconUnmute : st::menuIconMute; + icon.paint(p, _itemIconPosition, width(), color); +} + +} // namespace + +void FillMuteMenu( + not_null menu, + not_null peer) { + + menu->addAction( + base::make_unique_q(menu, menu->st().menu, peer)); +} + +void SetupMuteMenu( + not_null parent, + rpl::producer<> triggers, + not_null peer) { + struct State { + base::unique_qptr menu; + }; + const auto state = parent->lifetime().make_state(); + std::move( + triggers + ) | rpl::start_with_next([=] { + if (state->menu) { + return; + } + state->menu = base::make_unique_q( + parent, + st::popupMenuWithIcons); + FillMuteMenu(state->menu.get(), peer); + state->menu->popup(QCursor::pos()); + }, parent->lifetime()); +} + +} // namespace MuteMenu diff --git a/Telegram/SourceFiles/menu/menu_mute.h b/Telegram/SourceFiles/menu/menu_mute.h new file mode 100644 index 000000000..e0442e396 --- /dev/null +++ b/Telegram/SourceFiles/menu/menu_mute.h @@ -0,0 +1,28 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class PeerData; + +namespace Ui { +class PopupMenu; +class RpWidget; +} // namespace Ui + +namespace MuteMenu { + +void FillMuteMenu( + not_null menu, + not_null peer); + +void SetupMuteMenu( + not_null parent, + rpl::producer<> triggers, + not_null peer); + +} // namespace MuteMenu diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index 473e2568b..db16b99e7 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -93,6 +93,7 @@ menuIconFake: icon {{ "menu/fake", menuIconColor }}; menuIconPersonal: icon {{ "menu/personal", menuIconColor }}; menuIconPorn: icon {{ "menu/porn", menuIconColor }}; menuIconViolence: icon {{ "menu/violence", menuIconColor }}; +menuIconSilent: icon {{ "menu/silent", menuIconColor }}; mediaMenuIconStickers: icon {{ "menu/stickers", mediaviewMenuFg }}; mediaMenuIconCancel: icon {{ "menu/cancel", mediaviewMenuFg }};