2016-04-12 21:31:28 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-12 21:31:28 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/basic_click_handlers.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2021-11-29 10:54:31 +00:00
|
|
|
constexpr auto kPeerLinkPeerIdProperty = 0x01;
|
2022-01-13 17:31:35 +00:00
|
|
|
constexpr auto kPhotoLinkMediaIdProperty = 0x02;
|
|
|
|
constexpr auto kDocumentLinkMediaIdProperty = 0x03;
|
2021-11-29 10:54:31 +00:00
|
|
|
|
2020-06-09 09:36:40 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2020-11-10 16:38:21 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
class ElementDelegate;
|
|
|
|
} // namespace HistoryView
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
namespace Window {
|
|
|
|
class SessionController;
|
|
|
|
} // namespace Window
|
|
|
|
|
2020-11-02 06:34:54 +00:00
|
|
|
[[nodiscard]] bool UrlRequiresConfirmation(const QUrl &url);
|
|
|
|
|
2021-07-26 16:27:08 +00:00
|
|
|
class PeerData;
|
2020-11-10 16:38:21 +00:00
|
|
|
struct ClickHandlerContext {
|
|
|
|
FullMsgId itemId;
|
2021-07-26 16:27:08 +00:00
|
|
|
// Is filled from sections.
|
2020-11-10 16:38:21 +00:00
|
|
|
Fn<HistoryView::ElementDelegate*()> elementDelegate;
|
2021-02-25 15:12:51 +00:00
|
|
|
base::weak_ptr<Window::SessionController> sessionWindow;
|
2021-03-11 16:21:25 +00:00
|
|
|
bool skipBotAutoLogin = false;
|
2021-07-26 16:27:08 +00:00
|
|
|
// Is filled from peer info.
|
|
|
|
PeerData *peer = nullptr;
|
2020-11-10 16:38:21 +00:00
|
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(ClickHandlerContext);
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
class HiddenUrlClickHandler : public UrlClickHandler {
|
|
|
|
public:
|
|
|
|
HiddenUrlClickHandler(QString url) : UrlClickHandler(url, false) {
|
|
|
|
}
|
2021-11-18 12:03:12 +00:00
|
|
|
QString copyToClipboardText() const override;
|
|
|
|
QString copyToClipboardContextItemText() const override;
|
|
|
|
QString dragText() const override;
|
2016-12-20 13:03:51 +00:00
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
static void Open(QString url, QVariant context = {});
|
|
|
|
void onClick(ClickContext context) const override {
|
|
|
|
const auto button = context.button;
|
2016-12-20 13:03:51 +00:00
|
|
|
if (button == Qt::LeftButton || button == Qt::MiddleButton) {
|
2018-07-09 18:13:48 +00:00
|
|
|
Open(url(), context.other);
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextEntity getTextEntity() const override;
|
2016-04-29 12:00:48 +00:00
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
};
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
class UserData;
|
2016-09-15 19:15:49 +00:00
|
|
|
class BotGameUrlClickHandler : public UrlClickHandler {
|
|
|
|
public:
|
2018-02-06 07:24:55 +00:00
|
|
|
BotGameUrlClickHandler(UserData *bot, QString url)
|
|
|
|
: UrlClickHandler(url, false)
|
|
|
|
, _bot(bot) {
|
2016-09-15 19:15:49 +00:00
|
|
|
}
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2016-09-15 19:15:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
UserData *_bot;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
class MentionClickHandler : public TextClickHandler {
|
|
|
|
public:
|
|
|
|
MentionClickHandler(const QString &tag) : _tag(tag) {
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2016-04-29 12:00:48 +00:00
|
|
|
|
|
|
|
QString dragText() const override {
|
2016-04-12 21:31:28 +00:00
|
|
|
return _tag;
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
|
|
|
|
QString copyToClipboardContextItemText() const override;
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextEntity getTextEntity() const override;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QString url() const override {
|
|
|
|
return _tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _tag;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-30 17:04:14 +00:00
|
|
|
class MentionNameClickHandler : public ClickHandler {
|
|
|
|
public:
|
2020-06-09 09:36:40 +00:00
|
|
|
MentionNameClickHandler(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
QString text,
|
|
|
|
UserId userId,
|
|
|
|
uint64 accessHash)
|
|
|
|
: _session(session)
|
|
|
|
, _text(text)
|
2020-06-08 09:06:50 +00:00
|
|
|
, _userId(userId)
|
|
|
|
, _accessHash(accessHash) {
|
2016-04-30 17:04:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2016-04-30 17:04:14 +00:00
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextEntity getTextEntity() const override;
|
2016-04-30 17:04:14 +00:00
|
|
|
|
|
|
|
QString tooltip() const override;
|
|
|
|
|
|
|
|
private:
|
2020-06-09 09:36:40 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2016-04-30 17:04:14 +00:00
|
|
|
QString _text;
|
|
|
|
UserId _userId;
|
|
|
|
uint64 _accessHash;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
class HashtagClickHandler : public TextClickHandler {
|
|
|
|
public:
|
|
|
|
HashtagClickHandler(const QString &tag) : _tag(tag) {
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2016-04-29 12:00:48 +00:00
|
|
|
|
|
|
|
QString dragText() const override {
|
2016-04-12 21:31:28 +00:00
|
|
|
return _tag;
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
|
|
|
|
QString copyToClipboardContextItemText() const override;
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextEntity getTextEntity() const override;
|
2018-02-06 07:24:55 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QString url() const override {
|
|
|
|
return _tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _tag;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class CashtagClickHandler : public TextClickHandler {
|
|
|
|
public:
|
|
|
|
CashtagClickHandler(const QString &tag) : _tag(tag) {
|
|
|
|
}
|
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2018-02-06 07:24:55 +00:00
|
|
|
|
|
|
|
QString dragText() const override {
|
|
|
|
return _tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString copyToClipboardContextItemText() const override;
|
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextEntity getTextEntity() const override;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QString url() const override {
|
|
|
|
return _tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _tag;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class BotCommandClickHandler : public TextClickHandler {
|
|
|
|
public:
|
|
|
|
BotCommandClickHandler(const QString &cmd) : _cmd(cmd) {
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
|
2018-07-09 18:13:48 +00:00
|
|
|
void onClick(ClickContext context) const override;
|
2016-04-29 12:00:48 +00:00
|
|
|
|
|
|
|
QString dragText() const override {
|
2016-04-12 21:31:28 +00:00
|
|
|
return _cmd;
|
|
|
|
}
|
2016-04-29 12:00:48 +00:00
|
|
|
|
2019-04-08 15:10:06 +00:00
|
|
|
TextEntity getTextEntity() const override;
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QString url() const override {
|
|
|
|
return _cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _cmd;
|
|
|
|
|
|
|
|
};
|
2022-01-08 04:41:44 +00:00
|
|
|
|
|
|
|
class MonospaceClickHandler : public TextClickHandler {
|
|
|
|
public:
|
|
|
|
MonospaceClickHandler(const QString &text, EntityType type);
|
|
|
|
|
|
|
|
void onClick(ClickContext context) const override;
|
|
|
|
|
|
|
|
TextEntity getTextEntity() const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QString url() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const QString _text;
|
|
|
|
const TextEntity _entity;
|
|
|
|
|
|
|
|
};
|