2017-06-06 21:18:05 +02:00
|
|
|
#pragma once
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/Message.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>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
struct SystemMessageTag {
|
|
|
|
};
|
|
|
|
struct TimeoutMessageTag {
|
|
|
|
};
|
|
|
|
const SystemMessageTag systemMessage{};
|
|
|
|
const TimeoutMessageTag timeoutMessage{};
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
MessagePtr makeSystemMessage(const QString &text);
|
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;
|
|
|
|
};
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
class MessageBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MessageBuilder();
|
|
|
|
MessageBuilder(const QString &text);
|
|
|
|
MessageBuilder(SystemMessageTag, const QString &text);
|
|
|
|
MessageBuilder(TimeoutMessageTag, const QString &username,
|
|
|
|
const QString &durationInSeconds, const QString &reason,
|
|
|
|
bool multipleTimes);
|
|
|
|
MessageBuilder(const BanAction &action, uint32_t count = 1);
|
|
|
|
MessageBuilder(const UnbanAction &action);
|
|
|
|
|
|
|
|
Message *operator->();
|
|
|
|
Message &message();
|
|
|
|
MessagePtr release();
|
|
|
|
|
|
|
|
void append(std::unique_ptr<MessageElement> element);
|
2018-01-28 03:48:15 +01:00
|
|
|
QString matchLink(const QString &string);
|
2018-01-11 20:16:25 +01:00
|
|
|
|
2018-01-28 15:28:02 +01:00
|
|
|
template <typename T, typename... Args>
|
2018-01-22 14:39:24 +01:00
|
|
|
T *emplace(Args &&... args)
|
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
|
|
|
}
|
|
|
|
|
2018-08-07 01:35:24 +02:00
|
|
|
private:
|
|
|
|
std::unique_ptr<Message> message_;
|
2017-04-12 17:46:44 +02:00
|
|
|
};
|
|
|
|
|
2017-06-06 21:18:05 +02:00
|
|
|
} // namespace chatterino
|