diff --git a/Telegram/SourceFiles/media/stories/media_stories_controller.cpp b/Telegram/SourceFiles/media/stories/media_stories_controller.cpp index d6d735043..76e880664 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_controller.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_controller.cpp @@ -119,25 +119,6 @@ struct SameDayRange { int(base::SafeRound(asin * point.x() + acos * point.y()))); } -[[nodiscard]] ClickHandlerPtr MakeChannelPostHandler( - not_null session, - FullMsgId item) { - return std::make_shared(crl::guard(session, [=] { - const auto peer = session->data().peer(item.peer); - if (const auto window = Core::App().windowFor(peer)) { - if (const auto controller = window->sessionController()) { - if (&controller->session() == &peer->session()) { - Core::App().hideMediaView(); - controller->showPeerHistory( - item.peer, - Window::SectionShow::Way::ClearStack, - item.msg); - } - } - } - })); -} - } // namespace class Controller::PhotoPlayback final { @@ -898,7 +879,7 @@ void Controller::show( const auto document = story->document(); _header->show({ .peer = peer, - .repostPeer = story->repostSourcePeer(), + .repostPeer = _repostView ? _repostView->fromPeer() : nullptr, .repostFrom = _repostView ? _repostView->fromName() : nullptr, .date = story->date(), .fullIndex = _sliderCount ? _index : 0, @@ -1533,7 +1514,7 @@ StoryId Controller::shownId(int index) const { std::unique_ptr Controller::validateRepostView( not_null story) { - return story->repost() + return (story->repost() || !story->channelPosts().empty()) ? std::make_unique(this, story) : nullptr; } @@ -1841,4 +1822,23 @@ object_ptr PrepareShortInfoBox(not_null peer) { &st::storiesShortInfoBox); } +ClickHandlerPtr MakeChannelPostHandler( + not_null session, + FullMsgId item) { + return std::make_shared(crl::guard(session, [=] { + const auto peer = session->data().peer(item.peer); + if (const auto window = Core::App().windowFor(peer)) { + if (const auto controller = window->sessionController()) { + if (&controller->session() == &peer->session()) { + Core::App().hideMediaView(); + controller->showPeerHistory( + item.peer, + Window::SectionShow::Way::ClearStack, + item.msg); + } + } + } + })); +} + } // namespace Media::Stories diff --git a/Telegram/SourceFiles/media/stories/media_stories_controller.h b/Telegram/SourceFiles/media/stories/media_stories_controller.h index 8943a9e84..0a6c4a8fe 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_controller.h +++ b/Telegram/SourceFiles/media/stories/media_stories_controller.h @@ -337,5 +337,8 @@ void ReportRequested( const style::ReportBox *stOverride = nullptr); [[nodiscard]] object_ptr PrepareShortInfoBox( not_null peer); +[[nodiscard]] ClickHandlerPtr MakeChannelPostHandler( + not_null session, + FullMsgId item); } // namespace Media::Stories diff --git a/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp b/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp index 6b65ea45b..dd5c55ea7 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp +++ b/Telegram/SourceFiles/media/stories/media_stories_repost_view.cpp @@ -32,8 +32,18 @@ RepostView::RepostView( not_null controller, not_null story) : _controller(controller) -, _story(story) { - Expects(_story->repost()); +, _story(story) +, _sourcePeer(_story->repost() + ? _story->repostSourcePeer() + : _story->owner().peer( + _story->channelPosts().front().itemId.peer).get()) { + Expects(_story->repost() || !_story->channelPosts().empty()); + + if (!_story->repost()) { + _link = MakeChannelPostHandler( + &_story->session(), + _story->channelPosts().front().itemId); + } _story->session().colorIndicesValue( ) | rpl::start_with_next([=](Ui::ColorIndicesCompressed &&indices) { @@ -67,9 +77,8 @@ void RepostView::draw(Painter &p, int x, int y, int availableWidth) { const auto w = _lastWidth = std::min(int(_maxWidth), availableWidth); const auto h = height() - (simple ? st::normalFont->height : 0); const auto rect = QRect(x, y, w, h); - const auto colorPeer = _story->repostSourcePeer(); - const auto backgroundEmojiId = (!simple && colorPeer) - ? colorPeer->backgroundEmojiId() + const auto backgroundEmojiId = (!simple && _sourcePeer) + ? _sourcePeer->backgroundEmojiId() : DocumentId(); const auto cache = &_quoteCache; const auto "eSt = simple @@ -183,19 +192,23 @@ RepostClickHandler RepostView::lookupHandler(QPoint position) { return { _link, this }; } +PeerData *RepostView::fromPeer() const { + return _sourcePeer; +} + QString RepostView::fromName() const { - const auto sender = _story->repostSourcePeer(); - return sender ? sender->name() : _story->repostSourceName(); + return _sourcePeer ? _sourcePeer->name() : _story->repostSourceName(); } void RepostView::recountDimensions() { - const auto sender = _story->repostSourcePeer(); - const auto name = sender ? sender->name() : _story->repostSourceName(); + const auto name = _sourcePeer + ? _sourcePeer->name() + : _story->repostSourceName(); const auto owner = &_story->owner(); - const auto repostId = _story->repostSourceId(); + const auto repostId = _story->repost() ? _story->repostSourceId() : 0; - const auto colorIndexPlusOne = sender - ? (sender->colorIndex() + 1) + const auto colorIndexPlusOne = _sourcePeer + ? (_sourcePeer->colorIndex() + 1) : 1; const auto dark = true; const auto colorPattern = colorIndexPlusOne @@ -211,8 +224,9 @@ void RepostView::recountDimensions() { auto text = TextWithEntities(); auto unavailable = false; - if (sender && repostId) { - const auto of = owner->stories().lookup({ sender->id, repostId }); + if (_sourcePeer && repostId) { + const auto senderId = _sourcePeer->id; + const auto of = owner->stories().lookup({ senderId, repostId }); unavailable = !of && (of.error() == Data::NoStory::Deleted); if (of) { text = (*of)->caption(); @@ -221,12 +235,12 @@ void RepostView::recountDimensions() { _maxWidth = 0; _controller->repaint(); }); - owner->stories().resolve({ sender->id, repostId }, done); + owner->stories().resolve({ _sourcePeer->id, repostId }, done); } } auto nameFull = TextWithEntities(); - nameFull.append(HistoryView::Reply::PeerEmoji(owner, sender)); + nameFull.append(HistoryView::Reply::PeerEmoji(owner, _sourcePeer)); nameFull.append(name); auto context = Core::MarkedTextContext{ .session = &_story->session(), diff --git a/Telegram/SourceFiles/media/stories/media_stories_repost_view.h b/Telegram/SourceFiles/media/stories/media_stories_repost_view.h index f98fe0350..a77569df2 100644 --- a/Telegram/SourceFiles/media/stories/media_stories_repost_view.h +++ b/Telegram/SourceFiles/media/stories/media_stories_repost_view.h @@ -38,6 +38,7 @@ public: void draw(Painter &p, int x, int y, int availableWidth); [[nodiscard]] RepostClickHandler lookupHandler(QPoint position); + [[nodiscard]] PeerData *fromPeer() const; [[nodiscard]] QString fromName() const; private: @@ -49,6 +50,7 @@ private: const not_null _controller; const not_null _story; + PeerData *_sourcePeer = nullptr; ClickHandlerPtr _link; std::unique_ptr _ripple;