mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Channel message reposts to stories like reposts.
This commit is contained in:
parent
73690d14f7
commit
23cce64d00
4 changed files with 56 additions and 37 deletions
|
@ -119,25 +119,6 @@ struct SameDayRange {
|
||||||
int(base::SafeRound(asin * point.x() + acos * point.y())));
|
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
|
} // namespace
|
||||||
|
|
||||||
class Controller::PhotoPlayback final {
|
class Controller::PhotoPlayback final {
|
||||||
|
@ -898,7 +879,7 @@ void Controller::show(
|
||||||
const auto document = story->document();
|
const auto document = story->document();
|
||||||
_header->show({
|
_header->show({
|
||||||
.peer = peer,
|
.peer = peer,
|
||||||
.repostPeer = story->repostSourcePeer(),
|
.repostPeer = _repostView ? _repostView->fromPeer() : nullptr,
|
||||||
.repostFrom = _repostView ? _repostView->fromName() : nullptr,
|
.repostFrom = _repostView ? _repostView->fromName() : nullptr,
|
||||||
.date = story->date(),
|
.date = story->date(),
|
||||||
.fullIndex = _sliderCount ? _index : 0,
|
.fullIndex = _sliderCount ? _index : 0,
|
||||||
|
@ -1533,7 +1514,7 @@ StoryId Controller::shownId(int index) const {
|
||||||
|
|
||||||
std::unique_ptr<RepostView> Controller::validateRepostView(
|
std::unique_ptr<RepostView> Controller::validateRepostView(
|
||||||
not_null<Data::Story*> story) {
|
not_null<Data::Story*> story) {
|
||||||
return story->repost()
|
return (story->repost() || !story->channelPosts().empty())
|
||||||
? std::make_unique<RepostView>(this, story)
|
? std::make_unique<RepostView>(this, story)
|
||||||
: nullptr;
|
: nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1841,4 +1822,23 @@ object_ptr<Ui::BoxContent> PrepareShortInfoBox(not_null<PeerData*> peer) {
|
||||||
&st::storiesShortInfoBox);
|
&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
|
} // namespace Media::Stories
|
||||||
|
|
|
@ -337,5 +337,8 @@ void ReportRequested(
|
||||||
const style::ReportBox *stOverride = nullptr);
|
const style::ReportBox *stOverride = nullptr);
|
||||||
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareShortInfoBox(
|
[[nodiscard]] object_ptr<Ui::BoxContent> PrepareShortInfoBox(
|
||||||
not_null<PeerData*> peer);
|
not_null<PeerData*> peer);
|
||||||
|
[[nodiscard]] ClickHandlerPtr MakeChannelPostHandler(
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
FullMsgId item);
|
||||||
|
|
||||||
} // namespace Media::Stories
|
} // namespace Media::Stories
|
||||||
|
|
|
@ -32,8 +32,18 @@ RepostView::RepostView(
|
||||||
not_null<Controller*> controller,
|
not_null<Controller*> controller,
|
||||||
not_null<Data::Story*> story)
|
not_null<Data::Story*> story)
|
||||||
: _controller(controller)
|
: _controller(controller)
|
||||||
, _story(story) {
|
, _story(story)
|
||||||
Expects(_story->repost());
|
, _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(
|
_story->session().colorIndicesValue(
|
||||||
) | rpl::start_with_next([=](Ui::ColorIndicesCompressed &&indices) {
|
) | 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 w = _lastWidth = std::min(int(_maxWidth), availableWidth);
|
||||||
const auto h = height() - (simple ? st::normalFont->height : 0);
|
const auto h = height() - (simple ? st::normalFont->height : 0);
|
||||||
const auto rect = QRect(x, y, w, h);
|
const auto rect = QRect(x, y, w, h);
|
||||||
const auto colorPeer = _story->repostSourcePeer();
|
const auto backgroundEmojiId = (!simple && _sourcePeer)
|
||||||
const auto backgroundEmojiId = (!simple && colorPeer)
|
? _sourcePeer->backgroundEmojiId()
|
||||||
? colorPeer->backgroundEmojiId()
|
|
||||||
: DocumentId();
|
: DocumentId();
|
||||||
const auto cache = &_quoteCache;
|
const auto cache = &_quoteCache;
|
||||||
const auto "eSt = simple
|
const auto "eSt = simple
|
||||||
|
@ -183,19 +192,23 @@ RepostClickHandler RepostView::lookupHandler(QPoint position) {
|
||||||
return { _link, this };
|
return { _link, this };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PeerData *RepostView::fromPeer() const {
|
||||||
|
return _sourcePeer;
|
||||||
|
}
|
||||||
|
|
||||||
QString RepostView::fromName() const {
|
QString RepostView::fromName() const {
|
||||||
const auto sender = _story->repostSourcePeer();
|
return _sourcePeer ? _sourcePeer->name() : _story->repostSourceName();
|
||||||
return sender ? sender->name() : _story->repostSourceName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RepostView::recountDimensions() {
|
void RepostView::recountDimensions() {
|
||||||
const auto sender = _story->repostSourcePeer();
|
const auto name = _sourcePeer
|
||||||
const auto name = sender ? sender->name() : _story->repostSourceName();
|
? _sourcePeer->name()
|
||||||
|
: _story->repostSourceName();
|
||||||
const auto owner = &_story->owner();
|
const auto owner = &_story->owner();
|
||||||
const auto repostId = _story->repostSourceId();
|
const auto repostId = _story->repost() ? _story->repostSourceId() : 0;
|
||||||
|
|
||||||
const auto colorIndexPlusOne = sender
|
const auto colorIndexPlusOne = _sourcePeer
|
||||||
? (sender->colorIndex() + 1)
|
? (_sourcePeer->colorIndex() + 1)
|
||||||
: 1;
|
: 1;
|
||||||
const auto dark = true;
|
const auto dark = true;
|
||||||
const auto colorPattern = colorIndexPlusOne
|
const auto colorPattern = colorIndexPlusOne
|
||||||
|
@ -211,8 +224,9 @@ void RepostView::recountDimensions() {
|
||||||
|
|
||||||
auto text = TextWithEntities();
|
auto text = TextWithEntities();
|
||||||
auto unavailable = false;
|
auto unavailable = false;
|
||||||
if (sender && repostId) {
|
if (_sourcePeer && repostId) {
|
||||||
const auto of = owner->stories().lookup({ sender->id, repostId });
|
const auto senderId = _sourcePeer->id;
|
||||||
|
const auto of = owner->stories().lookup({ senderId, repostId });
|
||||||
unavailable = !of && (of.error() == Data::NoStory::Deleted);
|
unavailable = !of && (of.error() == Data::NoStory::Deleted);
|
||||||
if (of) {
|
if (of) {
|
||||||
text = (*of)->caption();
|
text = (*of)->caption();
|
||||||
|
@ -221,12 +235,12 @@ void RepostView::recountDimensions() {
|
||||||
_maxWidth = 0;
|
_maxWidth = 0;
|
||||||
_controller->repaint();
|
_controller->repaint();
|
||||||
});
|
});
|
||||||
owner->stories().resolve({ sender->id, repostId }, done);
|
owner->stories().resolve({ _sourcePeer->id, repostId }, done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nameFull = TextWithEntities();
|
auto nameFull = TextWithEntities();
|
||||||
nameFull.append(HistoryView::Reply::PeerEmoji(owner, sender));
|
nameFull.append(HistoryView::Reply::PeerEmoji(owner, _sourcePeer));
|
||||||
nameFull.append(name);
|
nameFull.append(name);
|
||||||
auto context = Core::MarkedTextContext{
|
auto context = Core::MarkedTextContext{
|
||||||
.session = &_story->session(),
|
.session = &_story->session(),
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
void draw(Painter &p, int x, int y, int availableWidth);
|
void draw(Painter &p, int x, int y, int availableWidth);
|
||||||
[[nodiscard]] RepostClickHandler lookupHandler(QPoint position);
|
[[nodiscard]] RepostClickHandler lookupHandler(QPoint position);
|
||||||
|
|
||||||
|
[[nodiscard]] PeerData *fromPeer() const;
|
||||||
[[nodiscard]] QString fromName() const;
|
[[nodiscard]] QString fromName() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -49,6 +50,7 @@ private:
|
||||||
|
|
||||||
const not_null<Controller*> _controller;
|
const not_null<Controller*> _controller;
|
||||||
const not_null<Data::Story*> _story;
|
const not_null<Data::Story*> _story;
|
||||||
|
PeerData *_sourcePeer = nullptr;
|
||||||
ClickHandlerPtr _link;
|
ClickHandlerPtr _link;
|
||||||
std::unique_ptr<Ui::RippleAnimation> _ripple;
|
std::unique_ptr<Ui::RippleAnimation> _ripple;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue