From 3dbc131b98cdb3bc21897cb90d521441c7ab8c4f Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 22 Oct 2020 12:13:00 +0300 Subject: [PATCH] Show pin icon in pinned messages. --- Telegram/Resources/icons/history_pin.png | Bin 0 -> 438 bytes Telegram/Resources/icons/history_pin@2x.png | Bin 0 -> 720 bytes Telegram/Resources/icons/history_pin@3x.png | Bin 0 -> 1034 bytes Telegram/SourceFiles/history/history_item.cpp | 4 ++ .../history/view/history_view_message.cpp | 43 +++++++++++++++--- .../history/view/history_view_message.h | 12 +++-- .../ui/chat/attach/attach_prepare.cpp | 5 +- Telegram/SourceFiles/ui/chat/chat.style | 6 +++ 8 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 Telegram/Resources/icons/history_pin.png create mode 100644 Telegram/Resources/icons/history_pin@2x.png create mode 100644 Telegram/Resources/icons/history_pin@3x.png diff --git a/Telegram/Resources/icons/history_pin.png b/Telegram/Resources/icons/history_pin.png new file mode 100644 index 0000000000000000000000000000000000000000..55066f98ba051cdb81a8c5257acd1baf6f0e06d1 GIT binary patch literal 438 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|mUKs7M+SzC{oH>NS%G|u)CkWs zUtb0-Ae)1Mu|1Q41;}CqVksbIU|?Fn1Q!unz>HvnBzGoG$OkIc^mK6yu@GE4$#7MR zfk4~l^WhbY+}0aE2{bKW-zfTKPfNtjjMuC-%^MadggxREvA!6UQ!;Pj-3dFSZyf#Z zoRIe9f11&=Hi4$UG1tzg9%BAr>LKEqmtV8BzwiBTgY(8Ap{!kt=Ge}6d}P5E6?=Vd zV$B2<&jblJ6;CH)k2$H5wxZldzQUhu+B0W$G>U(zJ|k1|%Oc%$NbBSkfJR9T^xl_H+M9WCijqQX@Rm ze0>?TfNTy1#`a7G79fieh^2s-fq`iO6I?`P0W*RPlH@#g@EA~uv!{z=NCfBGY1Zo* z9Yu~G5B0El6sQrhNcoZAT&EglR@+{ehtVrK{1scg7GGE`%B6I%BjbutV8xlan>SXM zzqfn##xy*y$k(Xs>>SJg@&7*GC=_tgSY5xY=8xng_7l<_=F0!iFLY3FFq+9zxcjb6 z@szq7sfSiyez|0>U;Dj0bFQZ)Ru|JYcV7G{JL6)8N@LCc%&k#28XFxR^hoyb9B&k2 zZ)tRN=w#f)tn3`RI`r-rOF8bS$cHzk7g+cRb+U9Ge;jo7`Dc~srxV+~f#&zQEDk&? zArhb?ro1%BlUabP)uglT)APFh!qZQ?uDiZEZO1vYYpb^ys=xSHF(p>)SB#EWSD)8s z@0hDASkxwaE)*!*bo!|icWcw4#h13RH64gsul`){6Uz**rAaKzxit&szfmwQ;^X1t zSm5fw=(97%tk^B@xwXpfA39Txnw&JKXrI?=CBv5$c)9%ccg1gC)eb+Lu)*|@#K+XF zQ45=LnGfDgGmsEyXFeBF6R9_SMMAX0M2{99HQ`4eD*{elb&P0F=y_SQ>i3P_{&UZZ z58vh4-5!2pJKxe~rliZx#~*K8_^fL0vXvoS)$E^s|9#YO>+Lp0pZ)ij$E^<++GHj4 z?YFHM+oLth*MzNpnQ-p8@!IRJtptr%yewJOz4gLYwp)4Ir52n`bH4m?%gP49knOik zd(9a(v&}l2#wBoPYOS5TxuwI##g0wy0O$?AJZ$|BgH@83Y=f)AO335+6R9=Yyl-JPgg&ebxsLQ007=Fy#N3J literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/history_pin@3x.png b/Telegram/Resources/icons/history_pin@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..7ef2fce37e1615347b4b6dcf2c3c3af8fed2917d GIT binary patch literal 1034 zcmV+l1oiugP)2{z`CxKgGp3xiA?02XN5A7&itcVPY^baZm?kFfkDZAsS&pqcQr}$9P1vy=!|1 zcQ2ty!_oHX^Zne@UfVktAp~gdxb&~%h`xckVEHUPp(Nqj3uYEdgS)=I z2Cvtv_dsbM*wE0B(1St~Z}hvpz0C!4eXn7%YoBiW;o)I2Jw4sX;c)otdSqlo*G{&w zSS*r>i3z5eDKP950W{$n%;4Z4(^)GD`}+FG^Yb&aYi>AcYi3z}c5@P9+iv zQZAQuMR2L96|)Z4qNAgumPUlv`P0)A%+1X)b^X%I7XPc!pN{N+lYm0KYG7#BPB=*@ zb71X)Q-CrLrorhQ6nXPSq+Aio8n9NvZES3yNR_N)#B_vn&g#g;<8h`h0a)w6(AoU_ zJiNcZi;Oa%Hd9km_Jg5_$Hzw@!6J=bUS7cMcH0YvXDvMZS()g2MO7$J+EURW*OYpC zdPq8*CZSNMsodiGB=#>U3D z!bIS9cXzq=f`D>hdwY9aC>(m5o11{2gp8aU!L6>Y8unq}LmUjp{O|8q8YS*HVzHQ% z7(KYf#YL&U7?9#%XncEntFbhGPfku?e0*F<2n!BxlELe15npm(3kwTStJS`s-rn9| zYikSW&O^izw++IjQYpZ**UilhEH5u}+cF}{*`3+BYA=xORkOz-YEv9232Cq_k2Q^!W^6S=j98&6GyasU7T07*qoM6N<$ Ef+dR9ssI20 literal 0 HcmV?d00001 diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 7bb00c86e..a30aa9275 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -348,6 +348,7 @@ void HistoryItem::markMediaRead() { } void HistoryItem::setIsPinned(bool pinned) { + const auto changed = (isPinned() != pinned); if (pinned) { _flags |= MTPDmessage::Flag::f_pinned; history()->session().storage().add(Storage::SharedMediaAddExisting( @@ -363,6 +364,9 @@ void HistoryItem::setIsPinned(bool pinned) { Storage::SharedMediaType::Pinned, id)); } + if (changed) { + history()->owner().requestItemResize(this); + } } bool HistoryItem::definesReplyKeyboard() const { diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index d909a839d..b1c2bfb3e 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1816,9 +1816,28 @@ void Message::drawInfo( p.drawText(dateX, dateY + st::msgDateFont->ascent, item->_timeText); } + const auto viewIconTop = infoBottom + st::historyViewsTop; + const auto pinIconTop = infoBottom + st::historyPinTop; + auto left = infoRight - infoW; + if (displayPinIcon()) { + const auto icon = [&] { + if (outbg) { + return &(invertedsprites + ? st::historyPinInvertedIcon + : selected + ? st::historyPinOutSelectedIcon + : st::historyPinOutIcon); + } + return &(invertedsprites + ? st::historyPinInvertedIcon + : selected + ? st::historyPinInSelectedIcon + : st::historyPinInIcon); + }(); + icon->paint(p, left, pinIconTop, width); + left += st::historyViewsWidth; + } if (auto views = item->Get()) { - auto left = infoRight - infoW; - const auto iconTop = infoBottom + st::historyViewsTop; const auto textTop = infoBottom - st::msgDateFont->descent; if (views->replies.count > 0 && !views->commentsMegagroupId @@ -1843,11 +1862,11 @@ void Message::drawInfo( : st::historyViewsSendingIcon); }(); if (item->id > 0) { - icon->paint(p, left, iconTop, width); + icon->paint(p, left, viewIconTop, width); p.drawText(left + st::historyViewsWidth, textTop, views->replies.text); } else if (!outbg && views->views.count < 0) { // sending outbg icon will be painted below auto iconSkip = st::historyViewsSpace + views->replies.textWidth; - icon->paint(p, left + iconSkip, iconTop, width); + icon->paint(p, left + iconSkip, viewIconTop, width); } left += st::historyViewsSpace + views->replies.textWidth @@ -1874,16 +1893,16 @@ void Message::drawInfo( : st::historyViewsSendingIcon); }(); if (item->id > 0) { - icon->paint(p, left, iconTop, width); + icon->paint(p, left, viewIconTop, width); p.drawText(left + st::historyViewsWidth, textTop, views->views.text); } else if (!outbg) { // sending outbg icon will be painted below auto iconSkip = st::historyViewsSpace + views->views.textWidth; - icon->paint(p, left + iconSkip, iconTop, width); + icon->paint(p, left + iconSkip, viewIconTop, width); } } } else if (item->id < 0 && item->history()->peer->isSelf() && !outbg) { auto icon = &(invertedsprites ? st::historyViewsSendingInvertedIcon : st::historyViewsSendingIcon); - icon->paint(p, infoRight - infoW, infoBottom + st::historyViewsTop, width); + icon->paint(p, left, viewIconTop, width); } if (outbg) { auto icon = [&] { @@ -1951,6 +1970,9 @@ int Message::infoWidth() const { result += st::historySendStateSpace; } } + if (displayPinIcon()) { + result += st::historyViewsWidth; + } // When message is scheduled until online, time is not displayed, // so message should have less space. @@ -2000,6 +2022,9 @@ int Message::timeLeft() const { result += st::historySendStateSpace; } } + if (displayPinIcon()) { + result += st::historyViewsWidth; + } return result; } @@ -2046,6 +2071,10 @@ HistoryMessageReply *Message::displayedReply() const { return nullptr; } +bool Message::displayPinIcon() const { + return data()->isPinned() && context() != Context::Pinned; +} + bool Message::hasFromName() const { switch (context()) { case Context::AdminLog: diff --git a/Telegram/SourceFiles/history/view/history_view_message.h b/Telegram/SourceFiles/history/view/history_view_message.h index 3ffa3cff1..e8a3fb229 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.h +++ b/Telegram/SourceFiles/history/view/history_view_message.h @@ -176,11 +176,13 @@ private: QSize performCountCurrentSize(int newWidth) override; bool hasVisibleText() const override; - bool displayFastShare() const; - bool displayGoToOriginal() const; - ClickHandlerPtr fastReplyLink() const; - const HistoryMessageEdited *displayedEditBadge() const; - HistoryMessageEdited *displayedEditBadge(); + [[nodiscard]] bool displayFastShare() const; + [[nodiscard]] bool displayGoToOriginal() const; + [[nodiscard]] ClickHandlerPtr fastReplyLink() const; + [[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const; + [[nodiscard]] HistoryMessageEdited *displayedEditBadge(); + [[nodiscard]] bool displayPinIcon() const; + void initTime(); [[nodiscard]] int timeLeft() const; [[nodiscard]] int plainMaxWidth() const; diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp index 15339973a..be79c4dd6 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_prepare.cpp @@ -214,9 +214,12 @@ std::vector DivideByGroups( auto result = std::vector(); auto pushGroup = [&] { + const auto type = (group.files.size() > 1) + ? groupType + : AlbumType::None; result.push_back(PreparedGroup{ .list = base::take(group), - .type = groupType, + .type = type, }); }; for (auto i = 0; i != list.files.size(); ++i) { diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 62472aeb6..4631d5f93 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -182,6 +182,12 @@ historyRepliesInSelectedIcon: icon {{ "history_replies", msgInDateFgSelected }}; historyRepliesOutIcon: icon {{ "history_replies", historyOutIconFg }}; historyRepliesOutSelectedIcon: icon {{ "history_replies", historyOutIconFgSelected }}; historyRepliesInvertedIcon: icon {{ "history_replies", historySendingInvertedIconFg }}; +historyPinTop: -18px; +historyPinInIcon: icon {{ "history_pin", msgInDateFg }}; +historyPinInSelectedIcon: icon {{ "history_pin", msgInDateFgSelected }}; +historyPinOutIcon: icon {{ "history_pin", historyOutIconFg }}; +historyPinOutSelectedIcon: icon {{ "history_pin", historyOutIconFgSelected }}; +historyPinInvertedIcon: icon {{ "history_pin", historySendingInvertedIconFg }}; historyComposeField: InputField(defaultInputField) { font: msgFont;