From fe0e526b79f05fc44d9a3cd306d789ba0df7e5ca Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 28 Oct 2023 21:26:56 +0400 Subject: [PATCH] Support phrases for unclaimed giveaway prizes. --- Telegram/Resources/langs/lang.strings | 5 ++++ .../SourceFiles/boxes/gift_premium_box.cpp | 30 +++++++++++++------ Telegram/SourceFiles/data/data_media_types.h | 1 + .../export/data/export_data_types.cpp | 1 + .../export/data/export_data_types.h | 1 + .../export/output/export_output_html.cpp | 7 ++++- .../export/output/export_output_json.cpp | 1 + Telegram/SourceFiles/history/history_item.cpp | 5 +++- .../view/media/history_view_premium_gift.cpp | 10 +++++-- 9 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 846b14aef9..89705be165 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2111,6 +2111,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_prize_gift_about" = "You've received a gift from {channel}."; "lng_prize_gift_duration" = "Your gift is a **Telegram Premium** subscription {duration}."; "lng_prize_open" = "Open Gift Link"; +"lng_prize_unclaimed_title" = "Unclaimed Prize"; +"lng_prize_unclaimed_about" = "You have an unclaimed prize from a giveaway by {channel}."; +"lng_prize_unclaimed_duration" = "This prize is a **Telegram Premium** subscription {duration}."; "lng_prizes_title#one" = "Giveaway Prize"; "lng_prizes_title#other" = "Giveaway Prizes"; @@ -2161,10 +2164,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_gift_link_about" = "This link allows you to activate\na **Telegram Premium** subscription."; "lng_gift_link_label_from" = "From"; "lng_gift_link_label_to" = "To"; +"lng_gift_link_label_to_unclaimed" = "No recipient"; "lng_gift_link_label_gift" = "Gift"; "lng_gift_link_gift_premium" = "Telegram Premium {duration}"; "lng_gift_link_label_reason" = "Reason"; "lng_gift_link_reason_giveaway" = "Giveaway"; +"lng_gift_link_reason_unclaimed" = "Incomplete Giveaway"; "lng_gift_link_reason_chosen" = "You were selected by the channel"; "lng_gift_link_label_date" = "Date"; "lng_gift_link_also_send" = "You can also {link} to a friend as a gift."; diff --git a/Telegram/SourceFiles/boxes/gift_premium_box.cpp b/Telegram/SourceFiles/boxes/gift_premium_box.cpp index 84c2db7e65..c7b59f44be 100644 --- a/Telegram/SourceFiles/boxes/gift_premium_box.cpp +++ b/Telegram/SourceFiles/boxes/gift_premium_box.cpp @@ -477,11 +477,18 @@ void GiftCodeBox( tr::lng_gift_link_label_from(), controller, current.from); - AddTableRow( - table, - tr::lng_gift_link_label_to(), - controller, - current.to); + if (current.to) { + AddTableRow( + table, + tr::lng_gift_link_label_to(), + controller, + current.to); + } else { + AddTableRow( + table, + tr::lng_gift_link_label_to(), + tr::lng_gift_link_label_to_unclaimed(Ui::Text::WithEntities)); + } AddTableRow( table, tr::lng_gift_link_label_gift(), @@ -493,11 +500,16 @@ void GiftCodeBox( table, tr::lng_gift_link_label_reason(), (current.giveawayId - ? (tr::lng_gift_link_reason_giveaway() | Ui::Text::ToLink()) + ? ((current.to + ? tr::lng_gift_link_reason_giveaway + : tr::lng_gift_link_reason_unclaimed)( + ) | Ui::Text::ToLink()) : current.giveaway - ? (tr::lng_gift_link_reason_giveaway( - Ui::Text::WithEntities - ) | rpl::type_erased()) + ? ((current.to + ? tr::lng_gift_link_reason_giveaway + : tr::lng_gift_link_reason_unclaimed)( + Ui::Text::WithEntities + ) | rpl::type_erased()) : tr::lng_gift_link_reason_chosen(Ui::Text::WithEntities))); reason->setClickHandlerFilter([=](const auto &...) { controller->showPeerHistory( diff --git a/Telegram/SourceFiles/data/data_media_types.h b/Telegram/SourceFiles/data/data_media_types.h index 02d321720d..9af199b4dd 100644 --- a/Telegram/SourceFiles/data/data_media_types.h +++ b/Telegram/SourceFiles/data/data_media_types.h @@ -104,6 +104,7 @@ struct GiftCode { ChannelData *channel = nullptr; int months = 0; bool viaGiveaway = false; + bool unclaimed = false; }; class Media { diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index bd7203cdb4..bbfcd37aad 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -1330,6 +1330,7 @@ ServiceAction ParseServiceAction( ? peerFromMTP(*data.vboost_peer()) : PeerId(); content.viaGiveaway = data.is_via_giveaway(); + content.unclaimed = data.is_unclaimed(); content.months = data.vmonths().v; content.code = data.vslug().v; result.content = content; diff --git a/Telegram/SourceFiles/export/data/export_data_types.h b/Telegram/SourceFiles/export/data/export_data_types.h index e670c9a5c0..99848724c2 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.h +++ b/Telegram/SourceFiles/export/data/export_data_types.h @@ -544,6 +544,7 @@ struct ActionGiftCode { PeerId boostPeerId = 0; int months = 0; bool viaGiveaway = false; + bool unclaimed = false; }; struct ActionRequestedPeer { diff --git a/Telegram/SourceFiles/export/output/export_output_html.cpp b/Telegram/SourceFiles/export/output/export_output_html.cpp index 28018e8884..c2cb8d46e8 100644 --- a/Telegram/SourceFiles/export/output/export_output_html.cpp +++ b/Telegram/SourceFiles/export/output/export_output_html.cpp @@ -1280,7 +1280,12 @@ auto HtmlWriter::Wrap::pushMessage( + wrapReplyToLink("the same background") + " for this chat"; }, [&](const ActionGiftCode &data) { - return data.viaGiveaway + return data.unclaimed + ? ("This is an unclaimed Telegram Premium for " + + NumberToString(data.months) + + (data.months > 1 ? " months" : "month") + + " prize in a giveaway organized by a channel.") + : data.viaGiveaway ? ("You won a Telegram Premium for " + NumberToString(data.months) + (data.months > 1 ? " months" : "month") diff --git a/Telegram/SourceFiles/export/output/export_output_json.cpp b/Telegram/SourceFiles/export/output/export_output_json.cpp index 02545e1fdd..8cdbb5dbba 100644 --- a/Telegram/SourceFiles/export/output/export_output_json.cpp +++ b/Telegram/SourceFiles/export/output/export_output_json.cpp @@ -600,6 +600,7 @@ QByteArray SerializeMessage( push("boost_peer_id", data.boostPeerId); } push("months", data.months); + push("unclaimed", data.unclaimed); push("via_giveaway", data.viaGiveaway); }, [&](const ActionGiveawayLaunch &data) { pushAction("giveaway_launch"); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 6fafd5465a..bc2b4b5031 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -4477,7 +4477,9 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { const auto months = action.vmonths().v; result.text = { - (action.is_via_giveaway() + (action.is_unclaimed() + ? tr::lng_prize_unclaimed_about + : action.is_via_giveaway() ? tr::lng_prize_about : tr::lng_prize_gift_about)( tr::now, @@ -4668,6 +4670,7 @@ void HistoryItem::applyAction(const MTPMessageAction &action) { : nullptr), .months = data.vmonths().v, .viaGiveaway = data.is_via_giveaway(), + .unclaimed = data.is_unclaimed(), }); }, [](const auto &) { }); diff --git a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp index 1ec8cd507a..b7758eafa4 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_premium_gift.cpp @@ -45,6 +45,8 @@ QSize PremiumGift::size() { QString PremiumGift::title() { return _data.slug.isEmpty() ? tr::lng_premium_summary_title(tr::now) + : _data.unclaimed + ? tr::lng_prize_unclaimed_title(tr::now) : tr::lng_prize_title(tr::now); } @@ -53,7 +55,9 @@ TextWithEntities PremiumGift::subtitle() { return { GiftDuration(_data.months) }; } const auto name = _data.channel ? _data.channel->name() : "channel"; - auto result = (_data.viaGiveaway + auto result = (_data.unclaimed + ? tr::lng_prize_unclaimed_about + : _data.viaGiveaway ? tr::lng_prize_about : tr::lng_prize_gift_about)( tr::now, @@ -61,7 +65,9 @@ TextWithEntities PremiumGift::subtitle() { Ui::Text::Bold(name), Ui::Text::RichLangValue); result.append("\n\n"); - result.append((_data.viaGiveaway + result.append((_data.unclaimed + ? tr::lng_prize_unclaimed_duration + : _data.viaGiveaway ? tr::lng_prize_duration : tr::lng_prize_gift_duration)( tr::now,