2017-06-06 21:18:05 +02:00
|
|
|
#pragma once
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "messages/MessageElement.hpp"
|
2017-06-06 21:18:05 +02:00
|
|
|
|
2017-07-26 09:08:19 +02:00
|
|
|
#include <QRegularExpression>
|
2017-07-31 00:57:42 +02:00
|
|
|
#include <ctime>
|
2019-01-20 01:02:04 +01:00
|
|
|
#include <utility>
|
2017-07-31 00:57:42 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2018-08-11 22:23:06 +02:00
|
|
|
struct BanAction;
|
|
|
|
struct UnbanAction;
|
2019-01-20 01:02:04 +01:00
|
|
|
struct AutomodAction;
|
2019-01-21 18:33:57 +01:00
|
|
|
struct AutomodUserAction;
|
2021-05-08 14:49:30 +02:00
|
|
|
struct AutomodInfoAction;
|
2018-08-11 22:23:06 +02:00
|
|
|
struct Message;
|
|
|
|
using MessagePtr = std::shared_ptr<const Message>;
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
struct SystemMessageTag {
|
|
|
|
};
|
|
|
|
struct TimeoutMessageTag {
|
|
|
|
};
|
2022-11-13 12:07:41 +01:00
|
|
|
struct LiveUpdatesUpdateEmoteMessageTag {
|
|
|
|
};
|
|
|
|
struct LiveUpdatesRemoveEmoteMessageTag {
|
|
|
|
};
|
|
|
|
struct LiveUpdatesAddEmoteMessageTag {
|
|
|
|
};
|
|
|
|
struct LiveUpdatesUpdateEmoteSetMessageTag {
|
|
|
|
};
|
2018-08-07 01:35:24 +02:00
|
|
|
const SystemMessageTag systemMessage{};
|
|
|
|
const TimeoutMessageTag timeoutMessage{};
|
2022-11-13 12:07:41 +01:00
|
|
|
const LiveUpdatesUpdateEmoteMessageTag liveUpdatesUpdateEmoteMessage{};
|
|
|
|
const LiveUpdatesRemoveEmoteMessageTag liveUpdatesRemoveEmoteMessage{};
|
|
|
|
const LiveUpdatesAddEmoteMessageTag liveUpdatesAddEmoteMessage{};
|
|
|
|
const LiveUpdatesUpdateEmoteSetMessageTag liveUpdatesUpdateEmoteSetMessage{};
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
MessagePtr makeSystemMessage(const QString &text);
|
2020-07-18 16:03:51 +02:00
|
|
|
MessagePtr makeSystemMessage(const QString &text, const QTime &time);
|
2019-01-20 01:02:04 +01:00
|
|
|
std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
|
|
|
|
const AutomodAction &action);
|
2021-05-08 14:49:30 +02:00
|
|
|
MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-11 14:20:53 +02:00
|
|
|
struct MessageParseArgs {
|
|
|
|
bool disablePingSounds = false;
|
|
|
|
bool isReceivedWhisper = false;
|
|
|
|
bool isSentWhisper = false;
|
|
|
|
bool trimSubscriberUsername = false;
|
|
|
|
bool isStaffOrBroadcaster = false;
|
2022-06-05 17:40:57 +02:00
|
|
|
bool isSubscriptionMessage = false;
|
2020-08-08 15:37:22 +02:00
|
|
|
QString channelPointRewardId = "";
|
2018-08-11 14:20:53 +02:00
|
|
|
};
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
class MessageBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MessageBuilder();
|
2020-07-18 16:03:51 +02:00
|
|
|
MessageBuilder(SystemMessageTag, const QString &text,
|
|
|
|
const QTime &time = QTime::currentTime());
|
2022-08-14 15:34:32 +02:00
|
|
|
MessageBuilder(TimeoutMessageTag, const QString &timeoutUser,
|
|
|
|
const QString &sourceUser, const QString &systemMessageText,
|
2020-10-03 13:37:07 +02:00
|
|
|
int times, const QTime &time = QTime::currentTime());
|
2018-08-07 01:35:24 +02:00
|
|
|
MessageBuilder(TimeoutMessageTag, const QString &username,
|
2021-04-25 15:44:12 +02:00
|
|
|
const QString &durationInSeconds, bool multipleTimes,
|
2020-10-03 13:37:07 +02:00
|
|
|
const QTime &time = QTime::currentTime());
|
2018-08-07 01:35:24 +02:00
|
|
|
MessageBuilder(const BanAction &action, uint32_t count = 1);
|
|
|
|
MessageBuilder(const UnbanAction &action);
|
2019-01-21 18:33:57 +01:00
|
|
|
MessageBuilder(const AutomodUserAction &action);
|
2022-11-13 12:07:41 +01:00
|
|
|
|
|
|
|
MessageBuilder(LiveUpdatesAddEmoteMessageTag, const QString &platform,
|
|
|
|
const QString &actor,
|
|
|
|
const std::vector<QString> &emoteNames);
|
|
|
|
MessageBuilder(LiveUpdatesRemoveEmoteMessageTag, const QString &platform,
|
|
|
|
const QString &actor,
|
|
|
|
const std::vector<QString> &emoteNames);
|
|
|
|
MessageBuilder(LiveUpdatesUpdateEmoteMessageTag, const QString &platform,
|
|
|
|
const QString &actor, const QString &emoteName,
|
|
|
|
const QString &oldEmoteName);
|
|
|
|
MessageBuilder(LiveUpdatesUpdateEmoteSetMessageTag, const QString &platform,
|
|
|
|
const QString &actor, const QString &emoteSetName);
|
|
|
|
|
2021-06-20 15:55:35 +02:00
|
|
|
virtual ~MessageBuilder() = default;
|
2018-08-07 01:35:24 +02:00
|
|
|
|
|
|
|
Message *operator->();
|
|
|
|
Message &message();
|
|
|
|
MessagePtr release();
|
2018-10-24 11:36:36 +02:00
|
|
|
std::weak_ptr<Message> weakOf();
|
2018-08-07 01:35:24 +02:00
|
|
|
|
|
|
|
void append(std::unique_ptr<MessageElement> element);
|
2018-01-28 03:48:15 +01:00
|
|
|
QString matchLink(const QString &string);
|
2019-03-13 15:26:55 +01:00
|
|
|
void addLink(const QString &origLink, const QString &matchedLink);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2022-10-01 17:36:22 +02:00
|
|
|
/**
|
|
|
|
* Adds the text, applies irc colors, adds links,
|
|
|
|
* and updates the message's messageText.
|
|
|
|
* See https://modern.ircdocs.horse/formatting.html
|
|
|
|
*/
|
|
|
|
void addIrcMessageText(const QString &text);
|
|
|
|
|
2018-01-28 15:28:02 +01:00
|
|
|
template <typename T, typename... Args>
|
2022-05-07 16:57:26 +02:00
|
|
|
// clang-format off
|
|
|
|
// clang-format can be enabled once clang-format v11+ has been installed in CI
|
|
|
|
T *emplace(Args &&...args)
|
|
|
|
// clang-format on
|
2018-01-11 20:16:25 +01:00
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
static_assert(std::is_base_of<MessageElement, T>::value,
|
|
|
|
"T must extend MessageElement");
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
auto unique = std::make_unique<T>(std::forward<Args>(args)...);
|
|
|
|
auto pointer = unique.get();
|
|
|
|
this->append(std::move(unique));
|
|
|
|
return pointer;
|
2018-01-11 20:16:25 +01:00
|
|
|
}
|
|
|
|
|
2022-10-01 17:36:22 +02:00
|
|
|
protected:
|
|
|
|
virtual void addTextOrEmoji(EmotePtr emote);
|
|
|
|
virtual void addTextOrEmoji(const QString &value);
|
|
|
|
|
|
|
|
MessageColor textColor_ = MessageColor::Text;
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
private:
|
2020-07-18 16:03:51 +02:00
|
|
|
// Helper method that emplaces some text stylized as system text
|
|
|
|
// and then appends that text to the QString parameter "toUpdate".
|
|
|
|
// Returns the TextElement that was emplaced.
|
|
|
|
TextElement *emplaceSystemTextAndUpdate(const QString &text,
|
|
|
|
QString &toUpdate);
|
|
|
|
|
2022-10-01 17:36:22 +02:00
|
|
|
/**
|
|
|
|
* This will add the text and replace any emojis
|
|
|
|
* with an emoji emote-element.
|
|
|
|
*
|
|
|
|
* @param text Text to add
|
|
|
|
* @param color Color of the text
|
|
|
|
* @param addSpace true if a trailing space should be added after emojis
|
|
|
|
*/
|
|
|
|
void addIrcWord(const QString &text, const QColor &color,
|
|
|
|
bool addSpace = true);
|
|
|
|
|
2018-08-11 22:23:06 +02:00
|
|
|
std::shared_ptr<Message> message_;
|
2017-04-12 17:46:44 +02:00
|
|
|
};
|
2020-07-04 15:15:59 +02:00
|
|
|
|
2017-06-06 21:18:05 +02:00
|
|
|
} // namespace chatterino
|