From 81492b7d3a1f9339fd344d6a7f100f755245a130 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 11 Oct 2024 14:08:04 +0400 Subject: [PATCH] Add "when edited" context menu information. --- .../Resources/icons/menu/edited_status.png | Bin 0 -> 586 bytes .../Resources/icons/menu/edited_status@2x.png | Bin 0 -> 1252 bytes .../Resources/icons/menu/edited_status@3x.png | Bin 0 -> 1825 bytes Telegram/SourceFiles/api/api_who_reacted.cpp | 14 +++++++++ Telegram/SourceFiles/api/api_who_reacted.h | 3 ++ .../history/history_inner_widget.cpp | 16 +++++----- .../view/history_view_context_menu.cpp | 28 ++++++++++++++++++ .../history/view/history_view_context_menu.h | 3 ++ Telegram/SourceFiles/ui/chat/chat.style | 2 ++ .../controls/who_reacted_context_action.cpp | 4 ++- .../ui/controls/who_reacted_context_action.h | 3 +- 11 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 Telegram/Resources/icons/menu/edited_status.png create mode 100644 Telegram/Resources/icons/menu/edited_status@2x.png create mode 100644 Telegram/Resources/icons/menu/edited_status@3x.png diff --git a/Telegram/Resources/icons/menu/edited_status.png b/Telegram/Resources/icons/menu/edited_status.png new file mode 100644 index 0000000000000000000000000000000000000000..70fb24466a33f9fb18ea1d76d62250f003eb566b GIT binary patch literal 586 zcmV-Q0=4~#P)#Q8deL7Yt%hSu`zpUir%R>#q9w!W)>dGk509nc2D5MMR(v%CAo* z|9Jq6G4lC*Z-c-|RaFJ&9Q*wq7uoOk7z_r8#bS=JLuFjAU89+HL@j$0HpM2m1Q@x(Rf-TvRTXX*?cNv)QD{WOA3BF-CzvfL5y&F~)9u zPlw#;bg2yLQ5_$hOO{G!@27|WAOQjM3fOG!;7cH4g!m=zFh5^Rd zYXE{EK-cxBS4Aik!e+C9X_}BE>9tM%6GYQASeAuWtA$J^15p&=cDq4D@OV6!PNx8X zTrTIt(zykHU)PmN1w@2uwF&^J*Xz&P_}aqI??t>YC=?24G#b}$J9S-9J|#cvP5u}8 Y28d4pK!e(vM*si-07*qoM6N<$f{Bs<3IG5A literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/menu/edited_status@2x.png b/Telegram/Resources/icons/menu/edited_status@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..004167a148f30c34abcc7441be3cff13cb27c7e1 GIT binary patch literal 1252 zcmVo;LPVe+4C!|h5Q|>{-;G}Z-;EzHKo+UQ48xF8sU)dXN^ZBCJRT1LkvXvu z4$I5SLtkGXc6WDie}9jUczu1v#>NIrCKF0aOT$w0e-oELtJPwEfBzFi$g&wYRt9?d=T!@bdBkgTa89m>9u@qoShF+uMuh=Vt)G+uIvjT3RA2pt`!6 zCGT>%P+ndxx`zu23UGCG1px5*e5kFhjf?=bTFthN%jH5wMuuqee#^?r!o|e}0Knt% z2+hsU(PFW%Z4-`_|7ay8C3tyx0RXJ8uZLHFR;y(yb2Fzur-1tU zdLkmSTCMc>_$ZPdH=drJXl`zfh=_7?b2@ znjWf10)iOAmT+uMVOqNL_$IWl9Q7$H8mCNDiSp!0Yt}9az%R(y+I; z7ck^#G#bIHo|KdXyWI`|I6gi`PEHP2Oz?z!uM!{oH8C+!FnOs|ilwC`{EhzpesKbb z_+93zs;aQQzK+h$PQk?eW-^%q$S*D~LMoMt7a-<3&DUycYvJ?x*gAH*9Z5+^d}8?( zh~z+{R;%Ihcv$jYuNQ@dg?!`r7m37385b9agM)*B*6HZz5R!v`u}BQ{6B82wzIwG<&2H?! zH{Zg-0*po@bUGa>D=Wb;%%|9tloU7|4mR%n{T($mHKDelxE|(u+`YcO4iFI)6@`_R zl>ncfo*pqA#0l`*SI_Go1r!z*29TefofTURwsi~t+Q8Uk6Ma~R-4K<{t~EKo zhu^RHd7E}w+MBdLfBC|JCM4&a`^imnbMB1+01$L#6qD}+3SBxN8R>vzqyv(X4oF5i zAQ|a^WTXR_VqM`z-s;Z!&p#j#fU!T#(z`y_;J9Z2{eE6V7GXOvZ z>K=~=uh)xKt98--)~;QPE|&{Kp-|f1G&eVgUawcJ-b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#gL0v!q z%0Fg#_Uu_&KY>6X?eRBn-c&Px^#T2ECX)%BPUnK3LuKkggM)*TV~2-_v81Hr&jFNb zEX$(JW<$H(j?K-@3qI*m%d|5yGpdzL3I>o8>+I}AM8tSJj-#Wa*woaddQ8=xVrppB zs#Uvzqyv(X4oF5iAQ}Ay%?W##HIDN> P00000NkvXXu0mjfzB-0{ literal 0 HcmV?d00001 diff --git a/Telegram/SourceFiles/api/api_who_reacted.cpp b/Telegram/SourceFiles/api/api_who_reacted.cpp index 6c9df39b2d..b0e44cfc9a 100644 --- a/Telegram/SourceFiles/api/api_who_reacted.cpp +++ b/Telegram/SourceFiles/api/api_who_reacted.cpp @@ -756,5 +756,19 @@ rpl::producer WhoReacted( const style::WhoRead &st) { return WhoReacted(item, reaction, context, st, nullptr); } +rpl::producer WhenEdited( + not_null author, + TimeId date) { + return rpl::single(Ui::WhoReadContent{ + .participants = { Ui::WhoReadParticipant{ + .name = author->name(), + .date = FormatReadDate(date, QDateTime::currentDateTime()), + .id = author->id.value, + } }, + .type = Ui::WhoReadType::Edited, + .fullReadCount = 1, + }); +} + } // namespace Api diff --git a/Telegram/SourceFiles/api/api_who_reacted.h b/Telegram/SourceFiles/api/api_who_reacted.h index 9a9100535c..0d1cf72342 100644 --- a/Telegram/SourceFiles/api/api_who_reacted.h +++ b/Telegram/SourceFiles/api/api_who_reacted.h @@ -61,5 +61,8 @@ struct WhoReadList { const Data::ReactionId &reaction, not_null context, // Cache results for this lifetime. const style::WhoRead &st); +[[nodiscard]] rpl::producer WhenEdited( + not_null author, + TimeId date); } // namespace Api diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index dcc9d77e85..6df845885f 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2252,22 +2252,22 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } return item; }; - const auto whoReactedItem = groupLeaderOrSelf(_dragStateItem); - const auto hasWhoReactedItem = whoReactedItem - && Api::WhoReactedExists(whoReactedItem, Api::WhoReactedList::All); + const auto leaderOrSelf = groupLeaderOrSelf(_dragStateItem); + const auto hasWhoReactedItem = leaderOrSelf + && Api::WhoReactedExists(leaderOrSelf, Api::WhoReactedList::All); const auto clickedReaction = link ? link->property( kReactionsCountEmojiProperty).value() : Data::ReactionId(); _whoReactedMenuLifetime.destroy(); if (!clickedReaction.empty() - && whoReactedItem - && Api::WhoReactedExists(whoReactedItem, Api::WhoReactedList::One)) { + && leaderOrSelf + && Api::WhoReactedExists(leaderOrSelf, Api::WhoReactedList::One)) { HistoryView::ShowWhoReactedMenu( &_menu, e->globalPos(), this, - whoReactedItem, + leaderOrSelf, clickedReaction, _controller, _whoReactedMenuLifetime); @@ -2954,8 +2954,10 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { HistoryView::AddWhoReactedAction( _menu, this, - whoReactedItem, + leaderOrSelf, _controller); + } else { + HistoryView::MaybeAddWhenEditedAction(_menu, leaderOrSelf); } if (_menu->empty()) { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 82da069a74..e34cab5898 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "history/history.h" #include "history/history_item.h" +#include "history/history_item_components.h" #include "history/history_item_text.h" #include "history/view/history_view_schedule_box.h" #include "history/view/media/history_view_media.h" @@ -1286,6 +1287,8 @@ base::unique_qptr FillContextMenu( } if (hasWhoReactedItem) { AddWhoReactedAction(result, list, item, list->controller()); + } else if (item) { + MaybeAddWhenEditedAction(result, item); } return result; @@ -1441,6 +1444,24 @@ void AddSaveSoundForNotifications( }, &st::menuIconSoundAdd); } +void AddWhenEditedActionHelper( + not_null menu, + not_null item, + bool insertSeparator) { + if (item->history()->peer->isUser()) { + if (const auto edited = item->Get()) { + if (!item->hideEditedBadge()) { + if (insertSeparator && !menu->empty()) { + menu->addSeparator(&st::expandedMenuSeparator); + } + menu->addAction(Ui::WhenReadContextAction( + menu.get(), + Api::WhenEdited(item->from(), edited->date))); + } + } + } +} + void AddWhoReactedAction( not_null menu, not_null context, @@ -1486,6 +1507,7 @@ void AddWhoReactedAction( if (!menu->empty()) { menu->addSeparator(&st::expandedMenuSeparator); } + AddWhenEditedActionHelper(menu, item, false); if (item->history()->peer->isUser()) { menu->addAction(Ui::WhenReadContextAction( menu.get(), @@ -1501,6 +1523,12 @@ void AddWhoReactedAction( } } +void MaybeAddWhenEditedAction( + not_null menu, + not_null item) { + AddWhenEditedActionHelper(menu, item, true); +} + void AddEditTagAction( not_null menu, const Data::ReactionId &id, diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index 1b14804aae..1d02e64c22 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -84,6 +84,9 @@ void AddWhoReactedAction( not_null context, not_null item, not_null controller); +void MaybeAddWhenEditedAction( + not_null menu, + not_null item); void ShowWhoReactedMenu( not_null*> menu, QPoint position, diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 7633eed080..53b2ef1836 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -808,6 +808,8 @@ whoReadPlayedDisabled: icon {{ "menu/read_audio", menuFgDisabled }}; whoReadReactions: icon{{ "menu/read_reactions", windowBoldFg }}; whoReadReactionsOver: icon{{ "menu/read_reactions", windowBoldFg }}; whoReadReactionsDisabled: icon{{ "menu/read_reactions", menuFgDisabled }}; +whenEdited: icon {{ "menu/edited_status", windowBoldFg }}; +whenEditedOver: icon {{ "menu/edited_status", windowBoldFg }}; reactionsTabAll: icon {{ "menu/read_reactions", windowFg }}; reactionsTabAllSelected: icon {{ "menu/read_reactions", activeButtonFg }}; diff --git a/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp b/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp index 37a15de627..a2f8f7229e 100644 --- a/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp +++ b/Telegram/SourceFiles/ui/controls/who_reacted_context_action.cpp @@ -597,7 +597,9 @@ void WhenAction::paint(Painter &p) { p.fillRect(0, 0, width(), _height, _st.itemBg); } p.fillRect(0, 0, width(), _height, _st.itemBg); - const auto &icon = loading + const auto &icon = (_content.type == WhoReadType::Edited) + ? (selected ? st::whenEditedOver : st::whenEdited) + : loading ? st::whoReadChecksDisabled : selected ? st::whoReadChecksOver diff --git a/Telegram/SourceFiles/ui/controls/who_reacted_context_action.h b/Telegram/SourceFiles/ui/controls/who_reacted_context_action.h index 74e3f0d544..f0b2545f55 100644 --- a/Telegram/SourceFiles/ui/controls/who_reacted_context_action.h +++ b/Telegram/SourceFiles/ui/controls/who_reacted_context_action.h @@ -36,6 +36,7 @@ enum class WhoReadType { Listened, Watched, Reacted, + Edited, }; enum class WhoReadState : uchar { @@ -65,7 +66,7 @@ struct WhoReadContent { [[nodiscard]] base::unique_qptr WhenReadContextAction( not_null menu, rpl::producer content, - Fn showOrPremium); + Fn showOrPremium = nullptr); enum class WhoReactedType : uchar { Viewed,