2017-04-08 16:27:53 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-04-08 16:27:53 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-04-08 16:27:53 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-10-26 11:30:36 +04:00
|
|
|
#include "base/qt/qt_compare.h"
|
2018-05-22 00:31:46 +03:00
|
|
|
#include "base/timer.h"
|
2023-05-17 15:51:04 +04:00
|
|
|
#include "chat_helpers/compose/compose_features.h"
|
2023-10-26 11:30:36 +04:00
|
|
|
#include "ui/widgets/fields/input_field.h"
|
2017-04-08 16:27:53 +03:00
|
|
|
|
2019-11-05 14:27:21 +03:00
|
|
|
#ifndef TDESKTOP_DISABLE_SPELLCHECK
|
2020-02-21 12:48:24 +03:00
|
|
|
#include "boxes/dictionaries_manager.h"
|
2019-11-05 14:27:21 +03:00
|
|
|
#include "spellcheck/spelling_highlighter.h"
|
|
|
|
#endif // TDESKTOP_DISABLE_SPELLCHECK
|
|
|
|
|
2019-09-04 10:19:15 +03:00
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2019-08-02 11:40:35 +01:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
2023-05-02 13:33:19 +04:00
|
|
|
class SessionShow;
|
2019-08-02 11:40:35 +01:00
|
|
|
} // namespace Main
|
2019-06-06 13:21:40 +03:00
|
|
|
|
2017-04-08 16:27:53 +03:00
|
|
|
namespace Window {
|
2019-06-06 13:21:40 +03:00
|
|
|
class SessionController;
|
2017-04-08 16:27:53 +03:00
|
|
|
} // namespace Window
|
|
|
|
|
2023-05-02 13:33:19 +04:00
|
|
|
namespace ChatHelpers {
|
|
|
|
enum class PauseReason;
|
|
|
|
class Show;
|
|
|
|
} // namespace ChatHelpers
|
|
|
|
|
2020-07-24 11:23:08 +03:00
|
|
|
namespace Ui {
|
|
|
|
class PopupMenu;
|
2024-06-10 18:05:37 +04:00
|
|
|
class Show;
|
2020-07-24 11:23:08 +03:00
|
|
|
} // namespace Ui
|
|
|
|
|
2023-08-21 11:00:38 +02:00
|
|
|
[[nodiscard]] QString PrepareMentionTag(not_null<UserData*> user);
|
|
|
|
[[nodiscard]] TextWithTags PrepareEditText(not_null<HistoryItem*> item);
|
|
|
|
[[nodiscard]] bool EditTextChanged(
|
|
|
|
not_null<HistoryItem*> item,
|
2024-06-12 21:22:06 +04:00
|
|
|
TextWithTags updated);
|
2017-04-08 16:27:53 +03:00
|
|
|
|
2018-06-04 18:35:11 +03:00
|
|
|
Fn<bool(
|
2018-05-26 17:58:21 +03:00
|
|
|
Ui::InputField::EditLinkSelection selection,
|
2025-01-16 10:01:59 +04:00
|
|
|
TextWithTags text,
|
2018-05-26 17:58:21 +03:00
|
|
|
QString link,
|
|
|
|
Ui::InputField::EditLinkAction action)> DefaultEditLinkCallback(
|
2023-05-02 13:33:19 +04:00
|
|
|
std::shared_ptr<Main::SessionShow> show,
|
2022-03-06 16:02:15 +03:00
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
const style::InputField *fieldStyle = nullptr);
|
2024-06-10 18:05:37 +04:00
|
|
|
Fn<void(QString now, Fn<void(QString)> save)> DefaultEditLanguageCallback(
|
|
|
|
std::shared_ptr<Ui::Show> show);
|
2024-09-26 22:05:58 +04:00
|
|
|
|
|
|
|
struct MessageFieldHandlersArgs {
|
|
|
|
not_null<Main::Session*> session;
|
|
|
|
std::shared_ptr<Main::SessionShow> show; // may be null
|
|
|
|
not_null<Ui::InputField*> field;
|
|
|
|
Fn<bool()> customEmojiPaused;
|
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji;
|
|
|
|
const style::InputField *fieldStyle = nullptr;
|
|
|
|
base::flat_set<QString> allowMarkdownTags;
|
|
|
|
};
|
|
|
|
void InitMessageFieldHandlers(MessageFieldHandlersArgs &&args);
|
|
|
|
|
2022-07-01 17:01:39 +04:00
|
|
|
void InitMessageFieldHandlers(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::InputField*> field,
|
2023-05-02 13:33:19 +04:00
|
|
|
ChatHelpers::PauseReason pauseReasonLevel,
|
2022-08-01 16:24:51 +03:00
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr);
|
2023-05-02 13:33:19 +04:00
|
|
|
void InitMessageField(
|
|
|
|
std::shared_ptr<ChatHelpers::Show> show,
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
|
2018-05-26 17:58:21 +03:00
|
|
|
void InitMessageField(
|
2019-06-06 13:21:40 +03:00
|
|
|
not_null<Window::SessionController*> controller,
|
2022-07-15 17:52:36 +03:00
|
|
|
not_null<Ui::InputField*> field,
|
2022-08-01 16:24:51 +03:00
|
|
|
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
|
2019-11-05 14:27:21 +03:00
|
|
|
|
2022-03-03 11:51:43 +03:00
|
|
|
void InitSpellchecker(
|
2023-05-02 13:33:19 +04:00
|
|
|
std::shared_ptr<Main::SessionShow> show,
|
2022-03-06 15:52:01 +03:00
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
bool skipDictionariesManager = false);
|
2019-11-05 14:27:21 +03:00
|
|
|
|
2024-05-24 11:23:27 +04:00
|
|
|
[[nodiscard]] Fn<void(not_null<Ui::InputField*>)> FactcheckFieldIniter(
|
|
|
|
std::shared_ptr<Main::SessionShow> show);
|
|
|
|
|
2018-05-22 00:31:46 +03:00
|
|
|
bool HasSendText(not_null<const Ui::InputField*> field);
|
2017-04-08 16:27:53 +03:00
|
|
|
|
2024-02-16 13:41:58 +03:00
|
|
|
void InitMessageFieldFade(
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
const style::color &bg);
|
2024-02-14 18:26:18 +03:00
|
|
|
|
2018-05-22 00:31:46 +03:00
|
|
|
struct InlineBotQuery {
|
|
|
|
QString query;
|
|
|
|
QString username;
|
|
|
|
UserData *bot = nullptr;
|
|
|
|
bool lookingUpBot = false;
|
|
|
|
};
|
2020-06-08 13:06:50 +04:00
|
|
|
InlineBotQuery ParseInlineBotQuery(
|
|
|
|
not_null<Main::Session*> session,
|
|
|
|
not_null<const Ui::InputField*> field);
|
2018-05-22 00:31:46 +03:00
|
|
|
|
|
|
|
struct AutocompleteQuery {
|
|
|
|
QString query;
|
|
|
|
bool fromStart = false;
|
|
|
|
};
|
|
|
|
AutocompleteQuery ParseMentionHashtagBotCommandQuery(
|
2023-05-17 15:51:04 +04:00
|
|
|
not_null<const Ui::InputField*> field,
|
|
|
|
ChatHelpers::ComposeFeatures features);
|
2018-05-22 00:31:46 +03:00
|
|
|
|
2023-10-26 11:30:36 +04:00
|
|
|
struct MessageLinkRange {
|
|
|
|
int start = 0;
|
|
|
|
int length = 0;
|
|
|
|
QString custom;
|
|
|
|
|
|
|
|
friend inline auto operator<=>(
|
|
|
|
const MessageLinkRange&,
|
|
|
|
const MessageLinkRange&) = default;
|
|
|
|
friend inline bool operator==(
|
|
|
|
const MessageLinkRange&,
|
|
|
|
const MessageLinkRange&) = default;
|
|
|
|
};
|
|
|
|
|
2023-10-26 09:26:45 +04:00
|
|
|
class MessageLinksParser final : private QObject {
|
2018-05-22 00:31:46 +03:00
|
|
|
public:
|
|
|
|
MessageLinksParser(not_null<Ui::InputField*> field);
|
2017-04-08 16:27:53 +03:00
|
|
|
|
2021-01-29 15:27:17 +04:00
|
|
|
void parseNow();
|
2023-08-21 11:00:38 +02:00
|
|
|
void setDisabled(bool disabled);
|
2021-01-29 15:27:17 +04:00
|
|
|
|
2023-10-26 11:30:36 +04:00
|
|
|
[[nodiscard]] const rpl::variable<QStringList> &list() const {
|
|
|
|
return _list;
|
|
|
|
}
|
|
|
|
[[nodiscard]] const std::vector<MessageLinkRange> &ranges() const {
|
|
|
|
return _ranges;
|
|
|
|
}
|
2023-10-26 09:26:45 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2017-04-08 16:27:53 +03:00
|
|
|
|
2018-05-22 00:31:46 +03:00
|
|
|
void parse();
|
2023-10-26 09:26:45 +04:00
|
|
|
void applyRanges(const QString &text);
|
2018-05-22 00:31:46 +03:00
|
|
|
|
|
|
|
not_null<Ui::InputField*> _field;
|
|
|
|
rpl::variable<QStringList> _list;
|
2023-10-26 11:30:36 +04:00
|
|
|
std::vector<MessageLinkRange> _ranges;
|
2018-05-22 00:31:46 +03:00
|
|
|
int _lastLength = 0;
|
2023-08-21 11:00:38 +02:00
|
|
|
bool _disabled = false;
|
2018-05-22 00:31:46 +03:00
|
|
|
base::Timer _timer;
|
2023-08-31 14:21:24 +03:00
|
|
|
rpl::lifetime _lifetime;
|
2018-05-22 00:31:46 +03:00
|
|
|
|
2019-07-26 18:06:22 +02:00
|
|
|
};
|
2023-01-31 21:21:47 +04:00
|
|
|
|
|
|
|
[[nodiscard]] base::unique_qptr<Ui::RpWidget> CreateDisabledFieldView(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<PeerData*> peer);
|
2024-01-11 23:20:36 +04:00
|
|
|
[[nodiscard]] base::unique_qptr<Ui::RpWidget> TextErrorSendRestriction(
|
|
|
|
QWidget *parent,
|
|
|
|
const QString &text);
|
|
|
|
[[nodiscard]] base::unique_qptr<Ui::RpWidget> PremiumRequiredSendRestriction(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<UserData*> user,
|
|
|
|
not_null<Window::SessionController*> controller);
|
2024-03-17 03:46:11 +03:00
|
|
|
|
|
|
|
void SelectTextInFieldWithMargins(
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
const TextSelection &selection);
|