Merge branch 'master' of https://github.com/fourtf/chatterino2
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "ircmanager.hpp"
|
||||
#include "messages/link.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "util/irchelpers.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
@@ -70,5 +71,83 @@ const QString &Message::getId() const
|
||||
return this->id;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
void AddCurrentTimestamp(Message *message)
|
||||
{
|
||||
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,
|
||||
MessageColor(MessageColor::System), QString(), QString()));
|
||||
|
||||
// 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,
|
||||
MessageColor(MessageColor::System), QString(), QString()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/// Static
|
||||
Message *Message::createSystemMessage(const QString &text)
|
||||
{
|
||||
Message *message = new Message;
|
||||
|
||||
AddCurrentTimestamp(message);
|
||||
|
||||
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);
|
||||
|
||||
message->getWords().push_back(word);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
Message *Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
|
||||
const QString &reason)
|
||||
{
|
||||
Message *message = new Message;
|
||||
|
||||
AddCurrentTimestamp(message);
|
||||
|
||||
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(ParseTagString(reason));
|
||||
text.append("\"");
|
||||
}
|
||||
text.append(".");
|
||||
|
||||
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);
|
||||
|
||||
message->getWords().push_back(word);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
} // namespace messages
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -33,6 +33,11 @@ public:
|
||||
const QString text;
|
||||
bool centered = false;
|
||||
|
||||
static Message *createSystemMessage(const QString &text);
|
||||
|
||||
static Message *createTimeoutMessage(const QString &username, const QString &durationInSeconds,
|
||||
const QString &reason);
|
||||
|
||||
private:
|
||||
static LazyLoadedImage *badgeStaff;
|
||||
static LazyLoadedImage *badgeAdmin;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
MessageColor::MessageColor(const QColor &_color)
|
||||
: type(Type::Custom)
|
||||
, color(_color)
|
||||
@@ -34,5 +35,6 @@ const QColor &MessageColor::getColor(ColorScheme &colorScheme) const
|
||||
static QColor _default;
|
||||
return _default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace messages
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
namespace chatterino {
|
||||
namespace messages {
|
||||
|
||||
class MessageColor
|
||||
{
|
||||
public:
|
||||
@@ -21,5 +22,6 @@ private:
|
||||
Type type;
|
||||
QColor color;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace messages
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user