Channel message reposts to stories like reposts.

This commit is contained in:
John Preston 2023-12-22 13:16:14 -04:00
parent 73690d14f7
commit 23cce64d00
4 changed files with 56 additions and 37 deletions

View File

@ -119,25 +119,6 @@ struct SameDayRange {
int(base::SafeRound(asin * point.x() + acos * point.y())));
}
[[nodiscard]] ClickHandlerPtr MakeChannelPostHandler(
not_null<Main::Session*> session,
FullMsgId item) {
return std::make_shared<LambdaClickHandler>(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<RepostView> Controller::validateRepostView(
not_null<Data::Story*> story) {
return story->repost()
return (story->repost() || !story->channelPosts().empty())
? std::make_unique<RepostView>(this, story)
: nullptr;
}
@ -1841,4 +1822,23 @@ object_ptr<Ui::BoxContent> PrepareShortInfoBox(not_null<PeerData*> peer) {
&st::storiesShortInfoBox);
}
ClickHandlerPtr MakeChannelPostHandler(
not_null<Main::Session*> session,
FullMsgId item) {
return std::make_shared<LambdaClickHandler>(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

View File

@ -337,5 +337,8 @@ void ReportRequested(
const style::ReportBox *stOverride = nullptr);
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareShortInfoBox(
not_null<PeerData*> peer);
[[nodiscard]] ClickHandlerPtr MakeChannelPostHandler(
not_null<Main::Session*> session,
FullMsgId item);
} // namespace Media::Stories

View File

@ -32,8 +32,18 @@ RepostView::RepostView(
not_null<Controller*> controller,
not_null<Data::Story*> 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 &quoteSt = 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(),

View File

@ -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*> _controller;
const not_null<Data::Story*> _story;
PeerData *_sourcePeer = nullptr;
ClickHandlerPtr _link;
std::unique_ptr<Ui::RippleAnimation> _ripple;