From bd4cf824056e8761191283863a0bf0014867af53 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 28 Sep 2023 23:48:45 +0400 Subject: [PATCH] Don't highlight links in non-premium stories. --- Telegram/SourceFiles/data/data_story.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Telegram/SourceFiles/data/data_story.cpp b/Telegram/SourceFiles/data/data_story.cpp index 237c3323d..13c453e06 100644 --- a/Telegram/SourceFiles/data/data_story.cpp +++ b/Telegram/SourceFiles/data/data_story.cpp @@ -43,6 +43,19 @@ using UpdateFlag = StoryUpdate::Flag; }; } +[[nodiscard]] TextWithEntities StripLinks(TextWithEntities text) { + const auto link = [&](const EntityInText &entity) { + return (entity.type() == EntityType::CustomUrl) + || (entity.type() == EntityType::Url) + || (entity.type() == EntityType::Mention) + || (entity.type() == EntityType::Hashtag); + }; + text.entities.erase( + ranges::remove_if(text.entities, link), + text.entities.end()); + return text; +} + [[nodiscard]] auto ParseLocation(const MTPMediaArea &area) -> std::optional { auto result = std::optional(); @@ -586,6 +599,11 @@ void Story::applyFields( &owner().session(), data.ventities().value_or_empty()), }; + if (const auto user = _peer->asUser()) { + if (!user->isVerified() && !user->isPremium()) { + caption = StripLinks(std::move(caption)); + } + } auto counts = ViewsCounts(); auto viewsKnown = _views.known; if (const auto info = data.vviews()) {