Show description about custom chat intro.

This commit is contained in:
John Preston 2024-03-22 10:38:52 +04:00
parent 1e1a48865f
commit 3a5b3ff3bd
9 changed files with 42 additions and 4 deletions

View file

@ -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";

View file

@ -1549,6 +1549,11 @@ void HistoryItem::setRealShortcutId(BusinessShortcutId id) {
_shortcutId = id;
}
void HistoryItem::setCustomServiceLink(ClickHandlerPtr link) {
AddComponents(HistoryServiceCustomLink::Bit());
Get<HistoryServiceCustomLink>()->link = std::move(link);
}
void HistoryItem::destroy() {
_history->destroyMessage(this);
}
@ -4849,6 +4854,7 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) {
prepareGiveawayLaunch,
prepareGiveawayResults,
prepareBoostApply,
PrepareEmptyText<MTPDmessageActionRequestedPeerSentMe>,
PrepareErrorText<MTPDmessageActionEmpty>));
// Additional information.

View file

@ -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,

View file

@ -629,6 +629,11 @@ struct HistoryServiceGiveawayResults
, public HistoryServiceDependentData {
};
struct HistoryServiceCustomLink
: public RuntimeComponent<HistoryServiceCustomLink, HistoryItem> {
ClickHandlerPtr link;
};
enum class HistorySelfDestructType {
Photo,
Video,

View file

@ -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<UserData*> 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<DocumentData*> sticker) {
setHelloChosen(sticker);
};
const auto handler = [=](ClickContext context) {
const auto my = context.other.value<ClickHandlerContext>();
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<HistoryView::MediaGeneric>(
owned.get(),
GenerateChatIntro(owned.get(), _item.get(), data, helloChosen),
HistoryView::MediaGenericDescriptor{
.maxWidth = st::chatIntroWidth,
.serviceLink = std::make_shared<LambdaClickHandler>(handler),
.service = true,
.hideServiceText = true,
.hideServiceText = text.isEmpty(),
}));
if (!data.sticker && _helloChosen) {
data.sticker = _helloChosen;

View file

@ -677,6 +677,8 @@ TextState Service::textState(QPoint point, StateRequest request) const {
result.link = same->lnk;
} else if (const auto results = item->Get<HistoryServiceGiveawayResults>()) {
result.link = results->lnk;
} else if (const auto custom = item->Get<HistoryServiceCustomLink>()) {
result.link = custom->link;
} else if (media && data()->showSimilarChannels()) {
result = media->textState(mediaPoint, request);
}

View file

@ -80,6 +80,10 @@ MediaGeneric::MediaGeneric(
.object = std::move(part),
});
});
if (descriptor.serviceLink) {
parent->data()->setCustomServiceLink(
std::move(descriptor.serviceLink));
}
}
MediaGeneric::~MediaGeneric() {

View file

@ -45,6 +45,7 @@ public:
struct MediaGenericDescriptor {
int maxWidth = 0;
ClickHandlerPtr serviceLink;
bool service = false;
bool hideServiceText = false;
};

View file

@ -684,7 +684,7 @@ std::vector<PremiumFeature> 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;