diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 85fd743628bbf2..dcb0c92ad9d60d 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -1333,7 +1333,11 @@ void HistoryItem::setServiceText(PreparedServiceText &&prepared) { _text = std::move(prepared.text); data->textLinks = std::move(prepared.links); if (had) { +#if 0 // mtp _history->owner().requestItemTextRefresh(this); +#endif + // Media could be updated as well which requires to recreate views. + _history->owner().requestItemViewRefresh(this); } } @@ -1835,6 +1839,52 @@ void HistoryItem::setCustomServiceLink(ClickHandlerPtr link) { Get()->link = std::move(link); } +void HistoryItem::ensurePropertiesLoaded() { + if (!isRegular() || (_flags & MessageFlag::PropertiesLoaded)) { + return; + } + _flags |= MessageFlag::PropertiesLoaded; + const auto id = fullId(); + const auto session = &history()->session(); + session->sender().request(TLgetMessageProperties( + peerToTdbChat(id.peer), + tl_int53(id.msg.bare) + )).done([=](const TLDmessageProperties &data) { + if (const auto that = session->data().message(id)) { + that->_flags |= MessageFlag::PropertiesLoaded; + // data.vcan_be_copied_to_secret_chat() + // data.vcan_be_deleted_only_for_self() + if (data.vcan_be_deleted_for_all_users().v) { + that->_flags |= MessageFlag::CanDeleteForAll; + } + if (data.vcan_be_edited().v) { + that->_flags |= MessageFlag::CanEdit; + } + // data.vcan_be_forwarded() + // data.vcan_be_paid() + // data.vcan_be_pinned() + // data.vcan_be_replied() + // data.vcan_be_replied_in_another_chat() + // data.vcan_be_saved() + // data.vcan_be_shared_in_story() + // data.vcan_edit_scheduling_state() + // data.vcan_get_embedding_code() + // data.vcan_get_link() + // data.vcan_get_media_timestamp_links() + // data.vcan_get_message_thread() + // data.vcan_get_read_date() + // data.vcan_get_statistics() + // data.vcan_get_viewers() + // data.vcan_recognize_speech() + // data.vcan_report_chat() + // data.vcan_report_reactions() + // data.vcan_report_supergroup_spam() + // data.vcan_set_fact_check() + // data.vneed_show_statistics() + } + }).send(); +} + void HistoryItem::destroy() { _history->destroyMessage(this); } @@ -5115,6 +5165,24 @@ void HistoryItem::setServiceMessageByContent( lt_from, fromLinkText(), // Link 1. Ui::Text::WithEntities); + }, [&](const TLDmessageGiveawayCompleted &data) { + const auto winners = data.vwinner_count().v; + const auto unclaimed = data.vunclaimed_prize_count().v; + const auto credits = data.vis_star_giveaway().v; + prepared.text = { + (!winners + ? tr::lng_action_giveaway_results_none(tr::now) + : (credits && unclaimed) + ? tr::lng_action_giveaway_results_credits_some(tr::now) + : (!credits && unclaimed) + ? tr::lng_action_giveaway_results_some(tr::now) + : (credits && !unclaimed) + ? tr::lng_action_giveaway_results_credits( + tr::now, + lt_count, + winners) + : tr::lng_action_giveaway_results(tr::now, lt_count, winners)) + }; }, [&](const TLDmessageForumTopicCreated &data) { const auto topicUrl = u"internal:url:https://t.me/c/%1/%2"_q .arg(peerToChannel(history()->peer->id).bare) @@ -5699,6 +5767,10 @@ std::unique_ptr HistoryItem::CreateMedia( return std::make_unique( item, Data::ComputeGiveawayResultsData(item, data)); + }, [&](const TLDmessagePaidMedia &media) -> Result { + return std::make_unique( + item, + Data::ComputeInvoiceData(item, media)); }, [](const auto &) -> Result { return nullptr; }); diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 1893f0b1b04fea..2dc9ba59ff2f91 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -245,6 +245,8 @@ class HistoryItem final : public RuntimeComposer { void setRealShortcutId(BusinessShortcutId id); void setCustomServiceLink(ClickHandlerPtr link); + void ensurePropertiesLoaded(); + void addLogEntryOriginal( WebPageId localId, const QString &label, diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index 12298b23bd1b0c..58c03f5948add7 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1114,6 +1114,7 @@ void Message::draw(Painter &p, const PaintContext &context) const { item->history()->session().factchecks().requestFor(item); } #endif + item->ensurePropertiesLoaded(); const auto stm = context.messageStyle(); const auto bubble = drawBubble(); diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index 0de40ca7a57363..506b15cab67ea9 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -501,6 +501,8 @@ void Service::draw(Painter &p, const PaintContext &context) const { } const auto &margin = st::msgServiceMargin; + data()->ensurePropertiesLoaded(); + const auto st = context.st; auto height = this->height() - margin.top() - margin.bottom(); auto dateh = 0; diff --git a/Telegram/SourceFiles/overview/overview_layout.cpp b/Telegram/SourceFiles/overview/overview_layout.cpp index 4357a17eb1123e..6fb9071e142821 100644 --- a/Telegram/SourceFiles/overview/overview_layout.cpp +++ b/Telegram/SourceFiles/overview/overview_layout.cpp @@ -162,6 +162,7 @@ ItemBase::ItemBase( : _delegate(delegate) , _parent(parent) , _dateTime(ItemDateTime(parent)) { + _parent->ensurePropertiesLoaded(); } ItemBase::~ItemBase() = default; diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 27086d2b8e7e42..94c5f8cef2434b 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -302,6 +302,10 @@ Form::Form(InvoiceId id, bool receipt) if (_receiptMode) { _invoice.receipt.paid = true; requestReceipt(); + } else if (v::is(id.value)) { + crl::on_main(this, [=] { + sendStarGiftForm(); + }); } else { requestForm(); } @@ -309,6 +313,24 @@ Form::Form(InvoiceId id, bool receipt) Form::~Form() = default; +void Form::sendStarGiftForm() { + const auto &gift = v::get(_id.value); + const auto invoice = InvoiceCredits{ + .session = _session, + .randomId = 0, + .credits = uint64(gift.stars), + .currency = ::Ui::kCreditsCurrency, + .amount = uint64(gift.stars), + }; + const auto formData = CreditsFormData{ + .id = _id, + .invoice = invoice, + .starGiftLimitedCount = gift.limitedCount, + .starGiftForm = true, + }; + _updates.fire(CreditsPaymentStarted{ .data = formData }); +} + void Form::fillInvoiceFromMessage() { const auto message = std::get_if(&_id.value); if (!message) { diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index 4ee345f00d9b06..71fe5c048bd97b 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -194,6 +194,7 @@ struct InvoiceCredits { struct InvoiceStarGift { uint64 giftId = 0; + int64 stars = 0; uint64 randomId = 0; TextWithEntities message; not_null user; @@ -411,6 +412,7 @@ class Form final : public base::has_weak_ptr { void fillStripeNativeMethod(QJsonObject object); void fillSmartGlocalNativeMethod(QJsonObject object); #endif + void sendStarGiftForm(); void refreshPaymentMethodDetails(); void refreshSavedPaymentMethodDetails(); [[nodiscard]] QString defaultPhone() const; diff --git a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp index c855fac0de1a9b..f6b1e8fdc7962b 100644 --- a/Telegram/SourceFiles/ui/effects/credits_graphics.cpp +++ b/Telegram/SourceFiles/ui/effects/credits_graphics.cpp @@ -442,6 +442,8 @@ PaintRoundImageCallback GenerateGiftStickerUserpicCallback( not_null session, uint64 stickerId, Fn update) { + Expects(stickerId != 0); + struct State { std::optional painter; int size = 0;