From 8b7ea09fa929e88af90f03568bb61bee6a022eb7 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 27 Mar 2022 13:08:47 +0300 Subject: [PATCH] Added initial implementation of detailed mute menu. --- Telegram/CMakeLists.txt | 2 + Telegram/Resources/icons/menu/silent.png | Bin 0 -> 576 bytes Telegram/Resources/icons/menu/silent@2x.png | Bin 0 -> 1007 bytes Telegram/Resources/icons/menu/silent@3x.png | Bin 0 -> 1445 bytes Telegram/Resources/langs/lang.strings | 13 ++ Telegram/SourceFiles/menu/menu_mute.cpp | 125 ++++++++++++++++++++ Telegram/SourceFiles/menu/menu_mute.h | 28 +++++ Telegram/SourceFiles/ui/menu_icons.style | 1 + 8 files changed, 169 insertions(+) create mode 100644 Telegram/Resources/icons/menu/silent.png create mode 100644 Telegram/Resources/icons/menu/silent@2x.png create mode 100644 Telegram/Resources/icons/menu/silent@3x.png create mode 100644 Telegram/SourceFiles/menu/menu_mute.cpp create mode 100644 Telegram/SourceFiles/menu/menu_mute.h 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 0000000000000000000000000000000000000000..16602a7c54b113a23923dd8358c5a05b1076898b GIT binary patch literal 576 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1SIoCSFHz9jKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uv49!D1}S`GTDlgfY?Y^rV~B;| z+YsN?jEN$0*E?=ZSd`&%ib*?ZVL(=v*s1!3Z~idMTq}RDuhrA;Uu#66dt{V?*yR4- zCHHSv-{1MfC~W(?$hpP$p4+@HKKJ`z;s0-sSl*QF);Ya5&VQ21Y>pptvZQ1h6D~~^R{QI-UPesUIc;?w>VXIB&pZ{BDuW2{e?_|m+K0*KM zO$QTp#;E<~ZW7>NDcX4_YpW8&)&4=wg3M46r=8=P3we~N9b(3 zojdz%+lAL(``i|1n5;T%G56f*r$T(~rIBh1YaR8|`g0ddx3CakJ6f2xUE1Y^$MjSt zD`k$EXVZ4y%`=b?$Yl9?S1LI5NNpd-+TP>Ip`pneXPkfjy2NVBR(&Opt0ubh&o6eL zarohng(ae(%TJ#dyl7;xG9+vF-D_EUE1i y5%bx+5g!`rYgMm5-NjSKZ!I|Il9oiak$PKbLh*2~7aCIO%Z! literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/menu/silent@2x.png b/Telegram/Resources/icons/menu/silent@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..6d6dabab1a1cfa70d64533d3d09a94f90b1eca22 GIT binary patch literal 1007 zcmVPx#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91FrWhf1ONa40RR91FaQ7m0NXcg3;+NFSxH1eR9Fe^m`zA3Q545bqYo+S zQ7!C~iUey_3qL5MO^X&$kdO-_hzJUzB7#;?i=d6TZENJpU7J=(no&5AwRaKLdlMaWY zrKKerjb<_#`7!g4U^1C*Z*Tv8Tn`Tq0|Nv3hm$$8r>7^8NDxdc7JGYp!}$LGzOu4X zX5@UPcXV_>4-mY(yi83^A;kFjIKd4K4doM2&K!fm5DJBm9;!HU0q$A4+b+cGt@=5x3~Fr#<;b$mBbhw9c4Vu zW)c8RPft@~J`+a+V_REWmXJoHk$?sV2eY`c9t(irg15$J;?oFZW5v^G3J%0)dU|@| z!!ZdY%bw|-pYibU5EH##Z$m=^2Jv`&WMm`~i7=ySnbr~-ivfgX1bNWjQmGWSzvkxV z)6-L_1*A9-M}q^C*=(Mjodpw$>l>yo@29YfnpyVzy31bnIOtH>kByCeAVgoVrVGSK09}|NJpsWd-DHjLbO;c3MT$0H2&QY4u=VXzF9H8y1FVa zFUF~c4c6Y?es*?7Ot|0N+@Q0wU30Ut`&({v|9hch+3oh;-d>!!PEJm+u75OLbygKn d75ME6`~w+|yyPt+ZS4R6002ovPDHLkV1m^Wsc8TJ literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/menu/silent@3x.png b/Telegram/Resources/icons/menu/silent@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..e4f4f943c2b9fcddf5e35fa4f8b2787adc286f90 GIT binary patch literal 1445 zcmV;W1zP%vP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91NT34%1ONa40RR91NB{r;0FW_8?*IS=4@pEpRA>e5noB5sUlhl^OB4wM z6lH+CisUU(iYP^4fG|*^Oe6+UGGHK5%A-(5o`slrO=P0HiX!qX?>zE;{QuwI@BFOa z`JJ=xxtGp8_nta;a`#+2gC8R_Nab#rs`{QPW$5ftyz-`{^}Y3aYO&+F@JdwaWsgM;FR$U0y_LBZqW z;}_K5@130;H#av~hf=V!yu7@RkB`4J|CWY^h7`0#zM(QRGvD6ch-GeWE-NdmtgP(x z^pu1#F){KDs7OyKDJj??2w-Gn#M=7LMwOVDNbhECBscd$L`1~h-5pWQ&(GW2+Y5|-d3oU~bar+MRA%}!BqZeO>WZka z%R4$cifvUHn4h2D+1VLUt*op#J3EW1AW;*TkB`sM(GgK?Zf;5(Q>p>;^z_`_-6blN zJv=;^bHxeO0fr!OYioANbBqSvC_4T2Cetv#-cJ{=?1hXxuFji7h610JVfn0%ElP$!-N`Bqm z-ga?uVb}YSlzQez9te?X{!t+#BSYLbsNi3!wz07xuA@hS7=qeYR#xh%{Y^C!%*MuM zW@d&46|)JbPywO#H%GRxh>nh?F>tN=c6-SNOfa+%n@;m4p^_X*q%;YbE;iYyFo3DR zm~5-7tMvGYA5qby{1R9(rKS}=Jw2tTr{l)WnSrPvG&GbeBM~IAVe-v3M=;pOu`Mht z@NGq+!9XgsGE*=<&(F$c3WnVRr!cZ3d@2N`!^6Y0Px4jbvN?irR1{KRU9GLHai(Lv z8OUaKU}7q)D{RsHy~IE^@ihLDm}I+`IIkpBYye$S<-rsRsgOmZGqI?sNEiRlkpc!o|e}*SW+gEI7NViP)+?S9-Am65Ji>MvVI(-XZ9^kKtZ} z>1B4p6k^7>EJIgUS7~V})xkv*S>)c{-o?d55{e60Z&g)Q$bvOBH60%xi!11n;28P* z{Gi4Gj$vJOY&A_%JT3XuS;h}&**Uz!B zF>G!UNSsOmF#Seg9*`#t3k%bge#4vC+S*!<2U)uQ{(dAa@C@t4Q$dBCoE-j}%kJ)O z$}}>qS764NEa2(JbP z1_%IonBwAMoB>WwPUGX_B$quEtAuxOWRH%H5(5edDfxeC+1uMw>p!Xx!cR|6^Vz73 z=QA!YP6-DaX$;I;eSJOsV}%1dI5600000NkvXXu0mjf_BD`q literal 0 HcmV?d00001 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 }};