mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added ability to open specific post from sponsored messages.
This commit is contained in:
parent
d8fb5be9b5
commit
c2b505b78c
3 changed files with 28 additions and 1 deletions
|
@ -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<Entry>::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
|
||||
|
|
|
@ -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*> history);
|
||||
[[nodiscard]] bool append(not_null<History*> history);
|
||||
void clearItems(not_null<History*> history);
|
||||
[[nodiscard]] MsgId channelPost(const FullMsgId &fullId) const;
|
||||
|
||||
private:
|
||||
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
||||
|
|
|
@ -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<PeerData*> peer, Fn<void()> updateCallback)
|
|||
, link(std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
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))
|
||||
|
|
Loading…
Add table
Reference in a new issue