mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added support of bot apps to sponsored messages.
Added api support of custom button text in sponsored messages.
This commit is contained in:
parent
d28ba4fad9
commit
0f3faf59ca
4 changed files with 47 additions and 12 deletions
|
@ -10,7 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "api/api_text_entities.h"
|
#include "api/api_text_entities.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
|
#include "data/data_bot_app.h"
|
||||||
#include "data/data_channel.h"
|
#include "data/data_channel.h"
|
||||||
|
#include "data/data_peer.h"
|
||||||
#include "data/data_peer_id.h"
|
#include "data/data_peer_id.h"
|
||||||
#include "data/data_photo.h"
|
#include "data/data_photo.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -273,10 +275,10 @@ void SponsoredMessages::append(
|
||||||
.isMegagroup = (channel && channel->isMegagroup()),
|
.isMegagroup = (channel && channel->isMegagroup()),
|
||||||
.isChannel = (channel != nullptr),
|
.isChannel = (channel != nullptr),
|
||||||
.isPublic = (channel && channel->isPublic()),
|
.isPublic = (channel && channel->isPublic()),
|
||||||
.isBot = (peer->isUser() && peer->asUser()->isBot()),
|
|
||||||
.isExactPost = exactPost,
|
.isExactPost = exactPost,
|
||||||
.isRecommended = data.is_recommended(),
|
.isRecommended = data.is_recommended(),
|
||||||
.isForceUserpicDisplay = data.is_show_peer_photo(),
|
.isForceUserpicDisplay = data.is_show_peer_photo(),
|
||||||
|
.buttonText = qs(data.vbutton_text().value_or_empty()),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const auto externalLink = data.vwebpage()
|
const auto externalLink = data.vwebpage()
|
||||||
|
@ -291,13 +293,36 @@ void SponsoredMessages::append(
|
||||||
return SponsoredFrom{
|
return SponsoredFrom{
|
||||||
.title = qs(data.vsite_name()),
|
.title = qs(data.vsite_name()),
|
||||||
.externalLink = externalLink,
|
.externalLink = externalLink,
|
||||||
.externalLinkPhotoId = photoId,
|
.webpageOrBotPhotoId = photoId,
|
||||||
.isForceUserpicDisplay = message.data().is_show_peer_photo(),
|
.isForceUserpicDisplay = message.data().is_show_peer_photo(),
|
||||||
};
|
};
|
||||||
} else if (const auto fromId = data.vfrom_id()) {
|
} else if (const auto fromId = data.vfrom_id()) {
|
||||||
return makeFrom(
|
const auto peerId = peerFromMTP(*fromId);
|
||||||
_session->data().peer(peerFromMTP(*fromId)),
|
auto result = makeFrom(
|
||||||
|
_session->data().peer(peerId),
|
||||||
(data.vchannel_post() != nullptr));
|
(data.vchannel_post() != nullptr));
|
||||||
|
const auto user = result.peer->asUser();
|
||||||
|
if (user && user->isBot()) {
|
||||||
|
const auto botAppData = data.vapp()
|
||||||
|
? _session->data().processBotApp(peerId, *data.vapp())
|
||||||
|
: nullptr;
|
||||||
|
result.botLinkInfo = Window::PeerByLinkInfo{
|
||||||
|
.usernameOrId = user->userName(),
|
||||||
|
.resolveType = botAppData
|
||||||
|
? Window::ResolveType::BotApp
|
||||||
|
: data.vstart_param()
|
||||||
|
? Window::ResolveType::BotStart
|
||||||
|
: Window::ResolveType::Default,
|
||||||
|
.startToken = qs(data.vstart_param().value_or_empty()),
|
||||||
|
.botAppName = botAppData
|
||||||
|
? botAppData->shortName
|
||||||
|
: QString(),
|
||||||
|
};
|
||||||
|
result.webpageOrBotPhotoId = (botAppData && botAppData->photo)
|
||||||
|
? botAppData->photo->id
|
||||||
|
: PhotoId(0);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
Assert(data.vchat_invite());
|
Assert(data.vchat_invite());
|
||||||
return data.vchat_invite()->match([&](const MTPDchatInvite &data) {
|
return data.vchat_invite()->match([&](const MTPDchatInvite &data) {
|
||||||
|
@ -434,11 +459,14 @@ SponsoredMessages::Details SponsoredMessages::lookupDetails(
|
||||||
.info = std::move(info),
|
.info = std::move(info),
|
||||||
.externalLink = data.externalLink,
|
.externalLink = data.externalLink,
|
||||||
.isForceUserpicDisplay = data.from.isForceUserpicDisplay,
|
.isForceUserpicDisplay = data.from.isForceUserpicDisplay,
|
||||||
.buttonText = !data.externalLink.isEmpty()
|
.buttonText = !data.from.buttonText.isEmpty()
|
||||||
|
? data.from.buttonText
|
||||||
|
: !data.externalLink.isEmpty()
|
||||||
? tr::lng_view_button_external_link(tr::now)
|
? tr::lng_view_button_external_link(tr::now)
|
||||||
: data.from.isBot
|
: data.from.botLinkInfo
|
||||||
? tr::lng_view_button_bot(tr::now)
|
? tr::lng_view_button_bot(tr::now)
|
||||||
: QString(),
|
: QString(),
|
||||||
|
.botLinkInfo = data.from.botLinkInfo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "history/history_item.h"
|
|
||||||
#include "base/timer.h"
|
#include "base/timer.h"
|
||||||
|
#include "history/history_item.h"
|
||||||
#include "ui/image/image_location.h"
|
#include "ui/image/image_location.h"
|
||||||
|
#include "window/window_session_controller_link_info.h"
|
||||||
|
|
||||||
class History;
|
class History;
|
||||||
|
|
||||||
|
@ -28,12 +29,13 @@ struct SponsoredFrom {
|
||||||
bool isMegagroup = false;
|
bool isMegagroup = false;
|
||||||
bool isChannel = false;
|
bool isChannel = false;
|
||||||
bool isPublic = false;
|
bool isPublic = false;
|
||||||
bool isBot = false;
|
std::optional<Window::PeerByLinkInfo> botLinkInfo;
|
||||||
bool isExactPost = false;
|
bool isExactPost = false;
|
||||||
bool isRecommended = false;
|
bool isRecommended = false;
|
||||||
QString externalLink;
|
QString externalLink;
|
||||||
PhotoId externalLinkPhotoId;
|
PhotoId webpageOrBotPhotoId = PhotoId(0);
|
||||||
bool isForceUserpicDisplay = false;
|
bool isForceUserpicDisplay = false;
|
||||||
|
QString buttonText;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SponsoredMessage {
|
struct SponsoredMessage {
|
||||||
|
@ -63,6 +65,7 @@ public:
|
||||||
QString externalLink;
|
QString externalLink;
|
||||||
bool isForceUserpicDisplay = false;
|
bool isForceUserpicDisplay = false;
|
||||||
QString buttonText;
|
QString buttonText;
|
||||||
|
std::optional<Window::PeerByLinkInfo> botLinkInfo;
|
||||||
};
|
};
|
||||||
using RandomId = QByteArray;
|
using RandomId = QByteArray;
|
||||||
explicit SponsoredMessages(not_null<Session*> owner);
|
explicit SponsoredMessages(not_null<Session*> owner);
|
||||||
|
|
|
@ -699,7 +699,9 @@ HistoryItem::HistoryItem(
|
||||||
|
|
||||||
const auto webPageType = from.isExactPost
|
const auto webPageType = from.isExactPost
|
||||||
? WebPageType::Message
|
? WebPageType::Message
|
||||||
: from.isBot
|
: (from.botLinkInfo && !from.botLinkInfo->botAppName.isEmpty())
|
||||||
|
? WebPageType::BotApp
|
||||||
|
: from.botLinkInfo
|
||||||
? WebPageType::Bot
|
? WebPageType::Bot
|
||||||
: from.isBroadcast
|
: from.isBroadcast
|
||||||
? WebPageType::Channel
|
? WebPageType::Channel
|
||||||
|
@ -717,8 +719,8 @@ HistoryItem::HistoryItem(
|
||||||
: tr::lng_sponsored_message_title(tr::now),
|
: tr::lng_sponsored_message_title(tr::now),
|
||||||
from.title,
|
from.title,
|
||||||
textWithEntities,
|
textWithEntities,
|
||||||
from.externalLinkPhotoId
|
from.webpageOrBotPhotoId
|
||||||
? history->owner().photo(from.externalLinkPhotoId)
|
? history->owner().photo(from.webpageOrBotPhotoId)
|
||||||
: nullptr,
|
: nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
WebPageCollage(),
|
WebPageCollage(),
|
||||||
|
|
|
@ -44,6 +44,8 @@ ClickHandlerPtr SponsoredLink(const QString &externalLink) {
|
||||||
File::OpenUrl(details.externalLink);
|
File::OpenUrl(details.externalLink);
|
||||||
} else if (details.hash) {
|
} else if (details.hash) {
|
||||||
Api::CheckChatInvite(controller, *details.hash);
|
Api::CheckChatInvite(controller, *details.hash);
|
||||||
|
} else if (details.botLinkInfo) {
|
||||||
|
controller->showPeerByLink(*details.botLinkInfo);
|
||||||
} else if (details.peer) {
|
} else if (details.peer) {
|
||||||
controller->showPeerHistory(
|
controller->showPeerHistory(
|
||||||
details.peer,
|
details.peer,
|
||||||
|
|
Loading…
Add table
Reference in a new issue