Added spoiler support to service messages.

This commit is contained in:
23rd 2021-12-25 16:43:21 +03:00 committed by John Preston
parent 1d2065e4ef
commit 8b74dc2dec
6 changed files with 17 additions and 19 deletions

View file

@ -1619,7 +1619,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) {
withLocalEntities(textWithEntities), withLocalEntities(textWithEntities),
Ui::ItemTextOptions(this), Ui::ItemTextOptions(this),
context); context);
HistoryView::FillTextWithAnimatedSpoilers(_text, textWithEntities); HistoryView::FillTextWithAnimatedSpoilers(_text);
if (!textWithEntities.text.isEmpty() && _text.isEmpty()) { if (!textWithEntities.text.isEmpty() && _text.isEmpty()) {
// If server has allowed some text that we've trim-ed entirely, // If server has allowed some text that we've trim-ed entirely,
// just replace it with something so that UI won't look buggy. // just replace it with something so that UI won't look buggy.

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "history/view/history_view_service_message.h" #include "history/view/history_view_service_message.h"
#include "history/view/history_view_item_preview.h" #include "history/view/history_view_item_preview.h"
#include "history/view/history_view_spoiler_click_handler.h"
#include "data/data_folder.h" #include "data/data_folder.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_media_types.h" #include "data/data_media_types.h"
@ -695,7 +696,8 @@ HistoryService::PreparedText HistoryService::preparePinnedText() {
result.links.push_back(fromLink()); result.links.push_back(fromLink());
result.links.push_back(pinned->lnk); result.links.push_back(pinned->lnk);
if (mediaText.isEmpty()) { if (mediaText.isEmpty()) {
auto original = pinned->msg->originalText().text; auto original = TextUtilities::TextWithSpoilerCommands(
pinned->msg->originalText());
auto cutAt = 0; auto cutAt = 0;
auto limit = kPinnedMessageTextLimit; auto limit = kPinnedMessageTextLimit;
auto size = original.size(); auto size = original.size();
@ -946,7 +948,9 @@ ItemPreview HistoryService::toPreview(ToPreviewOptions options) const {
// Because larger version is shown exactly to the left of the preview. // Because larger version is shown exactly to the left of the preview.
//auto media = _media ? _media->toPreview(options) : ItemPreview(); //auto media = _media ? _media->toPreview(options) : ItemPreview();
return { return {
.text = textcmdLink(1, TextUtilities::Clean(notificationText())), .text = textcmdLink(
1,
TextUtilities::Clean(notificationText(), true)),
//.images = std::move(media.images), //.images = std::move(media.images),
//.loadingContext = std::move(media.loadingContext), //.loadingContext = std::move(media.loadingContext),
}; };
@ -980,6 +984,7 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
st::serviceTextStyle, st::serviceTextStyle,
prepared.text, prepared.text,
Ui::ItemTextServiceOptions()); Ui::ItemTextServiceOptions());
HistoryView::FillTextWithAnimatedSpoilers(_text);
auto linkIndex = 0; auto linkIndex = 0;
for (const auto &link : prepared.links) { for (const auto &link : prepared.links) {
// Link indices start with 1. // Link indices start with 1.

View file

@ -38,15 +38,11 @@ void AnimatedSpoilerClickHandler::onClick(ClickContext context) const {
} // namespace } // namespace
void FillTextWithAnimatedSpoilers( void FillTextWithAnimatedSpoilers(Ui::Text::String &text) {
Ui::Text::String &text, for (auto i = 0; i < text.spoilersCount(); i++) {
const TextWithEntities &textWithEntities) { text.setSpoiler(
for (auto i = 0; i < textWithEntities.entities.size(); i++) { i + 1,
if (textWithEntities.entities[i].type() == EntityType::Spoiler) { std::make_shared<AnimatedSpoilerClickHandler>());
text.setSpoiler(
i + 1,
std::make_shared<AnimatedSpoilerClickHandler>());
}
} }
} }

View file

@ -9,8 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace HistoryView { namespace HistoryView {
void FillTextWithAnimatedSpoilers( void FillTextWithAnimatedSpoilers(Ui::Text::String &text);
Ui::Text::String &text,
const TextWithEntities &textWithEntities);
} // namespace HistoryView } // namespace HistoryView

View file

@ -197,13 +197,12 @@ Ui::Text::String Media::createCaption(not_null<HistoryItem*> item) const {
const auto context = Core::MarkedTextContext{ const auto context = Core::MarkedTextContext{
.session = &history()->session() .session = &history()->session()
}; };
const auto textWithEntities = item->originalTextWithLocalEntities();
result.setMarkedText( result.setMarkedText(
st::messageTextStyle, st::messageTextStyle,
textWithEntities, item->originalTextWithLocalEntities(),
Ui::ItemTextOptions(item), Ui::ItemTextOptions(item),
context); context);
FillTextWithAnimatedSpoilers(result, textWithEntities); FillTextWithAnimatedSpoilers(result);
if (const auto width = _parent->skipBlockWidth()) { if (const auto width = _parent->skipBlockWidth()) {
result.updateSkipBlock(width, _parent->skipBlockHeight()); result.updateSkipBlock(width, _parent->skipBlockHeight());
} }

@ -1 +1 @@
Subproject commit db871a87f5a2895b6ffdca106ecdff6f710e2b02 Subproject commit 44853e933400a7f1536b9847fd0adc2b7d575bff