2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/message.hpp"
|
|
|
|
#include "channel.hpp"
|
|
|
|
#include "emojis.hpp"
|
2018-01-01 23:29:54 +01:00
|
|
|
#include "messages/link.hpp"
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/emotemanager.hpp"
|
|
|
|
#include "singletons/fontmanager.hpp"
|
|
|
|
#include "singletons/ircmanager.hpp"
|
2017-12-31 02:21:33 +01:00
|
|
|
#include "singletons/resourcemanager.hpp"
|
2018-01-01 23:29:54 +01:00
|
|
|
#include "singletons/thememanager.hpp"
|
2017-12-17 00:01:42 +01:00
|
|
|
#include "util/irchelpers.hpp"
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-01-05 16:43:01 +01:00
|
|
|
#include <ctime>
|
2017-01-11 01:08:20 +01:00
|
|
|
#include <list>
|
2017-01-11 18:52:09 +01:00
|
|
|
#include <tuple>
|
2017-01-05 16:43:01 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-12-26 12:32:24 +01:00
|
|
|
bool Message::containsHighlightedPhrase() const
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-09-24 18:43:24 +02:00
|
|
|
return this->highlightTab;
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
|
|
|
|
2017-09-24 18:43:24 +02:00
|
|
|
void Message::setHighlight(bool value)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2017-09-24 18:43:24 +02:00
|
|
|
this->highlightTab = value;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &Message::getTimeoutUser() const
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->timeoutUser;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
int Message::getTimeoutCount() const
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->timeoutCount;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &Message::getContent() const
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->content;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const std::chrono::time_point<std::chrono::system_clock> &Message::getParseTime() const
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->parseTime;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
std::vector<Word> &Message::getWords()
|
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->words;
|
2017-01-06 23:28:48 +01:00
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
bool Message::isDisabled() const
|
2017-01-07 20:43:55 +01:00
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->disabled;
|
2017-01-07 20:43:55 +01:00
|
|
|
}
|
2017-01-28 20:29:02 +01:00
|
|
|
|
2018-01-01 23:29:54 +01:00
|
|
|
void Message::setDisabled(bool value)
|
|
|
|
{
|
|
|
|
this->disabled = value;
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
const QString &Message::getId() const
|
2017-01-28 20:29:02 +01:00
|
|
|
{
|
2017-06-13 22:03:29 +02:00
|
|
|
return this->id;
|
2017-01-18 21:30:23 +01:00
|
|
|
}
|
2017-01-28 20:29:02 +01:00
|
|
|
|
2017-12-19 00:09:38 +01:00
|
|
|
bool Message::getCollapsedDefault() const
|
|
|
|
{
|
|
|
|
return this->collapsedDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::setCollapsedDefault(bool value)
|
|
|
|
{
|
|
|
|
this->collapsedDefault = value;
|
|
|
|
}
|
|
|
|
|
2018-01-05 01:31:01 +01:00
|
|
|
bool Message::getDisableCompactEmotes() const
|
|
|
|
{
|
|
|
|
return this->disableCompactEmotes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::setDisableCompactEmotes(bool value)
|
|
|
|
{
|
|
|
|
this->disableCompactEmotes = value;
|
|
|
|
}
|
|
|
|
|
2017-12-16 19:03:22 +01:00
|
|
|
namespace {
|
2017-12-16 18:11:36 +01:00
|
|
|
|
2017-12-16 19:03:22 +01:00
|
|
|
void AddCurrentTimestamp(Message *message)
|
|
|
|
{
|
2017-12-16 18:11:36 +01:00
|
|
|
std::time_t t;
|
|
|
|
time(&t);
|
|
|
|
char timeStampBuffer[69];
|
|
|
|
|
|
|
|
// Add word for timestamp with no seconds
|
|
|
|
strftime(timeStampBuffer, 69, "%H:%M", localtime(&t));
|
|
|
|
QString timestampNoSeconds(timeStampBuffer);
|
|
|
|
message->getWords().push_back(Word(timestampNoSeconds, Word::TimestampNoSeconds,
|
2018-01-01 23:29:54 +01:00
|
|
|
MessageColor(MessageColor::System),
|
|
|
|
singletons::FontManager::Medium, QString(), QString()));
|
2017-12-16 18:11:36 +01:00
|
|
|
|
|
|
|
// Add word for timestamp with seconds
|
|
|
|
strftime(timeStampBuffer, 69, "%H:%M:%S", localtime(&t));
|
|
|
|
QString timestampWithSeconds(timeStampBuffer);
|
|
|
|
message->getWords().push_back(Word(timestampWithSeconds, Word::TimestampWithSeconds,
|
2018-01-01 23:29:54 +01:00
|
|
|
MessageColor(MessageColor::System),
|
|
|
|
singletons::FontManager::Medium, QString(), QString()));
|
2017-12-16 19:03:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/// Static
|
|
|
|
Message *Message::createSystemMessage(const QString &text)
|
|
|
|
{
|
|
|
|
Message *message = new Message;
|
|
|
|
|
|
|
|
AddCurrentTimestamp(message);
|
|
|
|
|
2017-12-24 00:24:35 +01:00
|
|
|
QStringList words = text.split(' ');
|
2017-12-16 19:03:22 +01:00
|
|
|
|
2017-12-24 00:24:35 +01:00
|
|
|
for (QString word : words) {
|
|
|
|
message->getWords().push_back(Word(word, Word::Flags::Default,
|
|
|
|
MessageColor(MessageColor::Type::System),
|
2017-12-31 22:58:35 +01:00
|
|
|
singletons::FontManager::Medium, word, QString()));
|
2017-12-24 00:24:35 +01:00
|
|
|
}
|
2017-12-16 19:03:22 +01:00
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
2017-12-16 18:11:36 +01:00
|
|
|
|
2017-12-16 19:08:32 +01:00
|
|
|
Message *Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
|
|
|
|
const QString &reason)
|
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
text.append(username);
|
2017-12-16 19:45:23 +01:00
|
|
|
if (!durationInSeconds.isEmpty()) {
|
|
|
|
text.append(" has been timed out");
|
|
|
|
|
|
|
|
// TODO: Implement who timed the user out
|
|
|
|
|
|
|
|
text.append(" for ");
|
|
|
|
text.append(durationInSeconds);
|
|
|
|
bool ok = true;
|
|
|
|
int timeoutDuration = durationInSeconds.toInt(&ok);
|
|
|
|
text.append(" second");
|
|
|
|
if (ok && timeoutDuration > 1) {
|
|
|
|
text.append("s");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
text.append(" has been permanently banned");
|
2017-12-16 19:08:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (reason.length() > 0) {
|
|
|
|
text.append(": \"");
|
2017-12-17 00:01:42 +01:00
|
|
|
text.append(ParseTagString(reason));
|
2017-12-16 19:08:32 +01:00
|
|
|
text.append("\"");
|
|
|
|
}
|
|
|
|
text.append(".");
|
|
|
|
|
2018-01-01 23:29:54 +01:00
|
|
|
return Message::createSystemMessage(text);
|
2017-12-16 18:11:36 +01:00
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|