From b39034ab74e1fda5edae1fe009f3077da1cf256a Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 16 Dec 2017 19:03:22 +0100 Subject: [PATCH] Move message timestamp-code to its own function --- src/messages/message.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/messages/message.cpp b/src/messages/message.cpp index 2d15e6515..e0469b9f3 100644 --- a/src/messages/message.cpp +++ b/src/messages/message.cpp @@ -70,11 +70,10 @@ const QString &Message::getId() const return this->id; } -/// Static -Message *Message::createSystemMessage(const QString &text) -{ - Message *message = new Message; +namespace { +void AddCurrentTimestamp(Message *message) +{ std::time_t t; time(&t); char timeStampBuffer[69]; @@ -90,6 +89,23 @@ Message *Message::createSystemMessage(const QString &text) 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; +} Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);