Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit b449346

Browse files
authored
[onebot] fix nullable (#825)
1 parent 225e1f0 commit b449346

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Lagrange.OneBot/Database/MessageChainFormatter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class MessageChainFormatter : IMessagePackFormatter<MessageChain?>
1414

1515
public void Serialize(ref MessagePackWriter writer, MessageChain? value, MessagePackSerializerOptions options)
1616
{
17-
MessagePackSerializer.Serialize(ref writer, (MessageRecord?)value, options);
17+
if (value == null) MessagePackSerializer.Serialize(ref writer, null as MessageRecord, options);
18+
else MessagePackSerializer.Serialize(ref writer, (MessageRecord)value, options);
1819
}
1920
}

Lagrange.OneBot/Database/MessageRecord.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static int CalcMessageHash(ulong msgId, uint seq)
7272
return ((ushort)seq << 16) | (ushort)msgId;
7373
}
7474

75-
public static implicit operator MessageRecord?(MessageChain? chain) => chain == null ? null : new()
75+
public static implicit operator MessageRecord(MessageChain chain) => new()
7676
{
7777
Id = CalcMessageHash(chain.MessageId, chain.Sequence),
7878
Type = chain.Type,
@@ -92,10 +92,8 @@ MessageType.Temp or
9292
Entities = MessagePackSerializer.Serialize<List<IMessageEntity>>(chain, OPTIONS)
9393
};
9494

95-
public static implicit operator MessageChain?(MessageRecord? record)
95+
public static implicit operator MessageChain(MessageRecord record)
9696
{
97-
if (record == null) return null;
98-
9997
var chain = record.Type switch
10098
{
10199
MessageType.Group => new MessageChain(

0 commit comments

Comments
 (0)