diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 64d657908..02ba53c30 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1760,6 +1760,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_action_giveaway_results_none" = "No winners of the giveaway could be selected."; "lng_action_boost_apply#one" = "{from} boosted the group"; "lng_action_boost_apply#other" = "{from} boosted the group {count} times"; +"lng_action_set_chat_intro" = "{from} added the message below for all empty chats. How?"; "lng_similar_channels_title" = "Similar channels"; "lng_similar_channels_view_all" = "View all"; diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index cec1042d5..dc5ad0b86 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -1549,6 +1549,11 @@ void HistoryItem::setRealShortcutId(BusinessShortcutId id) { _shortcutId = id; } +void HistoryItem::setCustomServiceLink(ClickHandlerPtr link) { + AddComponents(HistoryServiceCustomLink::Bit()); + Get()->link = std::move(link); +} + void HistoryItem::destroy() { _history->destroyMessage(this); } @@ -4849,6 +4854,7 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) { prepareGiveawayLaunch, prepareGiveawayResults, prepareBoostApply, + PrepareEmptyText, PrepareErrorText)); // Additional information. diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index d75182680..c8963b707 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -197,6 +197,7 @@ public: [[nodiscard]] BusinessShortcutId shortcutId() const; [[nodiscard]] bool isBusinessShortcut() const; void setRealShortcutId(BusinessShortcutId id); + void setCustomServiceLink(ClickHandlerPtr link); void addLogEntryOriginal( WebPageId localId, diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 61b1d86f4..e35a804a2 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -629,6 +629,11 @@ struct HistoryServiceGiveawayResults , public HistoryServiceDependentData { }; +struct HistoryServiceCustomLink +: public RuntimeComponent { + ClickHandlerPtr link; +}; + enum class HistorySelfDestructType { Photo, Video, diff --git a/Telegram/SourceFiles/history/view/history_view_about_view.cpp b/Telegram/SourceFiles/history/view/history_view_about_view.cpp index 9d1cb9ed2..18c692118 100644 --- a/Telegram/SourceFiles/history/view/history_view_about_view.cpp +++ b/Telegram/SourceFiles/history/view/history_view_about_view.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_sending.h" #include "apiwrap.h" #include "base/random.h" +#include "boxes/premium_preview_box.h" #include "chat_helpers/stickers_lottie.h" #include "core/click_handler_types.h" #include "data/business/data_business_common.h" @@ -28,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_reply_markup.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "settings/business/settings_chat_intro.h" #include "settings/settings_premium.h" #include "ui/chat/chat_style.h" #include "ui/text/text_utilities.h" @@ -237,7 +239,7 @@ bool AboutView::refresh() { const auto user = _history->peer->asUser(); const auto info = user ? user->botInfo.get() : nullptr; if (!info) { - if (user && _history->isDisplayedEmpty()) { + if (user && !user->isSelf() && _history->isDisplayedEmpty()) { if (_item) { return false; } else if (user->meRequiresPremiumToWrite() @@ -269,13 +271,16 @@ void AboutView::makeIntro(not_null user) { } void AboutView::make(Data::ChatIntro data) { + const auto text = data + ? tr::lng_action_set_chat_intro(tr::now, lt_from, _history->peer->name()) + : QString(); const auto item = _history->makeMessage({ .id = _history->nextNonHistoryEntryId(), .flags = (MessageFlag::FakeAboutView | MessageFlag::FakeHistoryItem | MessageFlag::Local), .from = _history->peer->id, - }, PreparedServiceText{ { } }); + }, PreparedServiceText{ { text }}); if (data.sticker) { _helloChosen = nullptr; @@ -287,13 +292,26 @@ void AboutView::make(Data::ChatIntro data) { const auto helloChosen = [=](not_null sticker) { setHelloChosen(sticker); }; + const auto handler = [=](ClickContext context) { + const auto my = context.other.value(); + if (const auto controller = my.sessionWindow.get()) { + if (controller->session().premium()) { + controller->showSettings(Settings::ChatIntroId()); + } else { + ShowPremiumPreviewBox( + controller->uiShow(), + PremiumFeature::ChatIntro); + } + } + }; owned->overrideMedia(std::make_unique( owned.get(), GenerateChatIntro(owned.get(), _item.get(), data, helloChosen), HistoryView::MediaGenericDescriptor{ .maxWidth = st::chatIntroWidth, + .serviceLink = std::make_shared(handler), .service = true, - .hideServiceText = true, + .hideServiceText = text.isEmpty(), })); if (!data.sticker && _helloChosen) { data.sticker = _helloChosen; diff --git a/Telegram/SourceFiles/history/view/history_view_service_message.cpp b/Telegram/SourceFiles/history/view/history_view_service_message.cpp index ee07aa326..107bb9416 100644 --- a/Telegram/SourceFiles/history/view/history_view_service_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_service_message.cpp @@ -677,6 +677,8 @@ TextState Service::textState(QPoint point, StateRequest request) const { result.link = same->lnk; } else if (const auto results = item->Get()) { result.link = results->lnk; + } else if (const auto custom = item->Get()) { + result.link = custom->link; } else if (media && data()->showSimilarChannels()) { result = media->textState(mediaPoint, request); } diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp b/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp index 98c3616a8..97ab60180 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_media_generic.cpp @@ -80,6 +80,10 @@ MediaGeneric::MediaGeneric( .object = std::move(part), }); }); + if (descriptor.serviceLink) { + parent->data()->setCustomServiceLink( + std::move(descriptor.serviceLink)); + } } MediaGeneric::~MediaGeneric() { diff --git a/Telegram/SourceFiles/history/view/media/history_view_media_generic.h b/Telegram/SourceFiles/history/view/media/history_view_media_generic.h index 0d16bf40d..bdc9f328f 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_media_generic.h +++ b/Telegram/SourceFiles/history/view/media/history_view_media_generic.h @@ -45,6 +45,7 @@ public: struct MediaGenericDescriptor { int maxWidth = 0; + ClickHandlerPtr serviceLink; bool service = false; bool hideServiceText = false; }; diff --git a/Telegram/SourceFiles/settings/settings_business.cpp b/Telegram/SourceFiles/settings/settings_business.cpp index 0e185869f..e6ae4de18 100644 --- a/Telegram/SourceFiles/settings/settings_business.cpp +++ b/Telegram/SourceFiles/settings/settings_business.cpp @@ -684,7 +684,7 @@ std::vector BusinessFeaturesOrder( return PremiumFeature::BusinessLocation; } else if (s == u"business_bots"_q) { return PremiumFeature::BusinessBots; - } else if (s == u"chat_intro"_q) { + } else if (s == u"business_intro"_q) { return PremiumFeature::ChatIntro; } return PremiumFeature::kCount;