mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Send sponsored peers click requests.
This commit is contained in:
parent
04e10f81b5
commit
33c5b35444
5 changed files with 41 additions and 9 deletions
|
@ -567,7 +567,13 @@ void SponsoredMessages::clicked(
|
|||
if (!entryPtr) {
|
||||
return;
|
||||
}
|
||||
const auto randomId = entryPtr->sponsored.randomId;
|
||||
clicked(entryPtr->sponsored.randomId, isMedia, isFullscreen);
|
||||
}
|
||||
|
||||
void SponsoredMessages::clicked(
|
||||
const QByteArray &randomId,
|
||||
bool isMedia,
|
||||
bool isFullscreen) {
|
||||
using Flag = MTPmessages_ClickSponsoredMessage::Flag;
|
||||
_session->api().request(MTPmessages_ClickSponsoredMessage(
|
||||
MTP_flags(Flag(0)
|
||||
|
|
|
@ -104,6 +104,10 @@ public:
|
|||
void clearItems(not_null<History*> history);
|
||||
[[nodiscard]] Details lookupDetails(const FullMsgId &fullId) const;
|
||||
void clicked(const FullMsgId &fullId, bool isMedia, bool isFullscreen);
|
||||
void clicked(
|
||||
const QByteArray &randomId,
|
||||
bool isMedia,
|
||||
bool isFullscreen);
|
||||
[[nodiscard]] FullMsgId fillTopBar(
|
||||
not_null<History*> history,
|
||||
not_null<Ui::RpWidget*> widget);
|
||||
|
|
|
@ -2962,6 +2962,11 @@ bool InnerWidget::showChatPreview() {
|
|||
void InnerWidget::chatPreviewShown(bool shown, RowDescriptor row) {
|
||||
_chatPreviewScheduled = false;
|
||||
if (shown) {
|
||||
const auto chosen = computeChosenRow();
|
||||
if (!chosen.sponsoredRandomId.isEmpty() && row.key == chosen.key) {
|
||||
auto &messages = session().sponsoredMessages();
|
||||
messages.clicked(chosen.sponsoredRandomId, false, false);
|
||||
}
|
||||
_chatPreviewRow = row;
|
||||
if (base::take(_chatPreviewTouchGlobal)) {
|
||||
_touchCancelRequests.fire({});
|
||||
|
@ -3692,8 +3697,18 @@ void InnerWidget::peerSearchReceived(Api::PeerSearchResult result) {
|
|||
for (const auto &peer : result.my) {
|
||||
appendToFiltered(peer->owner().history(peer));
|
||||
}
|
||||
const auto inlist = [&](not_null<PeerData*> peer) {
|
||||
if (const auto history = peer->owner().historyLoaded(peer)) {
|
||||
// Skip existing chats.
|
||||
return history->inChatList();
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto added = base::flat_set<not_null<PeerData*>>();
|
||||
for (const auto &sponsored : result.sponsored) {
|
||||
if (inlist(sponsored.peer)) {
|
||||
continue;
|
||||
}
|
||||
_peerSearchResults.push_back(
|
||||
std::make_unique<PeerSearchResult>(sponsored.peer));
|
||||
_peerSearchResults.back()->sponsored
|
||||
|
@ -3701,12 +3716,8 @@ void InnerWidget::peerSearchReceived(Api::PeerSearchResult result) {
|
|||
added.emplace(sponsored.peer);
|
||||
}
|
||||
for (const auto &peer : result.peers) {
|
||||
if (added.contains(peer)) {
|
||||
if (added.contains(peer) || inlist(peer)) {
|
||||
continue;
|
||||
} else if (const auto history = peer->owner().historyLoaded(peer)) {
|
||||
if (history->inChatList()) {
|
||||
continue; // skip existing chats
|
||||
}
|
||||
}
|
||||
_peerSearchResults.push_back(
|
||||
std::make_unique<PeerSearchResult>(peer));
|
||||
|
@ -4499,10 +4510,13 @@ ChosenRow InnerWidget::computeChosenRow() const {
|
|||
.filteredRow = true,
|
||||
};
|
||||
} else if (base::in_range(_peerSearchSelected, 0, _peerSearchResults.size())) {
|
||||
const auto peer = _peerSearchResults[_peerSearchSelected]->peer;
|
||||
const auto row = _peerSearchResults[_peerSearchSelected].get();
|
||||
return {
|
||||
.key = session().data().history(peer),
|
||||
.message = Data::UnreadMessagePosition
|
||||
.key = session().data().history(row->peer),
|
||||
.message = Data::UnreadMessagePosition,
|
||||
.sponsoredRandomId = (row->sponsored
|
||||
? row->sponsored->randomId
|
||||
: QByteArray()),
|
||||
};
|
||||
} else if (base::in_range(_previewSelected, 0, _previewResults.size())) {
|
||||
const auto result = _previewResults[_previewSelected].get();
|
||||
|
|
|
@ -82,6 +82,7 @@ enum class ChatTypeFilter : uchar;
|
|||
struct ChosenRow {
|
||||
Key key;
|
||||
Data::MessagePosition message;
|
||||
QByteArray sponsoredRandomId;
|
||||
bool userpicClick : 1 = false;
|
||||
bool filteredRow : 1 = false;
|
||||
bool newWindow : 1 = false;
|
||||
|
|
|
@ -63,6 +63,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "storage/storage_account.h"
|
||||
#include "storage/storage_domain.h"
|
||||
#include "data/components/recent_peers.h"
|
||||
#include "data/components/sponsored_messages.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_chat.h"
|
||||
|
@ -844,6 +845,12 @@ void Widget::chosenRow(const ChosenRow &row) {
|
|||
const auto topicJump = history
|
||||
? history->peer->forumTopicFor(row.message.fullId.msg)
|
||||
: nullptr;
|
||||
|
||||
if (!row.sponsoredRandomId.isEmpty()) {
|
||||
auto &messages = session().sponsoredMessages();
|
||||
messages.clicked(row.sponsoredRandomId, false, false);
|
||||
}
|
||||
|
||||
if (topicJump) {
|
||||
if (controller()->shownForum().current() == topicJump->forum()) {
|
||||
controller()->closeForum();
|
||||
|
|
Loading…
Add table
Reference in a new issue