From 83ec4498900f754fd50cfbf0ab0792e8789659b7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 1 Nov 2022 12:04:16 +0400 Subject: [PATCH] Display topic title in topic-root reply bars. --- .../SourceFiles/history/history_service.cpp | 44 +++++++++++++------ .../history/view/history_view_element.cpp | 23 +++++----- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/history/history_service.cpp b/Telegram/SourceFiles/history/history_service.cpp index a594913a2..6e85e8a72 100644 --- a/Telegram/SourceFiles/history/history_service.cpp +++ b/Telegram/SourceFiles/history/history_service.cpp @@ -636,25 +636,39 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { return result; }; + const auto wrapTopicIcon = [](DocumentId id) { + return TextWithEntities{ + "@", + { EntityInText( + EntityType::CustomEmoji, + 0, + 1, + Data::SerializeCustomEmojiId({ .id = id })) + }, + }; + }; + auto prepareTopicCreate = [&](const MTPDmessageActionTopicCreate &action) { auto result = PreparedText{}; - result.text = { tr::lng_action_topic_created_inside(tr::now) }; + auto title = TextWithEntities{ + qs(action.vtitle()) + }; + if (const auto icon = action.vicon_emoji_id().value_or_empty()) { + title = wrapTopicIcon(icon).append(' ').append(std::move(title)); + } + const auto topicUrl = u"internal:url:https://t.me/c/%1/%2"_q + .arg(peerToChannel(history()->peer->id).bare) + .arg(id.bare); + result.text = tr::lng_action_topic_created( + tr::now, + lt_topic, + Ui::Text::Link(std::move(title), topicUrl), + Ui::Text::WithEntities); return result; }; auto prepareTopicEdit = [&](const MTPDmessageActionTopicEdit &action) { auto result = PreparedText{}; - const auto wrapIcon = [](DocumentId id) { - return TextWithEntities{ - "@", - { EntityInText( - EntityType::CustomEmoji, - 0, - 1, - Data::SerializeCustomEmojiId({ .id = id })) - }, - }; - }; if (const auto closed = action.vclosed()) { result.text = { mtpIsTrue(*closed) ? tr::lng_action_topic_closed_inside(tr::now) @@ -670,7 +684,7 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { lt_link, { tr::lng_action_topic_placeholder(tr::now) }, lt_emoji, - wrapIcon(iconId), + wrapTopicIcon(iconId), Ui::Text::WithEntities); } else { result.links.push_back(fromLink()); @@ -689,7 +703,9 @@ void HistoryService::setMessageByAction(const MTPmessageAction &action) { qs(*action.vtitle()) }; if (const auto icon = action.vicon_emoji_id().value_or_empty()) { - title = wrapIcon(icon).append(' ').append(std::move(title)); + title = wrapTopicIcon(icon) + .append(' ') + .append(std::move(title)); } result.text = tr::lng_action_topic_renamed( tr::now, diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index 659b0ea3a..74fb27ff8 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -667,14 +667,23 @@ int Element::textHeightFor(int textWidth) { } auto Element::contextDependentServiceText() -> TextWithLinks { - if (_delegate->elementContext() == Context::Replies) { - return {}; - } const auto item = data(); const auto info = item->Get(); if (!info) { return {}; } + const auto created = !info->closed + && !info->reopened + && !info->renamed + && !info->reiconed; + if (_delegate->elementContext() == Context::Replies) { + if (created) { + return { { tr::lng_action_topic_created_inside(tr::now) } }; + } + return {}; + } else if (created) { + return{}; + } const auto peerId = item->history()->peer->id; const auto topicRootId = item->topicRootId(); if (!topicRootId || !peerIsChannel(peerId)) { @@ -791,13 +800,7 @@ auto Element::contextDependentServiceText() -> TextWithLinks { }; } } else { - return { - tr::lng_action_topic_created( - tr::now, - lt_topic, - wrapTopic(info->title, info->iconId), - Ui::Text::WithEntities), - }; + return {}; } }