From fb4e05405e7c95d6593ef53810b9c36e07d0a0d3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 24 Jul 2023 11:43:20 +0400 Subject: [PATCH] Support and use share comment in stories. --- Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/calls/calls.style | 5 ++++ .../SourceFiles/data/data_media_types.cpp | 21 +++------------ .../history/view/history_view_element.cpp | 8 ++++-- .../history/view/media/history_view_gif.cpp | 22 +++++++-------- .../history/view/media/history_view_gif.h | 2 +- .../history/view/media/history_view_photo.cpp | 25 ++++++++--------- .../history/view/media/history_view_photo.h | 2 +- .../media/stories/media_stories_share.cpp | 27 ++++++++++++------- 9 files changed, 57 insertions(+), 56 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ce176c6d1e..8ebc760054 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1710,6 +1710,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_forwarded" = "Forwarded from {user}"; "lng_forwarded_story" = "Story from {user}"; +"lng_forwarded_story_expired" = "This story has expired."; "lng_forwarded_date" = "Original: {date}"; "lng_forwarded_channel" = "Forwarded from {channel}"; "lng_forwarded_psa_default" = "Forwarded from {channel}"; diff --git a/Telegram/SourceFiles/calls/calls.style b/Telegram/SourceFiles/calls/calls.style index 28b5f90a6e..c8f287328d 100644 --- a/Telegram/SourceFiles/calls/calls.style +++ b/Telegram/SourceFiles/calls/calls.style @@ -744,6 +744,11 @@ groupCallShareBoxComment: InputField(groupCallField) { } groupCallShareBoxList: PeerList(groupCallMembersList) { item: PeerListItem(groupCallMembersListItem) { + nameStyle: TextStyle(defaultTextStyle) { + font: font(11px); + linkFont: font(11px); + linkFontOver: font(11px); + } checkbox: RoundImageCheckbox(groupCallMembersListCheckbox) { imageRadius: 28px; imageSmallRadius: 24px; diff --git a/Telegram/SourceFiles/data/data_media_types.cpp b/Telegram/SourceFiles/data/data_media_types.cpp index 19d89c500f..e623df3a54 100644 --- a/Telegram/SourceFiles/data/data_media_types.cpp +++ b/Telegram/SourceFiles/data/data_media_types.cpp @@ -1995,18 +1995,11 @@ MediaStory::MediaStory( owner->registerStoryItem(storyId, parent); const auto stories = &owner->stories(); - if (const auto maybeStory = stories->lookup(storyId)) { - if (!_mention) { - parent->setText((*maybeStory)->caption()); - } - } else { + const auto maybeStory = stories->lookup(storyId); + if (!maybeStory) { if (maybeStory.error() == NoStory::Unknown) { stories->resolve(storyId, crl::guard(this, [=] { - if (const auto maybeStory = stories->lookup(storyId)) { - if (!_mention) { - parent->setText((*maybeStory)->caption()); - } - } else { + if (!stories->lookup(storyId)) { _expired = true; } if (_mention) { @@ -2058,9 +2051,7 @@ TextWithEntities MediaStory::notificationText() const { && maybeStory.error() == Data::NoStory::Deleted)) ? tr::lng_in_dlg_story_expired : tr::lng_in_dlg_story)(tr::now), - (maybeStory - ? (*maybeStory)->caption() - : TextWithEntities())); + parent()->originalText()); } QString MediaStory::pinnedTextSubstring() const { @@ -2100,9 +2091,6 @@ std::unique_ptr MediaStory::createView( const auto stories = &parent()->history()->owner().stories(); const auto maybeStory = stories->lookup(_storyId); if (!maybeStory) { - if (!_mention) { - realParent->setText(TextWithEntities()); - } if (maybeStory.error() == Data::NoStory::Deleted) { _expired = true; return nullptr; @@ -2124,7 +2112,6 @@ std::unique_ptr MediaStory::createView( message, std::make_unique(message, story)); } else { - realParent->setText(story->caption()); if (const auto photo = story->photo()) { return std::make_unique( message, diff --git a/Telegram/SourceFiles/history/view/history_view_element.cpp b/Telegram/SourceFiles/history/view/history_view_element.cpp index f20499bb9a..f86159d385 100644 --- a/Telegram/SourceFiles/history/view/history_view_element.cpp +++ b/Telegram/SourceFiles/history/view/history_view_element.cpp @@ -846,8 +846,12 @@ void Element::validateText() { _media = nullptr; if (!storyMention) { if (_text.isEmpty()) { - setTextWithLinks( - Ui::Text::Italic(u"This story has expired"_q)); + auto now = Ui::Text::Italic( + tr::lng_forwarded_story_expired(tr::now)); + if (!text.empty()) { + now.append(u"\n\n"_q).append(text); + } + setTextWithLinks(std::move(now)); } return; } diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index d3040ce07c..0bee2fbf09 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -88,14 +88,13 @@ Gif::Gif( bool spoiler) : File(parent, realParent) , _data(document) -, _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) +, _storyId(realParent->media() + ? realParent->media()->storyId() + : FullStoryId()) +, _caption( + st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) , _spoiler(spoiler ? std::make_unique() : nullptr) , _downloadSize(Ui::FormatSizeText(_data->size)) { - if (const auto media = realParent->media()) { - if (media->storyId()) { - _story = true; - } - } setDocumentLinks(_data, realParent, [=] { if (!_data->createMediaView()->canBePlayed(realParent) || !_data->isAnimation() @@ -1438,15 +1437,14 @@ void Gif::dataMediaCreated() const { } void Gif::togglePollingStory(bool enabled) const { - if (!_story || _pollingStory == enabled) { + if (!_storyId || _pollingStory == enabled) { return; } const auto polling = Data::Stories::Polling::Chat; - const auto media = _parent->data()->media(); - const auto id = media ? media->storyId() : FullStoryId(); if (!enabled) { - _data->owner().stories().unregisterPolling(id, polling); - } else if (!_data->owner().stories().registerPolling(id, polling)) { + _data->owner().stories().unregisterPolling(_storyId, polling); + } else if ( + !_data->owner().stories().registerPolling(_storyId, polling)) { return; } _pollingStory = enabled; @@ -1464,7 +1462,7 @@ void Gif::hideSpoilers() { } bool Gif::needsBubble() const { - if (_story) { + if (_storyId) { return true; } else if (_data->isVideoMessage()) { return false; diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.h b/Telegram/SourceFiles/history/view/media/history_view_gif.h index 50c5583acb..c737d23914 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.h +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.h @@ -211,6 +211,7 @@ private: void togglePollingStory(bool enabled) const; const not_null _data; + const FullStoryId _storyId; Ui::Text::String _caption; std::unique_ptr _streamed; const std::unique_ptr _spoiler; @@ -223,7 +224,6 @@ private: mutable std::optional _thumbCacheRounding; mutable bool _thumbCacheBlurred : 1 = false; mutable bool _thumbIsEllipse : 1 = false; - mutable bool _story : 1 = false; mutable bool _pollingStory : 1 = false; }; diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp index ed5c49ac97..a5cf0f41c9 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.cpp @@ -69,13 +69,11 @@ Photo::Photo( bool spoiler) : File(parent, realParent) , _data(photo) +, _storyId(realParent->media() + ? realParent->media()->storyId() + : FullStoryId()) , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) , _spoiler(spoiler ? std::make_unique() : nullptr) { - if (const auto media = realParent->media()) { - if (media->storyId()) { - _story = 1; - } - } _caption = createCaption(realParent); create(realParent->fullId()); } @@ -168,15 +166,14 @@ void Photo::unloadHeavyPart() { void Photo::togglePollingStory(bool enabled) const { const auto pollingStory = (enabled ? 1 : 0); - if (!_story || _pollingStory == pollingStory) { + if (!_storyId || _pollingStory == pollingStory) { return; } const auto polling = Data::Stories::Polling::Chat; - const auto media = _parent->data()->media(); - const auto id = media ? media->storyId() : FullStoryId(); if (!enabled) { - _data->owner().stories().unregisterPolling(id, polling); - } else if (!_data->owner().stories().registerPolling(id, polling)) { + _data->owner().stories().unregisterPolling(_storyId, polling); + } else if ( + !_data->owner().stories().registerPolling(_storyId, polling)) { return; } _pollingStory = pollingStory; @@ -285,7 +282,7 @@ int Photo::adjustHeightForLessCrop(QSize dimensions, QSize current) const { void Photo::draw(Painter &p, const PaintContext &context) const { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { return; - } else if (_story && _data->isNull()) { + } else if (_storyId && _data->isNull()) { return; } @@ -623,7 +620,7 @@ void Photo::paintUserpicFrame( } QSize Photo::photoSize() const { - if (_story) { + if (_storyId) { return { kStoryWidth, kStoryHeight }; } return QSize(_data->width(), _data->height()); @@ -634,7 +631,7 @@ TextState Photo::textState(QPoint point, StateRequest request) const { if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) { return result; - } else if (_story && _data->isNull()) { + } else if (_storyId && _data->isNull()) { return result; } auto paintx = 0, painty = 0, paintw = width(), painth = height(); @@ -1054,7 +1051,7 @@ void Photo::hideSpoilers() { } bool Photo::needsBubble() const { - if (_story || !_caption.isEmpty()) { + if (_storyId || !_caption.isEmpty()) { return true; } const auto item = _parent->data(); diff --git a/Telegram/SourceFiles/history/view/media/history_view_photo.h b/Telegram/SourceFiles/history/view/media/history_view_photo.h index 94404ddbe0..cfe9e9627b 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_photo.h +++ b/Telegram/SourceFiles/history/view/media/history_view_photo.h @@ -163,6 +163,7 @@ private: void togglePollingStory(bool enabled) const; const not_null _data; + const FullStoryId _storyId; Ui::Text::String _caption; mutable std::shared_ptr _dataMedia; mutable std::unique_ptr _streamed; @@ -172,7 +173,6 @@ private: uint32 _serviceWidth : 28 = 0; mutable uint32 _imageCacheForum : 1 = 0; mutable uint32 _imageCacheBlurred : 1 = 0; - mutable uint32 _story : 1 = 0; mutable uint32 _pollingStory : 1 = 0; }; diff --git a/Telegram/SourceFiles/media/stories/media_stories_share.cpp b/Telegram/SourceFiles/media/stories/media_stories_share.cpp index 413fbf3d16..d6fe67adc5 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_share.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_share.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "media/stories/media_stories_share.h" #include "api/api_common.h" +#include "api/api_text_entities.h" #include "apiwrap.h" #include "base/random.h" #include "boxes/share_box.h" @@ -86,7 +87,7 @@ namespace Media::Stories { for (const auto thread : result) { const auto error = GetErrorTextForSending( thread, - { .story = story, .text = &comment }); + { .story = story }); if (!error.isEmpty()) { return std::make_pair(error, thread); } @@ -105,16 +106,21 @@ namespace Media::Stories { return; } + auto caption = TextWithEntities{ + comment.text, + TextUtilities::ConvertTextTagsToEntities(comment.tags) + }; + TextUtilities::Trim(caption); + auto sentEntities = Api::EntitiesToMTP( + session, + caption.entities, + Api::ConvertOption::SkipLocal); + const auto captionText = caption.text; + const auto api = &story->owner().session().api(); auto &histories = story->owner().histories(); for (const auto thread : result) { const auto action = Api::SendAction(thread, options); - if (!comment.text.isEmpty()) { - auto message = Api::MessageToSend(action); - message.textWithTags = comment; - message.action.clearDraft = false; - api->sendMessage(std::move(message)); - } const auto peer = thread->peer(); const auto threadHistory = thread->owningHistory(); const auto randomId = base::RandomValue(); @@ -126,6 +132,9 @@ namespace Media::Stories { if (silentPost) { sendFlags |= MTPmessages_SendMedia::Flag::f_silent; } + if (!sentEntities.v.isEmpty()) { + sendFlags |= MTPmessages_SendMedia::Flag::f_entities; + } const auto done = [=] { if (!--state->requests) { if (show->valid()) { @@ -145,10 +154,10 @@ namespace Media::Stories { MTP_inputMediaStory( user->inputUser, MTP_int(id.story)), - MTPstring(), + MTP_string(captionText), MTP_long(randomId), MTPReplyMarkup(), - MTPVector(), + sentEntities, MTP_int(action.options.scheduled), MTP_inputPeerEmpty() ), [=](const MTPUpdates &result, const MTP::Response &response) {