From f97064ed373f779900c517ac6578b728cc5ad549 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 11 Feb 2021 11:25:43 +0400 Subject: [PATCH] Add auto-delete control to compose controls. --- Telegram/CMakeLists.txt | 2 + .../icons/chat/send_control_autodelete_1d.png | Bin 0 -> 1029 bytes .../chat/send_control_autodelete_1d@2x.png | Bin 0 -> 2082 bytes .../chat/send_control_autodelete_1d@3x.png | Bin 0 -> 3088 bytes .../icons/chat/send_control_autodelete_7d.png | Bin 0 -> 1039 bytes .../chat/send_control_autodelete_7d@2x.png | Bin 0 -> 2171 bytes .../chat/send_control_autodelete_7d@3x.png | Bin 0 -> 3306 bytes Telegram/Resources/langs/lang.strings | 3 + Telegram/SourceFiles/data/data_changes.h | 117 +++++++++--------- Telegram/SourceFiles/data/data_peer.cpp | 13 +- .../SourceFiles/history/history_widget.cpp | 58 ++++++--- Telegram/SourceFiles/history/history_widget.h | 3 + .../history_view_compose_controls.cpp | 51 ++++++-- .../controls/history_view_compose_controls.h | 3 + .../view/controls/history_view_ttl_button.cpp | 94 ++++++++++++++ .../view/controls/history_view_ttl_button.h | 29 +++++ Telegram/SourceFiles/ui/chat/chat.style | 7 ++ 17 files changed, 293 insertions(+), 87 deletions(-) create mode 100644 Telegram/Resources/icons/chat/send_control_autodelete_1d.png create mode 100644 Telegram/Resources/icons/chat/send_control_autodelete_1d@2x.png create mode 100644 Telegram/Resources/icons/chat/send_control_autodelete_1d@3x.png create mode 100644 Telegram/Resources/icons/chat/send_control_autodelete_7d.png create mode 100644 Telegram/Resources/icons/chat/send_control_autodelete_7d@2x.png create mode 100644 Telegram/Resources/icons/chat/send_control_autodelete_7d@3x.png create mode 100644 Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp create mode 100644 Telegram/SourceFiles/history/view/controls/history_view_ttl_button.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index aef5cce01..235e68261 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -497,6 +497,8 @@ PRIVATE history/view/controls/compose_controls_common.h history/view/controls/history_view_compose_controls.cpp history/view/controls/history_view_compose_controls.h + history/view/controls/history_view_ttl_button.cpp + history/view/controls/history_view_ttl_button.h history/view/controls/history_view_voice_record_bar.cpp history/view/controls/history_view_voice_record_bar.h history/view/controls/history_view_voice_record_button.cpp diff --git a/Telegram/Resources/icons/chat/send_control_autodelete_1d.png b/Telegram/Resources/icons/chat/send_control_autodelete_1d.png new file mode 100644 index 0000000000000000000000000000000000000000..82a7179ea756c2a4f7f931def662a0082080a33b GIT binary patch literal 1029 zcmV+g1p51lP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91B%lKT1ONa40RR91Bme*a04fgS`~Uz0Z%IT!R9Fe^R?91OQ50YI`s6KU zB$AXz85u}X42`7Blz|MS2os4ZBL*T9kCc)D@dqdwP!clpP9C{~>oM_utZ%K=cTVTr zZ|`&OCPm#-XP>>-`mMEpXRWm#J^(;^f6U|mF--mui4qEzk!XZ|U4;IGW31Dsq@+Mw zTN~Wo-on(>6g)pa>!8MR-iM6e@$qrAp1r+2tg5Oq_Mw^AoD4hK-Q5*F7Z(>6FQiCe ze0=;@iG7YxFc=gf85tSa)6;_w4-Yb4US7t;#Kf0gR>r+nH z)zu~X?d@%)UO~c%^CmPhG9u2GmXl>Lawjzb{UUi;GR2qTlbwv$Hci zJUleD)f2k8xe-EikeWIbJl9}aTAK7@Vq%a>pscJcoG(40>+5SF#K(go*DhIpem-)& zEG#UzL)nt4zMeNm+DFI+prWEezPg5%Hf(HcKzVsN(7vUFeSCZ<<)K1P zLbUe?o;E=6`Fx?aGNxLA(a}*@TwDaI7Z--22Ai9kaCdhHLqkJAXP-;28)!oq8yky! zUh&h}*{Q`@b#iocghar`5m9`7eZ}71UYwbki6~`E(srQg^JYllmbbmV9Vt>;Jd<}4 zIyg8$N~PdaQ&Z(U{89}uTTVqwOAB{lcz76gc6OktsR>F-N`O|5$aM`}Q{d_8Nz{DB zrD*A(F1hxP31#c*>+A945U4S4D3J*q4WWxP7+N(=Y* z_YqlsJE4eJI6x7n%whAb-6)}O;f+QpT!j7tuT<>(@j*7<00000NkvXXu0mjf@|f3K literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/chat/send_control_autodelete_1d@2x.png b/Telegram/Resources/icons/chat/send_control_autodelete_1d@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..7b18d0760a4c5783ed1242bba76d43a829b5db36 GIT binary patch literal 2082 zcma)7dpy(M8~@BLG?!kaMkFPd5JNIyF0o}6O>zlS#$1zfX`wMCEAmA`LX^;qjEF)t zS?=VLJKqU&NvOHSejoq*e*gadc%SDv=XsykIj{3P@AD+sVXehPWkmr15JRIZFMt-c z3t=H}ytv4)1`XuK1#5GF-f@TnPAmydXm49vKppgj0Z6aD@Gpz1h?69n;vywk++u@1o+2LT(GcWMhM*|q!atBq$tLh z<;{qNB4q{i+Pwu~WIbVGR=cQrC!kO4LOPTyH#MDYApH@w zN;>46gFGjbck#93JLGc7_xdQKUbHK#+vm&P=IjyH79-G>VbkqT_joi!69Sp<@9-3apa+wSk|OwfHx3q@ z@`^LLF%9MSoM?;*QMjxb{G(-mKep}BVN?9?+3t$m&t%Mi%HCuta>p|xU49*{SbhKg z8f1R;W!}!V^LQNjoOm9Mrm_B;Bc)sK{(+QZbw1ZbK6-nzX)}8L7i491)p*NCk~RhS zb>|D}uK#F#qLwJH>-})=3)ku(v%ZpxxTFU#S_H&zutGW6!*{5%xb^-Ki+kGSjvV9p zIksNVP^E7GR7YC<^cErc(H=!oWPhov%F_DMcta^GV=nN=0ZkX?!_jh2N&sUk!mT*h z1r^p1z1<@_uY3~kb_QtA)U~cM>#=#F_4r;F)xI@OM9Rxm{pIURW#ZvKN9^N2eYm}* zsG_1$x?Jq_s#``r4-q=oI9z=#6LQL;Y*t(z0l?7Ll&T_(??sD-FAnXG-uYWB9>2_P z<{1GlZv$Ysk*|15sGy)AZ4-Rsm_*mQFwNBKTiifaM~ApZ^V0G4UTasgN{`L;<)gU2 z>&xtiD$}EN;k2MXbA2&l{{1vqqLN)J1byg|?i%W`qJ`Xqrz#z%Y=m9V=jx_{y$We;X@V|B(g)y{o}^X(O_ z-J93!XF| zujgh64+I0eHDcrgA<#oUXu_Mp^hsZ*dnNz$gXeTxCf{0MiiG);0Efm6MNDn}ncw>`yHD$%Sv6eYeeggR zI5zwA5$%Drx9_R@Pf)>}wC>b+q}{Yr(nEr3l8MOCnrUrqeITgl@_2rr>_A3Ka>Zd| z(lO49gf6VCloRF>rcl=eN~sII{&U1o2z$`*dXk8koxT0OZ~UF#V29Jd#6GHt+^CrC zEl$Qdg2INaT&nC?E7DJggKNdzO${D0zJ^u`$eD*eE z>WulPW+~#O^CJ2_KkM26r2?>?j*1%BQOt{mvcmJf=C!VNw)uTi#v12`>47 z^booL?)cH#+|D8JKuCu4X83%6JH3TwK1qk%`*HOB8W zQvJ2{<&5mqf6aA_ImRNX1x!9kwTj4%kT(&_SDs*vNxvm$gPTBo3VKVIiX9hxTn7A}xG>L%#v<^BmG^(wLf1Q=Zo^>p&ki3}MO;qAp<6 z@UG%f0ww9H*sSD~Sav=KwE>E>B&q&)x##CIGXoGyc5le!C&3J(aII{UDA`%IP*s`{ zIUvs{Y=J1RNQ$~ml$%)FelD)qawpgH&X~++I@nLH_=NnBQIu1q+G}qECmdVvY#q-JvMkq@%i8jFDJ2d-^M{()XK?gQ@hu uq362PqDEdmlbgjW%O?OmBhLSCv*Q8d8PzWZD5i&Y`!o71){<_HkNpn@yw_*| literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/chat/send_control_autodelete_1d@3x.png b/Telegram/Resources/icons/chat/send_control_autodelete_1d@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..95b78d7a785597d65b00ba8f3fda684d23800f47 GIT binary patch literal 3088 zcmbtW`9Bl>AD`Qti%m#$yIHbaE7#1#*swD6U{Ta}z*Sx7=4ei>=ybGf(F0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RCPNM&9gEw^_+D-3J7?)3cFBB0*}3{y+hUZ`;5)xT6x>hN zuwecB#1tdWtz}xny*z3ANbKRa-`x-RMP-K^JA?MS=W$OY)@ReWzrV6C&)^%~a{C9rzTE_#81{WkIiQ;SfRVHJ#DT<^)L+ zD0WsqK&ntfDhWBnnMb#F^W@=FjI>x01y>8Z^k%<+pT=?7T19tL)aH1fEBvnp1`(Z z%T&&Qu8t8tJTjwu4|r$TOaERtTs@{kQ|$IyV!#gM2gi+QXp4Y|kB&j=Fe(*F<_Dar{KGY|IS? zpk)V{ZxE)z3=j*QAjL-~xSuD3CjK1C5>AGaLGB2>fC+dHg<0kHY^qHzmMPM0b`Gi& z(VBBeP(b9?Ft$P<_!-)J3#@F{ypX*sr-X6NTxYc%`Q(f2TVPhav0wHO!fpz07o}DChX3*)Pr?qo>}KEe^iUY$@ru!H5;z+gWGPRh4lP zQad^#D1x4DbK6>oVD}(Gr}DkTzGVAODv}C*2J@4;dg{JQ(GhL`LQ_A{6NHqy_xv_qtR*hkTKZyAaKbkJJISTPgK1xzbidD6LNH$4$b}Q7k)fpQ4WP7B-zI zanyyej5=9E_-^9aC`OH8n?V^!X$*+hIEL)gBt>JI0-@^b%NN1ALO&VE=c~zW4=5 VNy^?fq4)1LZeeDPs50?<{9j%a#PI+C literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/chat/send_control_autodelete_7d.png b/Telegram/Resources/icons/chat/send_control_autodelete_7d.png new file mode 100644 index 0000000000000000000000000000000000000000..2f3a867fa9e8ce8a45b9e055928c7d32eb546fe6 GIT binary patch literal 1039 zcmV+q1n~QbP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91B%lKT1ONa40RR91Bme*a04fgS`~Uz0c}YY;R9Fe^mR~5lQ5eV1<|p!} zNEZ2%+|1N2+5yBK#XDRQ}7SSgVUlJX~oxRHgWA(V_(G~xN3 z=gHpe^`3V-l&GD0-12^egiTLRvsf%9GL`PfJS6>0PEJC+9335j&1RF<5UeW?gF*)f2gGx6aS`VN z?kUL5&i*dg*MM$sZwaKNqy&bBhT!q>k=o14%aD_k^BpL8AoK#3r>7@nVT;8Aac`}y ztwC;Xt}-SFjc7bIpwiM($jZthk?QJd0y;fCO%TQYv$HcAo0^(R7?XfX4%FY@53jGU zaDILcRaI5c*49RgVtCXGp{L^EYiViuG_JPSXzK%2R#w9E^D_b9Yjt%M#>dC0Jv=v#qKt7+3#OLPb;QIQS>Mt)Z^jlwF|4~S(V`wigFUjT$=|Bur zSXf9K7sFLkQv>bo?X(EKc6WCb0Ie?`85tqlv9U2-JB_(wpw7-t68*SW1_uXWV`BrF znwoSMYHn_(xtp7tx^_}PGcz+J+S}VJD+*<0WiPmL5*h9f!kVI>1Yh^{jXf#4N z9ERiLW7)Z4pu4*}0^$d$tSH&z9xNy*keaJ|LE|($#EkK*OTT)r*49>bczDP>9*<&% zH-Y>6d!?O9MHh(Y5z=UEY}D1_iIdIG&oiDBS#fc(u5BuVLYF!m4hq@+{yrEC22DH6 z+z$^AfJqX|=;$b&_;{>%yXp`ueCnF)=~61%ak`4`pU%0t#bsxm=n+{EKOy zl$V#29RgwB%E}6yoSaa7XJ-dOp%5%BEzxGjn}Xl(7wL(CP#BZp+uIvG_=SS6f{KcY z1fYR|0czLP)zLXBR2Pzl4=)zt-7s}(XbG88*C z5N38P7@nJ(8@eOmnTR({JbH?Xij=u3sN_I6p`)XN+)k^!zcA0_<>isE8VKiLm=Goq z2$0S8_BLR+*4NiXFrfP{b9xX4T<6XO6h zw6(RxxM$eH!h+gVX&ZP=tf-j%TqR`>{S;CfD4D0z9{O`0`VU}|D_OgZlS%*p002ov JPDHLkV1iEJ(!~G( literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/chat/send_control_autodelete_7d@2x.png b/Telegram/Resources/icons/chat/send_control_autodelete_7d@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..1837649262ef17b5240eb15e04d8c63f36e73b0e GIT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;P>oA-plNYKUpYsC2e}e?rGIWrFqEu1 z{Ed!JM4^6k!N}e@fRA8=5qjgf5;mRD3up#RX3>l?Rmy)_r2Ai&)V>3ExVt%LDD_0g z7S1A<%0(CAB7>~cRJNF|e8>2il_cRbX~G5j$~6h)gjI!82NU?k@XRlKL|^J(eNWm_ z{;pa>`*>a;{2}2Yr9jiaC-ILWdiT!yRClRyQsJ4RUC&G@6ZEt50vG)>xFxk!agw%q z*-VQ*joMku|A+Ia97hiE#)T3LMH;~i9TTNoy@e5so334;kTO~7^(}25eukY0{ACnv zw8A_X0ZFnA?|Z3?zh>=eU}3!eZBZ>fKn7$OD}L*JK&r+QR*td#J%`>u(M8H zY6LpMGL~fopgBq|iBEVjRtlBKrzS`(f|Cu zSm)l5MPff&?jy*ieuwnC1Y}ZdYXk#B0Cp0=T}ln8BAD1QmFaC#nv_nWP23U#3~8>R zx{^PHhlF~m-(5fuVvZs>WNw?_e>8Y>N{Yw6gWs8&Gh4pYW!?bKExzO@phL=Zuo*6t zy(b5e(_` zI|OI2hwJt>M*Fj8`A`5;bLLALhZX9dkaD1bvFur)RB|Y zL}ctAC@wM0;@^EJYn;eULc<_%s#5J_czL0^eX9^!_dDNK4J-zmg`3!%r^-!D8M8Sz z?Isxl;<{lC0`pNe9HHczz~)bqDn<TT3pR#oKR2@P8)d{~e`J;0O%J Vk;43OMW0Uwzl8}3QD<~B?qAOi3ON7( literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/chat/send_control_autodelete_7d@3x.png b/Telegram/Resources/icons/chat/send_control_autodelete_7d@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..0c54ebc5f3624f84e24656ee174462ba3f2b5171 GIT binary patch literal 3306 zcmb_fS6I_cv;QZQ&_WRcp?5+F9Rv}O66yU#igcwKqzbP<6p+w+7ZC_mktzzxCnbQi zAYB3JRq0Jy5aEkA=iHpjb1^%!v-9lkGduJ9JsWRkq6?+rpaB2?s;`H#AZhQvLPbd$ zQ{AlxNeUEbp{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!)irB;eJ6=LHf|kd$Fb~pkf?&Ns47M|0iJtJ%WOM=(Fs?}PziPT zj6AC`ZPy%5rUlWhsdD#pXE+sc7Wb^EXBU4Le$|5)QIGkg?bjxv;+6dK=Zf6r==#pg zha75IC*Hzv(?KyJwZgEeG3@M7-2oP$i`HRNRybZnaUcrdvBt|xMUX+QhL$4HDhSQ} zJ$fi;XRbuEx1G>n+LQd=v({pEwuA{g9K{N`aKYz5&<=FEPPY?SMq>wV1gwrIQFJ=} zlm2ucV>{Y&aPxZ5rloFhT?A3_r4o6^Tf|API2J`lJuV!Ba*9l>1ZcUyzF<*&%Z7xX z4~5Ml<6~wG&<|s$$Uq4^I2NA|(8&0n)4a3;u_}|#lbc0^j9V|x($wSm_eCPWU-H|) zKdmAt=p&UtEY9;sFy#+mq#soaH4gYyQHO7aIY(+Q8Uqy1m7Y)x)%+hvE#7+V6wWB{ TVZG|_KSTev3944h`PqK~No)L> literal 0 HcmV?d00001 diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 7fdf695e1..7af4eeaf7 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -982,6 +982,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_manage_messages_ttl_after2" = "After 7 days"; "lng_manage_messages_ttl_about" = "Turning on this setting will make auto-delete messages from this group after the selected period."; "lng_manage_messages_ttl_about_channel" = "Turning on this setting will make auto-delete messages from this channel after the selected period."; +"lng_ttl_about_tooltip" = "Messages in this chat will auto-delete in {duration}."; +"lng_ttl_about_duration1" = "24 hours"; +"lng_ttl_about_duration2" = "7 days"; "lng_report_title" = "Report channel"; "lng_report_group_title" = "Report group"; diff --git a/Telegram/SourceFiles/data/data_changes.h b/Telegram/SourceFiles/data/data_changes.h index 0a162906f..bede05e23 100644 --- a/Telegram/SourceFiles/data/data_changes.h +++ b/Telegram/SourceFiles/data/data_changes.h @@ -50,46 +50,47 @@ struct PeerUpdate { None = 0, // Common flags - Name = (1 << 0), - Username = (1 << 1), - Photo = (1 << 2), - About = (1 << 3), - Notifications = (1 << 4), - Migration = (1 << 5), - UnavailableReason = (1 << 6), - PinnedMessages = (1 << 7), - IsBlocked = (1 << 8), + Name = (1U << 0), + Username = (1U << 1), + Photo = (1U << 2), + About = (1U << 3), + Notifications = (1U << 4), + Migration = (1U << 5), + UnavailableReason = (1U << 6), + PinnedMessages = (1U << 7), + IsBlocked = (1U << 8), + MessagesTTL = (1U << 9), // For users - CanShareContact = (1 << 9), - IsContact = (1 << 10), - PhoneNumber = (1 << 11), - OnlineStatus = (1 << 12), - BotCommands = (1 << 13), - BotCanBeInvited = (1 << 14), - BotStartToken = (1 << 15), - CommonChats = (1 << 16), - HasCalls = (1 << 17), - SupportInfo = (1 << 18), - IsBot = (1 << 19), + CanShareContact = (1U << 10), + IsContact = (1U << 11), + PhoneNumber = (1U << 12), + OnlineStatus = (1U << 13), + BotCommands = (1U << 14), + BotCanBeInvited = (1U << 15), + BotStartToken = (1U << 16), + CommonChats = (1U << 17), + HasCalls = (1U << 18), + SupportInfo = (1U << 19), + IsBot = (1U << 20), // For chats and channels - InviteLinks = (1 << 20), - Members = (1 << 21), - Admins = (1 << 22), - BannedUsers = (1 << 23), - Rights = (1 << 24), + InviteLinks = (1U << 21), + Members = (1U << 22), + Admins = (1U << 23), + BannedUsers = (1U << 24), + Rights = (1U << 25), // For channels - ChannelAmIn = (1 << 25), - StickersSet = (1 << 26), - ChannelLinkedChat = (1 << 27), - ChannelLocation = (1 << 28), - Slowmode = (1 << 29), - GroupCall = (1 << 30), + ChannelAmIn = (1U << 26), + StickersSet = (1U << 27), + ChannelLinkedChat = (1U << 28), + ChannelLocation = (1U << 29), + Slowmode = (1U << 30), + GroupCall = (1U << 31), // For iteration - LastUsedBit = (1 << 30), + LastUsedBit = (1U << 31), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } @@ -103,22 +104,22 @@ struct HistoryUpdate { enum class Flag : uint32 { None = 0, - IsPinned = (1 << 0), - UnreadView = (1 << 1), - TopPromoted = (1 << 2), - Folder = (1 << 3), - UnreadMentions = (1 << 4), - LocalMessages = (1 << 5), - ChatOccupied = (1 << 6), - MessageSent = (1 << 7), - ScheduledSent = (1 << 8), - ForwardDraft = (1 << 9), - OutboxRead = (1 << 10), - BotKeyboard = (1 << 11), - CloudDraft = (1 << 12), - LocalDraftSet = (1 << 13), + IsPinned = (1U << 0), + UnreadView = (1U << 1), + TopPromoted = (1U << 2), + Folder = (1U << 3), + UnreadMentions = (1U << 4), + LocalMessages = (1U << 5), + ChatOccupied = (1U << 6), + MessageSent = (1U << 7), + ScheduledSent = (1U << 8), + ForwardDraft = (1U << 9), + OutboxRead = (1U << 10), + BotKeyboard = (1U << 11), + CloudDraft = (1U << 12), + LocalDraftSet = (1U << 13), - LastUsedBit = (1 << 13), + LastUsedBit = (1U << 13), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } @@ -132,16 +133,16 @@ struct MessageUpdate { enum class Flag : uint32 { None = 0, - Edited = (1 << 0), - Destroyed = (1 << 1), - DialogRowRepaint = (1 << 2), - DialogRowRefresh = (1 << 3), - NewAdded = (1 << 4), - ReplyMarkup = (1 << 5), - BotCallbackSent = (1 << 6), - NewMaybeAdded = (1 << 7), + Edited = (1U << 0), + Destroyed = (1U << 1), + DialogRowRepaint = (1U << 2), + DialogRowRefresh = (1U << 3), + NewAdded = (1U << 4), + ReplyMarkup = (1U << 5), + BotCallbackSent = (1U << 6), + NewMaybeAdded = (1U << 7), - LastUsedBit = (1 << 7), + LastUsedBit = (1U << 7), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } @@ -155,9 +156,9 @@ struct EntryUpdate { enum class Flag : uint32 { None = 0, - Repaint = (1 << 0), + Repaint = (1U << 0), - LastUsedBit = (1 << 0), + LastUsedBit = (1U << 0), }; using Flags = base::flags; friend inline constexpr auto is_flag_type(Flag) { return true; } diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 52c2c750f..8d3448043 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -955,9 +955,16 @@ void PeerData::setMessagesTTL( TimeId myPeriod, TimeId peerPeriod, bool oneSide) { - _ttlMyPeriod = myPeriod; - _ttlPeerPeriod = peerPeriod; - _ttlOneSide = oneSide; + if (_ttlMyPeriod != myPeriod + || _ttlPeerPeriod != peerPeriod + || _ttlOneSide != oneSide) { + _ttlMyPeriod = myPeriod; + _ttlPeerPeriod = peerPeriod; + _ttlOneSide = oneSide; + session().changes().peerUpdated( + this, + Data::PeerUpdate::Flag::MessagesTTL); + } } void PeerData::applyMessagesTTL(const MTPPeerHistoryTTL &ttl) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 1da6e2c10..c44b67773 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -65,6 +65,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_components.h" //#include "history/feed/history_feed_section.h" // #feed #include "history/view/controls/history_view_voice_record_bar.h" +#include "history/view/controls/history_view_ttl_button.h" #include "history/view/history_view_service_message.h" #include "history/view/history_view_element.h" #include "history/view/history_view_scheduled_section.h" @@ -589,6 +590,7 @@ HistoryWidget::HistoryWidget( | UpdateFlag::Slowmode | UpdateFlag::BotStartToken | UpdateFlag::PinnedMessages + | UpdateFlag::MessagesTTL ) | rpl::filter([=](const Data::PeerUpdate &update) { if (_migrated && update.peer.get() == _migrated->peer) { if (_pinnedTracker @@ -638,6 +640,9 @@ HistoryWidget::HistoryWidget( if (_pinnedTracker && (flags & UpdateFlag::PinnedMessages)) { checkPinnedBarState(); } + if (flags & UpdateFlag::MessagesTTL) { + checkMessagesTTL(); + } }, lifetime()); rpl::merge( @@ -1267,6 +1272,7 @@ void HistoryWidget::applyInlineBotQuery(UserData *bot, const QString &query) { } void HistoryWidget::orderWidgets() { + _voiceRecordBar->raise(); _send->raise(); if (_contactStatus) { _contactStatus->raise(); @@ -1942,6 +1948,7 @@ void HistoryWidget::showHistory( setupPinnedTracker(); setupGroupCallTracker(); + checkMessagesTTL(); if (_history->scrollTopItem || (_migrated && _migrated->scrollTopItem) || _history->isReadyFor(_showAtMsgId)) { @@ -1995,6 +2002,7 @@ void HistoryWidget::showHistory( } else { refreshTopBarActiveChat(); updateTopBarSelection(); + checkMessagesTTL(); clearFieldText(); doneShow(); @@ -2206,6 +2214,9 @@ void HistoryWidget::updateControlsVisibility() { if (_scheduled) { _scheduled->hide(); } + if (_ttlInfo) { + _ttlInfo->hide(); + } _kbScroll->hide(); _fieldBarCancel->hide(); _attachToggle->hide(); @@ -2268,6 +2279,9 @@ void HistoryWidget::updateControlsVisibility() { if (_scheduled) { _scheduled->show(); } + if (_ttlInfo) { + _ttlInfo->show(); + } updateFieldPlaceholder(); if (_editMsgId || _replyToId || readyToForward() || (_previewData && _previewData->pendingTill >= 0) || _kbReplyTo) { @@ -2296,6 +2310,9 @@ void HistoryWidget::updateControlsVisibility() { if (_scheduled) { _scheduled->hide(); } + if (_ttlInfo) { + _ttlInfo->hide(); + } _kbScroll->hide(); _fieldBarCancel->hide(); _attachToggle->hide(); @@ -2492,23 +2509,6 @@ void HistoryWidget::messagesReceived(PeerData *peer, const MTPmessages_Messages } break; } - const auto ExtractFirstId = [&] { - return histList->empty() ? -1 : IdFromMessage(histList->front()); - }; - const auto ExtractLastId = [&] { - return histList->empty() ? -1 : IdFromMessage(histList->back()); - }; - const auto PeerString = [](PeerId peerId) { - if (peerIsUser(peerId)) { - return QString("User-%1").arg(peerToUser(peerId)); - } else if (peerIsChat(peerId)) { - return QString("Chat-%1").arg(peerToChat(peerId)); - } else if (peerIsChannel(peerId)) { - return QString("Channel-%1").arg(peerToChannel(peerId)); - } - return QString("Bad-%1").arg(peerId); - }; - if (_preloadRequest == requestId) { auto to = toMigrated ? _migrated : _history; addMessagesToFront(peer, *histList); @@ -3992,7 +3992,7 @@ void HistoryWidget::moveFieldControls() { } // _attachToggle --------- _inlineResults -------------------------------------- _tabbedPanel --------- _fieldBarCancel -// (_attachDocument|_attachPhoto) _field (_scheduled) (_silent|_cmdStart|_kbShow) (_kbHide|_tabbedSelectorToggle) _send +// (_attachDocument|_attachPhoto) _field (_ttlInfo) (_scheduled) (_silent|_cmdStart|_kbShow) (_kbHide|_tabbedSelectorToggle) _send // (_botStart|_unblock|_joinChannel|_muteUnmute) auto buttonsBottom = bottom - _attachToggle->height(); @@ -4015,6 +4015,10 @@ void HistoryWidget::moveFieldControls() { } if (_scheduled) { _scheduled->moveToRight(right, buttonsBottom); + right += _scheduled->width(); + } + if (_ttlInfo) { + _ttlInfo->move(width() - right - _ttlInfo->width(), buttonsBottom); } _fieldBarCancel->moveToRight(0, _field->y() - st::historySendPadding - _fieldBarCancel->height()); @@ -4046,6 +4050,7 @@ void HistoryWidget::updateFieldSize() { if (_cmdStartShown) fieldWidth -= _botCommandStart->width(); if (_silent) fieldWidth -= _silent->width(); if (_scheduled) fieldWidth -= _scheduled->width(); + if (_ttlInfo) fieldWidth -= _ttlInfo->width(); if (_field->width() != fieldWidth) { _field->resize(fieldWidth, _field->height()); @@ -5405,6 +5410,23 @@ void HistoryWidget::checkPinnedBarState() { } } +void HistoryWidget::checkMessagesTTL() { + if (!_peer || !_peer->messagesTTL()) { + if (_ttlInfo) { + _ttlInfo = nullptr; + updateControlsGeometry(); + updateControlsVisibility(); + } + } else if (!_ttlInfo) { + _ttlInfo = std::make_unique( + this, + _peer); + orderWidgets(); + updateControlsGeometry(); + updateControlsVisibility(); + } +} + void HistoryWidget::refreshPinnedBarButton(bool many) { const auto close = !many; auto button = object_ptr( diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 3c52c09ac..13ccd8f69 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -99,6 +99,7 @@ class GroupCallTracker; namespace Controls { class RecordLock; class VoiceRecordBar; +class TTLButton; } // namespace Controls } // namespace HistoryView @@ -483,6 +484,7 @@ private: int wasScrollTop, int nowScrollTop); + void checkMessagesTTL(); void setupGroupCallTracker(); void sendInlineResult(InlineBots::ResultSelected result); @@ -692,6 +694,7 @@ private: object_ptr _botCommandStart; object_ptr _silent = { nullptr }; object_ptr _scheduled = { nullptr }; + std::unique_ptr _ttlInfo; const std::unique_ptr _voiceRecordBar; bool _cmdStartShown = false; object_ptr _field; 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 9b2bc1b74..e5fc9ce5e 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_item.h" #include "history/view/controls/history_view_voice_record_bar.h" +#include "history/view/controls/history_view_ttl_button.h" #include "history/view/history_view_webpage_preview.h" #include "inline_bots/inline_results_widget.h" #include "inline_bots/inline_bot_result.h" @@ -635,6 +636,10 @@ Main::Session &ComposeControls::session() const { } void ComposeControls::setHistory(SetHistoryArgs &&args) { + // Right now only single non-null set of history is supported. + // Otherwise initWebpageProcess should be updated / rewritten. + Expects(!_history && *args.history); + _showSlowmodeError = std::move(args.showSlowmodeError); _slowmodeSecondsLeft = rpl::single(0) | rpl::then(std::move(args.slowmodeSecondsLeft)); @@ -643,20 +648,21 @@ void ComposeControls::setHistory(SetHistoryArgs &&args) { _writeRestriction = rpl::single(std::optional()) | rpl::then(std::move(args.writeRestriction)); const auto history = *args.history; - if (_history == history) { - return; - } + //if (_history == history) { + // return; + //} _history = history; _window->tabbedSelector()->setCurrentPeer( history ? history->peer.get() : nullptr); initWebpageProcess(); updateBotCommandShown(); + updateMessagesTTLShown(); updateControlsGeometry(_wrap->size()); updateControlsVisibility(); updateFieldPlaceholder(); - if (!_history) { - return; - } + //if (!_history) { + // return; + //} const auto peer = _history->peer; if (peer->isChat() && peer->asChat()->noParticipantInfo()) { session().api().requestFullPeer(peer); @@ -1736,7 +1742,7 @@ void ComposeControls::finishAnimating() { void ComposeControls::updateControlsGeometry(QSize size) { // _attachToggle -- _inlineResults ------ _tabbedPanel -- _fieldBarCancel - // (_attachDocument|_attachPhoto) _field (_silent|_botCommandStart) _tabbedSelectorToggle _send + // (_attachDocument|_attachPhoto) _field (_ttlInfo) (_silent|_botCommandStart) _tabbedSelectorToggle _send const auto fieldWidth = size.width() - _attachToggle->width() @@ -1744,7 +1750,8 @@ void ComposeControls::updateControlsGeometry(QSize size) { - _send->width() - _tabbedSelectorToggle->width() - (_botCommandShown ? _botCommandStart->width() : 0) - - (_silent ? _silent->width() : 0); + - (_silent ? _silent->width() : 0) + - (_ttlInfo ? _ttlInfo->width() : 0); { const auto oldFieldHeight = _field->height(); _field->resizeToWidth(fieldWidth); @@ -1775,8 +1782,15 @@ void ComposeControls::updateControlsGeometry(QSize size) { _tabbedSelectorToggle->moveToRight(right, buttonsTop); right += _tabbedSelectorToggle->width(); _botCommandStart->moveToRight(right, buttonsTop); + if (_botCommandShown) { + right += _botCommandStart->width(); + } if (_silent) { _silent->moveToRight(right, buttonsTop); + right += _silent->width(); + } + if (_ttlInfo) { + _ttlInfo->move(size.width() - right - _ttlInfo->width(), buttonsTop); } _voiceRecordBar->resizeToWidth(size.width()); @@ -1787,6 +1801,9 @@ void ComposeControls::updateControlsGeometry(QSize size) { void ComposeControls::updateControlsVisibility() { _botCommandStart->setVisible(_botCommandShown); + if (_ttlInfo) { + _ttlInfo->show(); + } } bool ComposeControls::updateBotCommandShown() { @@ -1818,6 +1835,20 @@ void ComposeControls::updateOuterGeometry(QRect rect) { } } +void ComposeControls::updateMessagesTTLShown() { + const auto peer = _history ? _history->peer.get() : nullptr; + const auto shown = peer && (peer->messagesTTL() > 0); + if (!shown && _ttlInfo) { + _ttlInfo = nullptr; + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + } else if (shown && !_ttlInfo) { + _ttlInfo = std::make_unique(_wrap.get(), peer); + updateControlsVisibility(); + updateControlsGeometry(_wrap->size()); + } +} + void ComposeControls::paintBackground(QRect clip) { Painter p(_wrap.get()); @@ -2176,6 +2207,7 @@ void ComposeControls::initWebpageProcess() { session().changes().peerUpdates( Data::PeerUpdate::Flag::Rights | Data::PeerUpdate::Flag::Notifications + | Data::PeerUpdate::Flag::MessagesTTL ) | rpl::filter([=](const Data::PeerUpdate &update) { return (update.peer.get() == peer); }) | rpl::map([](const Data::PeerUpdate &update) { @@ -2189,6 +2221,9 @@ void ComposeControls::initWebpageProcess() { if (flags & Data::PeerUpdate::Flag::Notifications) { updateSilentBroadcast(); } + if (flags & Data::PeerUpdate::Flag::MessagesTTL) { + updateMessagesTTLShown(); + } }, lifetime); base::ObservableViewer( 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 0919baff7..1504e5dcb 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.h @@ -69,6 +69,7 @@ namespace HistoryView { namespace Controls { class VoiceRecordBar; +class TTLButton; } // namespace Controls class FieldHeader; @@ -201,6 +202,7 @@ private: void initKeyHandler(); void updateSubmitSettings(); void updateSendButtonType(); + void updateMessagesTTLShown(); void updateHeight(); void updateWrappingVisibility(); void updateControlsVisibility(); @@ -286,6 +288,7 @@ private: const not_null _field; const not_null _botCommandStart; std::unique_ptr _silent; + std::unique_ptr _ttlInfo; std::unique_ptr _inlineResults; std::unique_ptr _tabbedPanel; diff --git a/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp b/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp new file mode 100644 index 000000000..646dee793 --- /dev/null +++ b/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.cpp @@ -0,0 +1,94 @@ +/* +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 "history/view/controls/history_view_ttl_button.h" + +#include "data/data_peer.h" +#include "data/data_chat.h" +#include "data/data_channel.h" +#include "data/data_changes.h" +#include "main/main_session.h" +#include "lang/lang_keys.h" +#include "boxes/peers/edit_peer_info_box.h" +#include "ui/layers/generic_box.h" +#include "ui/toast/toast.h" +#include "apiwrap.h" +#include "styles/style_chat.h" + +namespace HistoryView::Controls { + +TTLButton::TTLButton(not_null parent, not_null peer) +: _button(parent, st::historyMessagesTTL) { + _button.setClickedCallback([=] { + const auto canEdit = peer->isUser() + || (peer->isChat() + && peer->asChat()->canDeleteMessages()) + || (peer->isChannel() + && peer->asChannel()->canDeleteMessages()); + if (!canEdit) { + const auto duration = (peer->messagesTTL() < 3 * 86400) + ? tr::lng_ttl_about_duration1(tr::now) + : tr::lng_ttl_about_duration2(tr::now); + Ui::Toast::Show(tr::lng_ttl_about_tooltip( + tr::now, + lt_duration, + duration)); + return; + } + const auto callback = crl::guard(&peer->session(), [=]( + TimeId period) { + using Flag = MTPmessages_SetHistoryTTL::Flag; + peer->session().api().request(MTPmessages_SetHistoryTTL( + MTP_flags(peer->oneSideTTL() + ? Flag::f_pm_oneside + : Flag(0)), + peer->input, + MTP_int(period) + )).done([=](const MTPUpdates &result) { + peer->session().api().applyUpdates(result); + }).fail([=](const RPCError &error) { + }).send(); + }); + Ui::show( + Box( + AutoDeleteSettingsBox, + peer->myMessagesTTL(), + callback), + Ui::LayerOption(0)); + }); + peer->session().changes().peerUpdates( + peer, + Data::PeerUpdate::Flag::MessagesTTL + ) | rpl::start_with_next([=] { + const auto ttl = peer->messagesTTL(); + if (ttl < 3 * 86400) { + _button.setIconOverride(nullptr, nullptr); + } else { + _button.setIconOverride( + &st::historyMessagesTTL2Icon, + &st::historyMessagesTTL2IconOver); + } + }, _button.lifetime()); +} + +void TTLButton::show() { + _button.show(); +} + +void TTLButton::hide() { + _button.hide(); +} + +void TTLButton::move(int x, int y) { + _button.move(x, y); +} + +int TTLButton::width() const { + return _button.width(); +} + +} // namespace HistoryView::Controls diff --git a/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.h b/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.h new file mode 100644 index 000000000..37dda0141 --- /dev/null +++ b/Telegram/SourceFiles/history/view/controls/history_view_ttl_button.h @@ -0,0 +1,29 @@ +/* +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 + +#include "ui/widgets/buttons.h" + +namespace HistoryView::Controls { + +class TTLButton final { +public: + TTLButton(not_null parent, not_null peer); + + void show(); + void hide(); + void move(int x, int y); + + [[nodiscard]] int width() const; + +private: + Ui::IconButton _button; + +}; + +} // namespace HistoryView::Controls diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index c34328a02..1d4538692 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -308,6 +308,13 @@ historyAttachEmoji: IconButton(historyAttach) { iconOver: icon {{ "send_control_emoji", historyComposeIconFgOver }}; iconPosition: point(-1px, -1px); } +historyMessagesTTL: IconButton(historyAttach) { + icon: icon {{ "chat/send_control_autodelete_1d", historyComposeIconFg }}; + iconOver: icon {{ "chat/send_control_autodelete_1d", historyComposeIconFgOver }}; + iconPosition: point(-1px, -1px); +} +historyMessagesTTL2Icon: icon {{ "chat/send_control_autodelete_7d", historyComposeIconFg }}; +historyMessagesTTL2IconOver: icon {{ "chat/send_control_autodelete_7d", historyComposeIconFgOver }}; historyAttachEmojiFgActive: windowActiveTextFg; historyAttachEmojiActive: icon {{ "send_control_emoji", historyAttachEmojiFgActive }}; historyAttachEmojiTooltipDelta: 4px;