2017-06-11 09:31:45 +02:00
|
|
|
#include "messagebuilder.hpp"
|
|
|
|
#include "colorscheme.hpp"
|
|
|
|
#include "emotemanager.hpp"
|
|
|
|
#include "resources.hpp"
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
2017-04-12 17:46:44 +02:00
|
|
|
|
|
|
|
MessageBuilder::MessageBuilder()
|
|
|
|
: _words()
|
|
|
|
{
|
|
|
|
_parseTime = std::chrono::system_clock::now();
|
2017-07-26 12:01:23 +02:00
|
|
|
regex.setPattern("(\\bhttps?:\/\/)?[-A-Z0-9+&@#\/%?=~_|!:,.;]*[A-Z0-9+&@#\/%=~_|]");
|
2017-07-26 09:08:19 +02:00
|
|
|
regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SharedMessage MessageBuilder::build()
|
|
|
|
{
|
2017-06-06 21:18:05 +02:00
|
|
|
return SharedMessage(new Message(this->originalMessage, _words));
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MessageBuilder::appendWord(const Word &word)
|
|
|
|
{
|
|
|
|
_words.push_back(word);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageBuilder::appendTimestamp()
|
|
|
|
{
|
|
|
|
time_t t;
|
|
|
|
time(&t);
|
|
|
|
appendTimestamp(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageBuilder::appendTimestamp(time_t time)
|
|
|
|
{
|
|
|
|
char timeStampBuffer[69];
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
// TODO(pajlada): Fix this
|
|
|
|
QColor systemMessageColor(140, 127, 127);
|
|
|
|
// QColor &systemMessageColor = ColorScheme::getInstance().SystemMessageColor;
|
|
|
|
|
2017-06-11 21:01:08 +02:00
|
|
|
// Add word for timestamp with no seconds
|
2017-04-12 17:46:44 +02:00
|
|
|
strftime(timeStampBuffer, 69, "%H:%M", localtime(&time));
|
2017-06-11 21:01:08 +02:00
|
|
|
QString timestampNoSeconds(timeStampBuffer);
|
2017-06-26 16:41:20 +02:00
|
|
|
appendWord(Word(timestampNoSeconds, Word::TimestampNoSeconds, systemMessageColor, 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-04-12 17:46:44 +02:00
|
|
|
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&time));
|
2017-06-11 21:01:08 +02:00
|
|
|
QString timestampWithSeconds(timeStampBuffer);
|
2017-06-26 16:41:20 +02:00
|
|
|
appendWord(Word(timestampWithSeconds, Word::TimestampWithSeconds, systemMessageColor, QString(),
|
|
|
|
QString()));
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MessageBuilder::matchLink(const QString &string)
|
|
|
|
{
|
2017-07-26 12:01:23 +02:00
|
|
|
QString match = regex.match(string,0,QRegularExpression::PartialPreferCompleteMatch,QRegularExpression::NoMatchOption).captured();
|
|
|
|
if(!match.contains(QRegularExpression("\\bhttps?:\/\/"))){
|
|
|
|
match.insert(0,"https://");
|
|
|
|
}
|
|
|
|
return match;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-06-11 20:53:43 +02:00
|
|
|
|
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|