#include "messages/message.hpp" #include "messageelement.hpp" #include "util/irchelpers.hpp" using SBHighlight = chatterino::widgets::ScrollbarHighlight; namespace chatterino { namespace messages { void Message::addElement(MessageElement *element) { this->elements.push_back(std::unique_ptr(element)); } const std::vector> &Message::getElements() const { return this->elements; } SBHighlight Message::getScrollBarHighlight() const { if (this->flags & Message::Highlighted) { 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); 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("."); if (multipleTimes) { text.append(" (multiple times)"); } MessagePtr message = Message::createSystemMessage(text); message->flags.EnableFlag(MessageFlags::System); message->flags.EnableFlag(MessageFlags::Timeout); message->timeoutUser = username; return message; } } // namespace messages } // namespace chatterino