diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.cpp b/Telegram/SourceFiles/data/data_sponsored_messages.cpp index 448dea62a..18f47510e 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.cpp +++ b/Telegram/SourceFiles/data/data_sponsored_messages.cpp @@ -153,6 +153,7 @@ void SponsoredMessages::append( data.ventities().value_or_empty()), }, .history = history, + //.msgId = data.vchannel_post().value_or_empty(), }; list.entries.push_back({ nullptr, std::move(sharedMessage) }); }); @@ -193,4 +194,22 @@ void SponsoredMessages::view(const std::vector::iterator entryIt) { }).send(); } +MsgId SponsoredMessages::channelPost(const FullMsgId &fullId) const { + const auto history = _session->data().history( + peerFromChannel(fullId.channel)); + const auto it = _data.find(history); + if (it == end(_data)) { + return ShowAtUnreadMsgId; + } + auto &list = it->second; + const auto entryIt = ranges::find_if(list.entries, [&](const Entry &e) { + return e.item->fullId() == fullId; + }); + if (entryIt == end(list.entries)) { + return ShowAtUnreadMsgId; + } + const auto msgId = entryIt->sponsored.msgId; + return msgId ? msgId : ShowAtUnreadMsgId; +} + } // namespace Data diff --git a/Telegram/SourceFiles/data/data_sponsored_messages.h b/Telegram/SourceFiles/data/data_sponsored_messages.h index b6115e59b..475c3c20a 100644 --- a/Telegram/SourceFiles/data/data_sponsored_messages.h +++ b/Telegram/SourceFiles/data/data_sponsored_messages.h @@ -25,6 +25,7 @@ struct SponsoredMessage final { PeerId fromId; TextWithEntities textWithEntities; History *history = nullptr; + MsgId msgId; }; class SponsoredMessages final { @@ -38,6 +39,7 @@ public: void request(not_null history); [[nodiscard]] bool append(not_null history); void clearItems(not_null history); + [[nodiscard]] MsgId channelPost(const FullMsgId &fullId) const; private: using OwnedItem = std::unique_ptr; diff --git a/Telegram/SourceFiles/history/view/history_view_view_button.cpp b/Telegram/SourceFiles/history/view/history_view_view_button.cpp index ff444a8d2..85f90b5d3 100644 --- a/Telegram/SourceFiles/history/view/history_view_view_button.cpp +++ b/Telegram/SourceFiles/history/view/history_view_view_button.cpp @@ -8,9 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_view_button.h" #include "core/click_handler_types.h" +#include "data/data_session.h" +#include "data/data_sponsored_messages.h" #include "data/data_user.h" #include "history/view/history_view_cursor_state.h" #include "lang/lang_keys.h" +#include "main/main_session.h" #include "ui/click_handler.h" #include "ui/effects/ripple_animation.h" #include "ui/round_rect.h" @@ -60,7 +63,10 @@ ViewButton::Inner::Inner(not_null peer, Fn updateCallback) , link(std::make_shared([=](ClickContext context) { const auto my = context.other.value(); if (const auto controller = my.sessionWindow.get()) { - controller->showPeer(peer); + const auto &data = controller->session().data(); + controller->showPeer( + peer, + data.sponsoredMessages().channelPost(my.itemId)); } })) , updateCallback(std::move(updateCallback))