2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/message.hpp"
|
2018-01-11 20:16:25 +01:00
|
|
|
#include "messageelement.hpp"
|
2017-12-17 00:01:42 +01:00
|
|
|
#include "util/irchelpers.hpp"
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2018-01-06 03:48:56 +01:00
|
|
|
typedef chatterino::widgets::ScrollbarHighlight SBHighlight;
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// elements
|
|
|
|
void Message::addElement(MessageElement *element)
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
this->elements.push_back(std::unique_ptr<MessageElement>(element));
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
const std::vector<std::unique_ptr<MessageElement>> &Message::getElements() const
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
return this->elements;
|
2017-04-12 17:46:44 +02:00
|
|
|
}
|
2017-01-07 20:43:55 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// Flags
|
|
|
|
Message::MessageFlags Message::getFlags() const
|
2017-04-12 17:46:44 +02:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
return this->flags;
|
2017-01-06 23:28:48 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
bool Message::hasFlags(MessageFlags _flags) const
|
2018-01-05 23:14:55 +01:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
return this->flags & _flags;
|
2018-01-05 23:14:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Message::setFlags(MessageFlags _flags)
|
|
|
|
{
|
|
|
|
this->flags = flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::addFlags(MessageFlags _flags)
|
|
|
|
{
|
|
|
|
this->flags = (MessageFlags)((MessageFlagsType)this->flags | (MessageFlagsType)_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Message::removeFlags(MessageFlags _flags)
|
|
|
|
{
|
|
|
|
this->flags = (MessageFlags)((MessageFlagsType)this->flags & ~((MessageFlagsType)_flags));
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// Parse Time
|
|
|
|
const QTime &Message::getParseTime() const
|
2017-01-07 20:43:55 +01:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
return this->parseTime;
|
2018-01-01 23:29:54 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// Id
|
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
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
void Message::setId(const QString &_id)
|
2017-12-19 00:09:38 +01:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
this->id = _id;
|
2017-12-19 00:09:38 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// Search
|
|
|
|
const QString &Message::getSearchText() const
|
2017-12-19 00:09:38 +01:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
// fourtf: asdf
|
|
|
|
// if (this->searchText.isNull()) {
|
|
|
|
// QString _content("");
|
2017-12-19 00:09:38 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// bool first;
|
2018-01-05 01:31:01 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// for (const MessageElement &word : this->words) {
|
|
|
|
// if (!first) {
|
|
|
|
// _content += "";
|
|
|
|
// }
|
2018-01-05 01:31:01 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// _content += word.getCopyText();
|
|
|
|
// first = false;
|
|
|
|
// }
|
2018-01-05 13:42:23 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// this->searchText = _content;
|
|
|
|
// }
|
2018-01-05 13:42:23 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// return this->searchText;
|
2018-01-05 13:42:23 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
static QString xd;
|
2018-01-05 13:42:23 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
return xd;
|
2018-01-05 13:42:23 +01:00
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// Highlight
|
2018-01-06 03:48:56 +01:00
|
|
|
SBHighlight Message::getScrollBarHighlight() const
|
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
if (this->hasFlags(Message::Highlighted)) {
|
2018-01-06 03:48:56 +01:00
|
|
|
return SBHighlight(SBHighlight::Highlight);
|
|
|
|
}
|
|
|
|
return SBHighlight();
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
// Static
|
|
|
|
MessagePtr Message::createSystemMessage(const QString &text)
|
2017-12-16 19:03:22 +01:00
|
|
|
{
|
2018-01-11 20:16:25 +01:00
|
|
|
MessagePtr message(new Message);
|
2017-12-16 19:03:22 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
message->addElement(new TimestampElement(QTime::currentTime()));
|
|
|
|
message->addElement(new TextElement(text, MessageElement::Text, MessageColor::System));
|
2018-01-05 23:14:55 +01:00
|
|
|
message->addFlags(Message::System);
|
2017-12-16 19:03:22 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
return MessagePtr(message);
|
2017-12-16 19:03:22 +01:00
|
|
|
}
|
2017-12-16 18:11:36 +01:00
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
MessagePtr Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
|
|
|
|
const QString &reason, bool multipleTimes)
|
2017-12-16 19:08:32 +01:00
|
|
|
{
|
|
|
|
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(": \"");
|
2018-01-11 20:16:25 +01:00
|
|
|
text.append(util::ParseTagString(reason));
|
2017-12-16 19:08:32 +01:00
|
|
|
text.append("\"");
|
|
|
|
}
|
|
|
|
text.append(".");
|
|
|
|
|
2018-01-05 23:14:55 +01:00
|
|
|
if (multipleTimes) {
|
|
|
|
text.append(" (multiple times)");
|
|
|
|
}
|
|
|
|
|
2018-01-11 20:16:25 +01:00
|
|
|
MessagePtr message = Message::createSystemMessage(text);
|
2018-01-05 23:14:55 +01:00
|
|
|
message->addFlags(Message::Timeout);
|
|
|
|
message->timeoutUser = username;
|
|
|
|
return message;
|
2017-12-16 18:11:36 +01:00
|
|
|
}
|
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|