2018-06-26 14:09:39 +02:00
|
|
|
#include "MessageBuilder.hpp"
|
2018-06-28 00:24:21 +02:00
|
|
|
|
|
|
|
#include "common/LinkParser.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Emotes.hpp"
|
|
|
|
#include "singletons/Resources.hpp"
|
2018-06-28 20:03:04 +02:00
|
|
|
#include "singletons/Theme.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-12-27 01:22:12 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
MessageBuilder::MessageBuilder()
|
2018-07-06 19:23:47 +02:00
|
|
|
: message_(new Message)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
MessagePtr MessageBuilder::getMessage()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
return this->message_;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-28 03:48:15 +01:00
|
|
|
void MessageBuilder::append(MessageElement *element)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-07-06 19:23:47 +02:00
|
|
|
this->message_->addElement(element);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageBuilder::appendTimestamp()
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
this->appendTimestamp(QTime::currentTime());
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-24 18:43:24 +02:00
|
|
|
void MessageBuilder::setHighlight(bool value)
|
2017-07-31 00:57:42 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
if (value) {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->message_->flags |= Message::Highlighted;
|
2018-01-11 20:16:25 +01:00
|
|
|
} else {
|
2018-07-06 19:23:47 +02:00
|
|
|
this->message_->flags &= ~Message::Highlighted;
|
2018-01-11 20:16:25 +01:00
|
|
|
}
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void MessageBuilder::appendTimestamp(const QTime &time)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-28 03:48:15 +01:00
|
|
|
this->append(new TimestampElement(time));
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MessageBuilder::matchLink(const QString &string)
|
|
|
|
{
|
2018-06-28 00:24:21 +02:00
|
|
|
LinkParser linkParser(string);
|
|
|
|
|
2018-07-03 16:57:11 +02:00
|
|
|
static QRegularExpression httpRegex("\\bhttps?://", QRegularExpression::CaseInsensitiveOption);
|
|
|
|
static QRegularExpression ftpRegex("\\bftps?://", QRegularExpression::CaseInsensitiveOption);
|
2018-07-11 13:50:05 +02:00
|
|
|
static QRegularExpression spotifyRegex("\\bspotify:", QRegularExpression::CaseInsensitiveOption);
|
2017-08-12 12:09:26 +02:00
|
|
|
|
2018-06-28 00:24:21 +02:00
|
|
|
if (!linkParser.hasMatch()) {
|
2017-08-12 12:09:26 +02:00
|
|
|
return QString();
|
|
|
|
}
|
2017-08-05 18:44:14 +02:00
|
|
|
|
2018-06-28 00:24:21 +02:00
|
|
|
QString captured = linkParser.getCaptured();
|
2017-07-31 14:23:23 +02:00
|
|
|
|
2018-07-11 13:50:05 +02:00
|
|
|
if (!captured.contains(httpRegex) && !captured.contains(ftpRegex) && !captured.contains(spotifyRegex)) {
|
|
|
|
captured.insert(0, "http://");
|
2017-07-26 12:01:23 +02:00
|
|
|
}
|
2017-09-24 18:43:24 +02:00
|
|
|
|
2017-07-31 14:23:23 +02:00
|
|
|
return captured;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-06-11 20:53:43 +02:00
|
|
|
|
|
|
|
} // namespace chatterino
|