mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Added tooltip and ability to copy external link to sponsored messages.
This commit is contained in:
parent
456f4d7b8a
commit
3332f012cf
7 changed files with 40 additions and 23 deletions
|
@ -297,7 +297,7 @@ void SponsoredMessages::append(
|
|||
: ImageWithLocation{};
|
||||
return SponsoredFrom{
|
||||
.title = qs(data.vsite_name()),
|
||||
.isExternalLink = true,
|
||||
.externalLink = externalLink,
|
||||
.userpic = std::move(userpic),
|
||||
.isForceUserpicDisplay = message.data().is_show_peer_photo(),
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ struct SponsoredFrom {
|
|||
bool isBot = false;
|
||||
bool isExactPost = false;
|
||||
bool isRecommended = false;
|
||||
bool isExternalLink = false;
|
||||
QString externalLink;
|
||||
ImageWithLocation userpic;
|
||||
bool isForceUserpicDisplay = false;
|
||||
};
|
||||
|
|
|
@ -2544,7 +2544,9 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
|
|||
}, &st::menuIconLink);
|
||||
}
|
||||
if (item && item->isSponsored()) {
|
||||
_menu->addSeparator(&st::expandedMenuSeparator);
|
||||
if (!_menu->empty()) {
|
||||
_menu->addSeparator(&st::expandedMenuSeparator);
|
||||
}
|
||||
auto item = base::make_unique_q<Ui::Menu::MultilineAction>(
|
||||
_menu,
|
||||
st::menuWithIcons,
|
||||
|
|
|
@ -3234,8 +3234,9 @@ void HistoryItem::setSponsoredFrom(const Data::SponsoredFrom &from) {
|
|||
from.userpic);
|
||||
}
|
||||
|
||||
sponsored->externalLink = from.externalLink;
|
||||
using Type = HistoryMessageSponsored::Type;
|
||||
sponsored->type = from.isExternalLink
|
||||
sponsored->type = (!from.externalLink.isEmpty())
|
||||
? Type::ExternalLink
|
||||
: from.isExactPost
|
||||
? Type::Post
|
||||
|
|
|
@ -146,6 +146,7 @@ struct HistoryMessageSponsored : public RuntimeComponent<HistoryMessageSponsored
|
|||
Type type = Type::User;
|
||||
bool recommended = false;
|
||||
bool isForceUserpicDisplay = false;
|
||||
QString externalLink;
|
||||
};
|
||||
|
||||
class ReplyToMessagePointer final {
|
||||
|
|
|
@ -103,6 +103,36 @@ inline auto WebPageToPhrase(not_null<WebPageData*> webpage) {
|
|||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] ClickHandlerPtr SponsoredLink(
|
||||
not_null<HistoryMessageSponsored*> sponsored) {
|
||||
if (!sponsored->externalLink.isEmpty()) {
|
||||
return std::make_shared<UrlClickHandler>(
|
||||
sponsored->externalLink,
|
||||
false);
|
||||
} else {
|
||||
return std::make_shared<LambdaClickHandler>([](ClickContext context) {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
const auto controller = my.sessionWindow.get();
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
const auto &data = controller->session().data();
|
||||
const auto details = data.sponsoredMessages().lookupDetails(
|
||||
my.itemId);
|
||||
if (!details.externalLink.isEmpty()) {
|
||||
File::OpenUrl(details.externalLink);
|
||||
} else if (details.hash) {
|
||||
Api::CheckChatInvite(controller, *details.hash);
|
||||
} else if (details.peer) {
|
||||
controller->showPeerHistory(
|
||||
details.peer,
|
||||
Window::SectionShow::Way::Forward,
|
||||
details.msgId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
struct ViewButton::Inner {
|
||||
|
@ -156,24 +186,7 @@ ViewButton::Inner::Inner(
|
|||
not_null<HistoryMessageSponsored*> sponsored,
|
||||
Fn<void()> updateCallback)
|
||||
: margins(st::historyViewButtonMargins)
|
||||
, link(std::make_shared<LambdaClickHandler>([=](ClickContext context) {
|
||||
const auto my = context.other.value<ClickHandlerContext>();
|
||||
if (const auto controller = my.sessionWindow.get()) {
|
||||
const auto &data = controller->session().data();
|
||||
const auto itemId = my.itemId;
|
||||
const auto details = data.sponsoredMessages().lookupDetails(itemId);
|
||||
if (!details.externalLink.isEmpty()) {
|
||||
File::OpenUrl(details.externalLink);
|
||||
} else if (details.hash) {
|
||||
Api::CheckChatInvite(controller, *details.hash);
|
||||
} else if (details.peer) {
|
||||
controller->showPeerHistory(
|
||||
details.peer,
|
||||
Window::SectionShow::Way::Forward,
|
||||
details.msgId);
|
||||
}
|
||||
}
|
||||
}))
|
||||
, link(SponsoredLink(sponsored))
|
||||
, updateCallback(std::move(updateCallback))
|
||||
, externalLink(sponsored->type == SponsoredType::ExternalLink)
|
||||
, text(st::historyViewButtonTextStyle, SponsoredPhrase(sponsored->type)) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e24eaa6b32799119caa78caacd57216f81d3e1a7
|
||||
Subproject commit aaa88be9d7eaba529b31d742444e80846a2aa003
|
Loading…
Add table
Reference in a new issue