mirror-chatterino2/src/messages/message.cpp

83 lines
2.2 KiB
C++
Raw Normal View History

2017-06-11 09:31:45 +02:00
#include "messages/message.hpp"
#include "messageelement.hpp"
2017-12-17 00:01:42 +01:00
#include "util/irchelpers.hpp"
using SBHighlight = chatterino::widgets::ScrollbarHighlight;
2018-01-06 03:48:56 +01:00
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace messages {
void Message::addElement(MessageElement *element)
2017-04-12 17:46:44 +02: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
const std::vector<std::unique_ptr<MessageElement>> &Message::getElements() const
2017-04-12 17:46:44 +02:00
{
return this->elements;
2017-04-12 17:46:44 +02:00
}
2017-01-07 20:43:55 +01:00
2018-01-06 03:48:56 +01:00
SBHighlight Message::getScrollBarHighlight() const
{
2018-01-28 03:29:42 +01:00
if (this->flags & Message::Highlighted) {
2018-01-06 03:48:56 +01:00
return SBHighlight(SBHighlight::Highlight);
}
return SBHighlight();
}
// Static
MessagePtr Message::createSystemMessage(const QString &text)
{
MessagePtr message(new Message);
message->addElement(new TimestampElement(QTime::currentTime()));
message->addElement(new TextElement(text, MessageElement::Text, MessageColor::System));
message->flags.EnableFlag(MessageFlags::System);
2018-01-28 03:29:42 +01:00
message->searchText = text;
return message;
}
MessagePtr Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
const QString &reason, bool multipleTimes)
{
QString text;
text.append(username);
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");
}
if (reason.length() > 0) {
text.append(": \"");
text.append(util::ParseTagString(reason));
text.append("\"");
}
text.append(".");
2018-01-05 23:14:55 +01:00
if (multipleTimes) {
text.append(" (multiple times)");
}
MessagePtr message = Message::createSystemMessage(text);
message->flags.EnableFlag(MessageFlags::System);
message->flags.EnableFlag(MessageFlags::Timeout);
2018-01-05 23:14:55 +01:00
message->timeoutUser = username;
return message;
}
2017-04-14 17:52:22 +02:00
} // namespace messages
} // namespace chatterino