From c14e20b33f028f693d396cd7ec19b099abf364f5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 28 Apr 2020 23:49:55 +0400 Subject: [PATCH] Support PSA forwarded info. --- .../Resources/icons/message_psa_tooltip.png | Bin 0 -> 549 bytes .../icons/message_psa_tooltip@2x.png | Bin 0 -> 1193 bytes .../icons/message_psa_tooltip@3x.png | Bin 0 -> 1879 bytes Telegram/Resources/langs/cloud_lang.strings | 8 ++-- Telegram/SourceFiles/history/history.style | 5 +++ .../history/history_item_components.cpp | 26 +++++++++--- .../history/history_item_components.h | 1 + .../SourceFiles/history/history_message.cpp | 3 ++ .../SourceFiles/history/history_widget.cpp | 10 ++--- Telegram/SourceFiles/history/history_widget.h | 2 +- .../history/view/history_view_message.cpp | 40 +++++++++++++----- 11 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 Telegram/Resources/icons/message_psa_tooltip.png create mode 100644 Telegram/Resources/icons/message_psa_tooltip@2x.png create mode 100644 Telegram/Resources/icons/message_psa_tooltip@3x.png diff --git a/Telegram/Resources/icons/message_psa_tooltip.png b/Telegram/Resources/icons/message_psa_tooltip.png new file mode 100644 index 0000000000000000000000000000000000000000..01a75e4114b663a91920513da1c687a0423515b5 GIT binary patch literal 549 zcmV+=0^0qFP)F|PqZ5FVFPpi@aG)oRg*Myt^I4-^WGLZi~qDAg*RKcFHi zN{K`wq0-P1GH<`}Zr|RyeecD4lWcBo=li~$otwD`5wTkTX0A;solaA=TBTyKNbq5Y z!+~bA8BHb=@oijWs8=G9;C{c)*XxyGx7&^P`@JmqFvNfX*5rQrUt*a|hS%%0kmmC_ zS1J{b#bTNSAA5+wR;v|*6A*n0;xqsrj|aC}Eg#5n9ClsTw+9Tc-~=*#3JwMXIn@+P zCX+lI4*7UI^67Nq(P-q$2v``dZ)8cViY|4*Rg3_)+if9qIvvUSe!p|C*Yjb(K~15d zYuIQsgoyf>g7tcxo6V-)TP~Np+wJr_u;9R;p#@bN$k#MKfGG?=l}hpDa^dN8>J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O|8ZPA^)>S|pq!A19`Z2Au8X&E%rRq%izxiy5lg8t1d#6S6*vupR5%$A0v@sn7MBPXO z0}s1$Y%bUT?9)RA&im{To{Ba5>7m$*Sf_296LmzA$itSyM=L>VyM9^{Nx7u44K?k( zlOPEl&>isIMi5Eyetg2bQ*g?{(b5!94@(|8pv&je1(8IUbaI3_aX1m+ZCHzc0f;=nryrE>@zI_CNE!&?w*hiv~V@l3ISjB%rI1He4*OlC~={B|&^shU@e*oXGF})-2 RZ&3gM002ovPDHLkV1g}FffxV) literal 0 HcmV?d00001 diff --git a/Telegram/Resources/langs/cloud_lang.strings b/Telegram/Resources/langs/cloud_lang.strings index c4c4a7ab9..1abb893e7 100644 --- a/Telegram/Resources/langs/cloud_lang.strings +++ b/Telegram/Resources/langs/cloud_lang.strings @@ -6,10 +6,10 @@ For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ -"cloud_lng_badge_psa_covid" = "Covid-19"; -"cloud_lng_about_psa_covid" = "This channel provides you with a public service announcement in relation to the ongoing pandemics.\nTo remove this channel from your chats list,\nright click it and select 'Hide'."; -"cloud_lng_forwarded_psa_covid" = "Covid-19 Notification from {channel}"; -"cloud_lng_tooltip_psa_covid" = "This message provides you with a public service announcement in relation to the ongoing pandemics. Learn more about this initiative at: https://telegram.org/blog/coronavirus"; +"cloud_lng_badge_psa_covid" = "COVID-19"; +"cloud_lng_about_psa_covid" = "This message provides you with a public service announcement in relation to the ongoing COVID-19 pandemic. To remove it from your chats list, right click it and select **Hide**."; +"cloud_lng_forwarded_psa_covid" = "COVID-19 Notification from {channel}"; +"cloud_lng_tooltip_psa_covid" = "This message provides you with a public service announcement in relation to the ongoing COVID-19 pandemic. Learn more about this initiative at https://telegram.org/blog/coronavirus"; "cloud_lng_passport_in_ar" = "Arabic"; "cloud_lng_passport_in_az" = "Azerbaijani"; diff --git a/Telegram/SourceFiles/history/history.style b/Telegram/SourceFiles/history/history.style index fd8b94f45..624dab4a6 100644 --- a/Telegram/SourceFiles/history/history.style +++ b/Telegram/SourceFiles/history/history.style @@ -509,12 +509,17 @@ historyGroupRadialLine: 3px; historyAboutProxy: FlatLabel(defaultFlatLabel) { align: align(top); textFg: windowSubTextFg; + minWidth: 300px; } historyAboutProxyPadding: margins(20px, 10px, 20px, 10px); historyMapPoint: icon {{ "map_point", mapPointDrop }}; historyMapPointInner: icon {{ "map_point_inner", mapPointDot }}; +historyPsaForwardPalette: TextPalette(defaultTextPalette) { + linkFg: boxTextFgGood; +} + webPageLeft: 10px; webPageBar: 2px; webPageTitleFont: semiboldFont; diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 7ea092c39..b491226e4 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -32,6 +32,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include +namespace { + +const auto kPsaForwardedPrefix = "cloud_lng_forwarded_psa_"; + +} // namespace + void HistoryMessageVia::create(UserId userId) { bot = Auth().data().user(userId); maxWidth = st::msgServiceNameFont->width( @@ -127,7 +133,7 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { } else { phrase = name; } - if (via) { + if (via && psaType.isEmpty()) { if (fromChannel) { phrase = tr::lng_forwarded_channel_via( tr::now, @@ -144,11 +150,19 @@ void HistoryMessageForwarded::create(const HistoryMessageVia *via) const { textcmdLink(2, '@' + via->bot->username)); } } else { - if (fromChannel) { - phrase = tr::lng_forwarded_channel( - tr::now, - lt_channel, - textcmdLink(1, phrase)); + if (fromChannel || !psaType.isEmpty()) { + auto custom = psaType.isEmpty() + ? QString() + : Lang::Current().getNonDefaultValue( + kPsaForwardedPrefix + psaType.toUtf8()); + phrase = !custom.isEmpty() + ? custom.replace("{channel}", textcmdLink(1, phrase)) + : (psaType.isEmpty() + ? tr::lng_forwarded_channel + : tr::lng_forwarded_psa_default)( + tr::now, + lt_channel, + textcmdLink(1, phrase)); } else { phrase = tr::lng_forwarded( tr::now, diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index cf016050f..6582bca1f 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -77,6 +77,7 @@ struct HistoryMessageForwarded : public RuntimeComponent hiddenSenderInfo; QString originalAuthor; + QString psaType; MsgId originalId = 0; mutable Ui::Text::String text = { 1 }; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 207f520c6..45f947551 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -383,6 +383,7 @@ struct HistoryMessage::CreateConfig { QString author; PeerId senderOriginal = 0; QString senderNameOriginal; + QString forwardPsaType; MsgId originalId = 0; PeerId savedFromPeer = 0; MsgId savedFromMsgId = 0; @@ -407,6 +408,7 @@ void HistoryMessage::FillForwardedInfo( } config.originalDate = data.vdate().v; config.senderNameOriginal = qs(data.vfrom_name().value_or_empty()); + config.forwardPsaType = qs(data.vpsa_type().value_or_empty()); config.originalId = data.vchannel_post().value_or_empty(); config.authorOriginal = qs(data.vpost_author().value_or_empty()); const auto savedFromPeer = data.vsaved_from_peer(); @@ -867,6 +869,7 @@ void HistoryMessage::setupForwardedComponent(const CreateConfig &config) { } forwarded->originalId = config.originalId; forwarded->originalAuthor = config.authorOriginal; + forwarded->psaType = config.forwardPsaType; forwarded->savedFromPeer = history()->owner().peerLoaded( config.savedFromPeer); forwarded->savedFromMsgId = config.savedFromMsgId; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index a88bd645a..0a247fc17 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2269,23 +2269,23 @@ void HistoryWidget::refreshAboutTopPromotion() { : Lang::Current().getNonDefaultValue( kPsaAboutPrefix + type.toUtf8()); const auto text = type.isEmpty() - ? tr::lng_proxy_sponsor_about(tr::now) + ? tr::lng_proxy_sponsor_about(tr::now, Ui::Text::RichLangValue) : custom.isEmpty() - ? tr::lng_about_psa_default(tr::now) - : custom; + ? tr::lng_about_psa_default(tr::now, Ui::Text::RichLangValue) + : Ui::Text::RichLangValue(custom); if (!_aboutTopPromotion || _aboutTopPromotionText != text) { _aboutTopPromotionText = text; _aboutTopPromotion = object_ptr>( this, object_ptr( this, - _aboutTopPromotionText, + rpl::single(_aboutTopPromotionText), st::historyAboutProxy), st::historyAboutProxyPadding); } _aboutTopPromotion->show(); } else { - _aboutTopPromotionText = QString(); + _aboutTopPromotionText = TextWithEntities(); _aboutTopPromotion.destroy(); } } diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index eab1ba9ca..eaf8855c1 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -735,7 +735,7 @@ private: object_ptr _muteUnmute; object_ptr _discuss; object_ptr _aboutTopPromotion = { nullptr }; - QString _aboutTopPromotionText; + TextWithEntities _aboutTopPromotionText; object_ptr _attachToggle; object_ptr _tabbedSelectorToggle; object_ptr _botKeyboardShow; diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 84bbd8f0d..e25fa0545 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -606,17 +606,33 @@ void Message::paintFromName( void Message::paintForwardedInfo(Painter &p, QRect &trect, bool selected) const { if (displayForwardedFrom()) { - const auto &serviceFont = st::msgServiceFont; - const auto &serviceName = st::msgServiceNameFont; - const auto item = message(); const auto outbg = hasOutLayout(); - p.setPen(selected ? (outbg ? st::msgOutServiceFgSelected : st::msgInServiceFgSelected) : (outbg ? st::msgOutServiceFg : st::msgInServiceFg)); - p.setFont(serviceFont); - auto forwarded = item->Get(); - auto breakEverywhere = (forwarded->text.countHeight(trect.width()) > 2 * serviceFont->height); - p.setTextPalette(selected ? (outbg ? st::outFwdTextPaletteSelected : st::inFwdTextPaletteSelected) : (outbg ? st::outFwdTextPalette : st::inFwdTextPalette)); + + const auto &serviceFont = st::msgServiceFont; + const auto &serviceName = st::msgServiceNameFont; + const auto breakEverywhere = (forwarded->text.countHeight(trect.width()) > 2 * serviceFont->height); + + p.setPen(!forwarded->psaType.isEmpty() + ? st::boxTextFgGood + : selected + ? (outbg + ? st::msgOutServiceFgSelected + : st::msgInServiceFgSelected) + : (outbg + ? st::msgOutServiceFg + : st::msgInServiceFg)); + p.setFont(serviceFont); + p.setTextPalette(!forwarded->psaType.isEmpty() + ? st::historyPsaForwardPalette + : selected + ? (outbg + ? st::outFwdTextPaletteSelected + : st::inFwdTextPaletteSelected) + : (outbg + ? st::outFwdTextPalette + : st::inFwdTextPalette)); forwarded->text.drawElided(p, trect.x(), trect.y(), trect.width(), 2, style::al_left, 0, -1, 0, breakEverywhere); p.setTextPalette(selected ? (outbg ? st::outTextPaletteSelected : st::inTextPaletteSelected) : (outbg ? st::outTextPalette : st::inTextPalette)); @@ -1367,8 +1383,12 @@ bool Message::hasFromName() const { } bool Message::displayFromName() const { - if (!hasFromName()) return false; - if (isAttachedToPrevious()) return false; + if (!hasFromName() || isAttachedToPrevious()) { + return false; + } + if (const auto forwarded = message()->Get()) { + return forwarded->psaType.isEmpty(); + } return true; }