Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 28f7ceb

Browse files
committed
修复: ForwardMessage::Node::MessageId 可能为 null.
1 parent 2a82757 commit 28f7ceb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

include/mirai/messages/ForwardMessage.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ namespace Cyan
1717
class Node : ISerializable
1818
{
1919
public:
20-
MessageId_t MessageId;
2120
int64_t Timestamp;
2221
QQ_t SenderId;
2322
string SenderName;
23+
std::optional<MessageId_t> MessageId;
2424
MessageChain_t MessageChain;
2525

2626
bool operator==(const Node& node) const
@@ -51,7 +51,10 @@ namespace Cyan
5151
virtual bool Set(const json& json) override
5252
{
5353
auto& messageIdJson = json["messageId"];
54-
MessageId = messageIdJson.is_null() ? 0 : messageIdJson.get<int64_t>();
54+
if (!messageIdJson.is_null())
55+
{
56+
MessageId = messageIdJson.get<int64_t>();
57+
}
5558
SenderId = QQ_t(json["senderId"].get<int64_t>());
5659
Timestamp = json["time"].get<int64_t>();
5760
SenderName = json["senderName"].get<string>();
@@ -61,14 +64,22 @@ namespace Cyan
6164

6265
virtual json ToJson() const override
6366
{
64-
return
67+
json result =
6568
{
6669
{ "senderId", SenderId.ToInt64() },
6770
{ "time", Timestamp },
6871
{ "senderName", SenderName },
69-
{ "messageId", MessageId },
7072
{ "messageChain", MessageChain.ToJson() }
7173
};
74+
if (MessageId.has_value())
75+
{
76+
result["messageId"] = MessageId.value();
77+
}
78+
else
79+
{
80+
result["messageId"] = nullptr;
81+
}
82+
return result;
7283
}
7384
};
7485

0 commit comments

Comments
 (0)