Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): add basic message construction #5754

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: tests
  • Loading branch information
Nerixyz committed Dec 8, 2024

Verified

This commit was signed with the committer’s verified signature.
jennydaman Jennings Zhang
commit 5dee992fcd3bdde99321eee8ff80f3a81b75c5ba
22 changes: 18 additions & 4 deletions src/controllers/plugins/api/Message.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "controllers/plugins/api/Message.hpp"

#include "Application.hpp"
#include "messages/MessageElement.hpp"

#ifdef CHATTERINO_HAVE_PLUGINS
@@ -13,6 +14,20 @@ namespace {

using namespace chatterino;

QDateTime datetimeFromOffset(qint64 offset)
{
auto dt = QDateTime::fromMSecsSinceEpoch(offset);

# ifdef CHATTERINO_WITH_TESTS
if (getApp()->isTest())
{
return dt.toUTC();
}
# endif

return dt;
}

MessageColor tryMakeMessageColor(const QString &name,
MessageColor fallback = MessageColor::Text)
{
@@ -70,7 +85,7 @@ std::unique_ptr<TimestampElement> timestampElementFromTable(
if (time)
{
return std::make_unique<TimestampElement>(
QDateTime::fromMSecsSinceEpoch(*time).time());
datetimeFromOffset(*time).time());
}
return std::make_unique<TimestampElement>();
}
@@ -147,7 +162,7 @@ std::shared_ptr<Message> messageFromTable(const sol::table &tbl)
auto parseTime = tbl.get<std::optional<qint64>>("parse_time");
if (parseTime)
{
msg->parseTime = QDateTime::fromMSecsSinceEpoch(*parseTime).time();
msg->parseTime = datetimeFromOffset(*parseTime).time();
}

msg->id = tbl.get_or("id", QString{});
@@ -169,8 +184,7 @@ std::shared_ptr<Message> messageFromTable(const sol::table &tbl)
tbl.get<std::optional<qint64>>("server_received_time");
if (serverReceivedTime)
{
msg->serverReceivedTime =
QDateTime::fromMSecsSinceEpoch(*serverReceivedTime);
msg->serverReceivedTime = datetimeFromOffset(*serverReceivedTime);
}

// missing: badges
2 changes: 1 addition & 1 deletion tests/snapshots/PluginMessageCtor/properties.json
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
"loginName": "login",
"messageText": "message",
"searchText": "search",
"serverReceivedTime": "1970-01-01T01:20:30",
"serverReceivedTime": "1970-01-01T00:20:30Z",
"timeoutUser": "",
"usernameColor": "#ff0000ff"
}
4 changes: 2 additions & 2 deletions tests/snapshots/PluginMessageCtor/timestamp-element.json
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@
"trailingSpace": true,
"type": "TextElement",
"words": [
"1:20"
"0:20"
]
},
"flags": "Timestamp",
@@ -65,7 +65,7 @@
"type": "None",
"value": ""
},
"time": "01:20:30",
"time": "00:20:30",
"tooltip": "",
"trailingSpace": true,
"type": "TimestampElement"
Loading