From 6d87dcb6a5809447b1c20b26e982e8b87f77b933 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 11 Sep 2022 02:32:20 +0300 Subject: [PATCH] [Improvement] Mention user from context menu --- Telegram/Resources/icons/menu/mention.png | Bin 0 -> 2342 bytes Telegram/Resources/icons/menu/mention@2x.png | Bin 0 -> 3026 bytes Telegram/Resources/icons/menu/mention@3x.png | Bin 0 -> 3355 bytes Telegram/Resources/langs/rewrites/en.json | 1 + .../boxes/peers/edit_participants_box.cpp | 8 ++++++++ .../SourceFiles/history/history_widget.cpp | 19 ++++++++++++++++++ Telegram/SourceFiles/history/history_widget.h | 2 ++ Telegram/SourceFiles/mainwidget.cpp | 8 ++++++++ Telegram/SourceFiles/mainwidget.h | 2 ++ Telegram/SourceFiles/ui/menu_icons.style | 1 + 10 files changed, 41 insertions(+) create mode 100644 Telegram/Resources/icons/menu/mention.png create mode 100644 Telegram/Resources/icons/menu/mention@2x.png create mode 100644 Telegram/Resources/icons/menu/mention@3x.png diff --git a/Telegram/Resources/icons/menu/mention.png b/Telegram/Resources/icons/menu/mention.png new file mode 100644 index 0000000000000000000000000000000000000000..bf6e9f6c5777ce1e1a13b90ec486905520225bf7 GIT binary patch literal 2342 zcmcgue@xV77(N*y{v0YYhQ>72IZ%4-wa4{ZITSe%3MhIbNFM)Fvd8HW*UNwIAzOp&KaBz7j;U+p}4Qdal-|j@sC~7_UqT@ zd!Ofh-=|-%CNF2<_%U%~G#btLtW0x0yvC|WWEeb4Q}#E(%VMo=i+xGWs2(>RI*AWE?bO;rhz zrItJ-P4WUHNo&A(ojwVn8LiGh=@}*wAqkxkCycm`!gK~!Pp~A31b--G^9mxHZ_WsE z!8;RbR}>G6<368H>!Y-iw+PoU41*ISPLdczU~-vT;ry6eo-r7~3}oKx@F)(+ji?bh zn^dBhP^feu1(zoj)-4Ci1Pg}yIS;PW5^72TpumT4o)WJ!KrZk&Z~_-_D>B6DLRgPo zQY6_fJtuVN@iPRlv=&Q``f;Ci1Oz@RT^{s6lyiHeW&g47~dyO;47{yhCM zSNdZ0dYaY&qex>mMzCRk(hHc8vcVH?;PoUBL_Ucg%zjw)L;d)Q>Vw7M?VP&^z#SAv zUp=3fbLW82|2H38-8%=YhX31zfoDVZS=i3N6x_VkVd$#?Z$jT4;D)90!mmnpb=*%H zP1u|)bE?(YdePc;pn;1%c_u93J*B|ckSGAYA!^d2<(V}{4n24yDrQqfQpc5q;>P$7 z_BcPRY9}_wa}6_{Q$AwKes8c;#8@j>5{s3q~ycb8dbPidZ78&R2OHPoN@Ig8yfD=PBr+^yN)ocitl>i5a5<9atQ zdaLqL#q`4CR}A%SF&i2$+|pz>=ASJlw`yih8a)k-@ADX=YRuoIqZ3cJT#>|h|&|}zl#a;dJtSzlqw_I`>T4KjkMXgAT(d@I%UVD@)jr^n)oUYn- z<&V;i+c|sd+QhNpVY@oJOSX%<6A>=_+J4(%|GfUr&VntiRV^1+ow??@Td;5W!3E*B zwc-S=#dnctVd^>u~^?SVvd!m1K>G3BUMxW~aG<#M>T;7e{ d5l`hmCr@s#Wo|mZ8ma!1$x6>Lf4QKr@^2eZHrfCH literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/menu/mention@2x.png b/Telegram/Resources/icons/menu/mention@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..f82cb39d7bc3ed8316a99d7bac13a3b2f503011b GIT binary patch literal 3026 zcmcgueN+=y77rB_P*6lfKrseT3QjWlf=nbRBnTWEKnMb&E|Zyoq>`B-37;M*MR1D& z1?wkBwXm?YS`kDlV3i{%de#G$svuN>b&H-A#UiV+Qo1jE)$XxfPyg7QGc#}A{NBC4 z`@8qum)y|c080x83kHK>85AfB15em^nY{<@ow4Li@Gz$Xqje0%92?_h!YDern8BF! zxmppWkCJ~N#wZON#VIAhPSwx=&0u)1Nu^P28=+?^iFh?BVGTB1VlmaYgcT{2!*W_m zsMLY!S|U6>Sb?Q)!w{Uc#)s*hDh38LgdSz4Y7$7DI90+Lw<`u?<1~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bEM%tg|WikFL8hIr32V@~!J6 zGWq3`y>O*@*s#Y2W!Y0k=ZlNAm-Tq}&5f<~4?i|FHPzq0?ZYuedmqCk#>+>qySTWR zThB4s>g((Biz_D&uIZ^wVZuPpiab`WnG%vs5 zC;e4Erc8hT%F4>Ox0VxwRajNs-5Zbk%Nhz)IodW-XK9L;yStWJ;=mqSD(_(ZqRT(T zy`P?L$^>RUei+I!s z&6>+p^4OfmT59q_jT!!=Q9I}&9O$ZhpASS3JH5*ADpyLnnliB3eeVuu?>oND?VN9+ z--7be2@VxMdTVlg{0JoQ%C*;a=hr)CukcuXcdgsDHjLRuluDnv|U*yE)BZ5 zuuY}u#F<}y8M|t@`^x(v02np z_;vu10N3{8PVZ3VBJAnv&Kl37IHya6frCA#-O@I^njG%BLAZ^Cez*SJEVeCL7gdE= zqbq}M-bFHwNEkw)kPx(Ehm~1*oprsXj7FtW-Q1EszAK?Gq%;MNk30+O33k!PVZ$o2ezcvzgDl4cgOHRCf&YfDR5d0|P;%NE-zO1+7({AA9f^O!5uW z;_JGFc`el^&zu2RtQDC^6BCyZ*Mgbs?Ch~IaP)0mO^*FeJ&aG8Vzy0qLW<6t;jZ%W zaY!POSYEhtE7@REV4zpz=FP@(vgX;)__RNlGHtTor6wL@po9k}NM0s`J77tl2{G)g8}D*ayZ@$su`?EO`k zUih5ndzza)l$8%)G>%E7uFlTRTejqEEPXNY+C2iUPt6KLwY8sXgV^lK2X%WIZp1tu zE)DfrwSD{cBby$-+n1D-l#`Q_kacJ}>51^B?ZLspEqk{L0_E>ji_rI<`_-3JU7Bu=4y%@bzPPz~(#|_?OZX@38H^zS literal 0 HcmV?d00001 diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 832b33c06..c6d27359e 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -133,6 +133,7 @@ "ktg_forward_subtitle_uncaptioned": "uncaptioned", "ktg_forward_subtitle_group_all_media": "as albums", "ktg_forward_subtitle_separate_messages": "one by one", + "ktg_profile_mention_user": "Mention user", "ktg_filters_exclude_not_owned": "Not owned", "ktg_filters_exclude_not_admin": "Not administrated", "ktg_filters_exclude_owned": "Owned", diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index bc4b724dd..b35d188f8 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1647,6 +1647,14 @@ base::unique_qptr ParticipantsBoxController::rowContextMenu( : Dialogs::Key(), user); }), &st::menuIconSearch); + if (const auto openedPeer = mainwidget->peer()) { + if (Data::CanSendTexts(openedPeer) && participant->isUser()) { + result->addAction( + ktr("ktg_profile_mention_user"), + crl::guard(this, [=] { mainwidget->mentionUser(user); }), + &st::menuIconMention); + } + } } } if (const auto by = _additional.restrictedBy(participant)) { diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index e329137a7..16ca2594b 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -7642,6 +7642,25 @@ bool HistoryWidget::sendExistingPhoto( return true; } +void HistoryWidget::mentionUser(PeerData *peer) { + if (!peer || !peer->isUser()) { + return; + } + + const auto user = peer->asUser(); + QString replacement, entityTag; + if (user->username.isEmpty()) { + replacement = user->firstName; + if (replacement.isEmpty()) { + replacement = user->name; + } + entityTag = PrepareMentionTag(user); + } else { + replacement = '@' + user->username; + } + _field->insertTag(replacement, entityTag); +} + void HistoryWidget::showInfoTooltip( const TextWithEntities &text, Fn hiddenCallback) { diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 7ec356f7a..11aba41ae 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -277,6 +277,8 @@ public: not_null photo, Api::SendOptions options); + void mentionUser(PeerData *peer); + void showInfoTooltip( const TextWithEntities &text, Fn hiddenCallback); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 3a5415a9c..bdb3d1c6f 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -2796,6 +2796,14 @@ int MainWidget::backgroundFromY() const { return -getMainSectionTop(); } +void MainWidget::mentionUser(PeerData *peer) { + if (!_history->peer() || !_history->peer()->canWrite()) { + return; + } + + _history->mentionUser(peer); +} + bool MainWidget::contentOverlapped(const QRect &globalRect) { return _history->contentOverlapped(globalRect) || _playerPlaylist->overlaps(globalRect); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index ca6748c31..ff821e658 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -202,6 +202,8 @@ public: bool contentOverlapped(const QRect &globalRect); + void mentionUser(PeerData *peer); + void showChooseReportMessages( not_null peer, Ui::ReportReason reason, diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index aefc143c8..a16e42b92 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -80,6 +80,7 @@ menuIconPersonal: icon {{ "menu/personal", menuIconColor }}; menuIconPorn: icon {{ "menu/porn", menuIconColor }}; menuIconViolence: icon {{ "menu/violence", menuIconColor }}; menuIconHide: icon {{ "menu/hide", menuIconColor }}; +menuIconMention: icon {{ "menu/mention", menuSubmenuArrowFg }}; menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }}; menuIconSilent: icon {{ "menu/silent", menuIconColor }}; menuIconCustomize: icon {{ "menu/customize", menuIconColor }};