mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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()),
|
data.ventities().value_or_empty()),
|
||||||
},
|
},
|
||||||
.history = history,
|
.history = history,
|
||||||
|
//.msgId = data.vchannel_post().value_or_empty(),
|
||||||
};
|
};
|
||||||
list.entries.push_back({ nullptr, std::move(sharedMessage) });
|
list.entries.push_back({ nullptr, std::move(sharedMessage) });
|
||||||
});
|
});
|
||||||
|
@ -193,4 +194,22 @@ void SponsoredMessages::view(const std::vector<Entry>::iterator entryIt) {
|
||||||
}).send();
|
}).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
|
} // namespace Data
|
||||||
|
|
|
@ -25,6 +25,7 @@ struct SponsoredMessage final {
|
||||||
PeerId fromId;
|
PeerId fromId;
|
||||||
TextWithEntities textWithEntities;
|
TextWithEntities textWithEntities;
|
||||||
History *history = nullptr;
|
History *history = nullptr;
|
||||||
|
MsgId msgId;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SponsoredMessages final {
|
class SponsoredMessages final {
|
||||||
|
@ -38,6 +39,7 @@ public:
|
||||||
void request(not_null<History*> history);
|
void request(not_null<History*> history);
|
||||||
[[nodiscard]] bool append(not_null<History*> history);
|
[[nodiscard]] bool append(not_null<History*> history);
|
||||||
void clearItems(not_null<History*> history);
|
void clearItems(not_null<History*> history);
|
||||||
|
[[nodiscard]] MsgId channelPost(const FullMsgId &fullId) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>;
|
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 "history/view/history_view_view_button.h"
|
||||||
|
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
|
#include "data/data_session.h"
|
||||||
|
#include "data/data_sponsored_messages.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "history/view/history_view_cursor_state.h"
|
#include "history/view/history_view_cursor_state.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "main/main_session.h"
|
||||||
#include "ui/click_handler.h"
|
#include "ui/click_handler.h"
|
||||||
#include "ui/effects/ripple_animation.h"
|
#include "ui/effects/ripple_animation.h"
|
||||||
#include "ui/round_rect.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) {
|
, link(std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||||
const auto my = context.other.value<ClickHandlerContext>();
|
const auto my = context.other.value<ClickHandlerContext>();
|
||||||
if (const auto controller = my.sessionWindow.get()) {
|
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))
|
, updateCallback(std::move(updateCallback))
|
||||||
|
|
Loading…
Add table
Reference in a new issue