2017-06-11 09:31:45 +02:00
|
|
|
#include "messagebuilder.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/thememanager.hpp"
|
|
|
|
#include "singletons/emotemanager.hpp"
|
2017-06-11 09:31:45 +02:00
|
|
|
#include "resources.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 {
|
|
|
|
namespace messages {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
MessageBuilder::MessageBuilder()
|
2017-09-12 19:06:16 +02:00
|
|
|
: message(new Message)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
|
|
|
_parseTime = std::chrono::system_clock::now();
|
|
|
|
}
|
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
SharedMessage MessageBuilder::getMessage()
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-12 19:06:16 +02:00
|
|
|
return this->message;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 19:06:16 +02:00
|
|
|
void MessageBuilder::appendWord(const Word &&word)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-12 19:06:16 +02:00
|
|
|
this->message->getWords().push_back(word);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageBuilder::appendTimestamp()
|
|
|
|
{
|
2017-12-27 01:22:12 +01:00
|
|
|
QDateTime t = QDateTime::currentDateTime();
|
2017-09-24 18:43:24 +02:00
|
|
|
this->appendTimestamp(t);
|
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
|
|
|
{
|
2017-09-24 18:43:24 +02:00
|
|
|
this->message->setHighlight(value);
|
2017-07-31 00:37:22 +02:00
|
|
|
}
|
|
|
|
|
2017-12-27 01:22:12 +01:00
|
|
|
void MessageBuilder::appendTimestamp(QDateTime &time)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-06-11 21:01:08 +02:00
|
|
|
// Add word for timestamp with no seconds
|
2017-12-27 01:22:12 +01:00
|
|
|
QString timestampNoSeconds(time.toString("hh:mm"));
|
2017-09-24 18:43:24 +02:00
|
|
|
this->appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds,
|
2017-12-23 21:18:13 +01:00
|
|
|
MessageColor(MessageColor::System), FontManager::Medium, QString(),
|
|
|
|
QString()));
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-06-11 21:01:08 +02:00
|
|
|
// Add word for timestamp with seconds
|
2017-12-27 01:22:12 +01:00
|
|
|
QString timestampWithSeconds(time.toString("hh:mm:ss"));
|
2017-09-24 18:43:24 +02:00
|
|
|
this->appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds,
|
2017-12-23 21:18:13 +01:00
|
|
|
MessageColor(MessageColor::System), FontManager::Medium, QString(),
|
|
|
|
QString()));
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MessageBuilder::matchLink(const QString &string)
|
|
|
|
{
|
2017-09-12 19:06:16 +02:00
|
|
|
static QRegularExpression linkRegex("[[:ascii:]]*\\.[a-zA-Z]+\\/?[[:ascii:]]*");
|
|
|
|
static QRegularExpression httpRegex("\\bhttps?://");
|
|
|
|
|
2017-08-05 18:44:14 +02:00
|
|
|
auto match = linkRegex.match(string);
|
2017-08-12 12:09:26 +02:00
|
|
|
|
|
|
|
if (!match.hasMatch()) {
|
|
|
|
return QString();
|
|
|
|
}
|
2017-08-05 18:44:14 +02:00
|
|
|
|
2017-07-31 14:23:23 +02:00
|
|
|
QString captured = match.captured();
|
|
|
|
|
2017-09-12 19:06:16 +02:00
|
|
|
if (!captured.contains(httpRegex)) {
|
2017-07-31 14:23:23 +02:00
|
|
|
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 messages
|
|
|
|
} // namespace chatterino
|