diff --git a/Lagrange.Core/Internal/Service/Message/MultiMsgUploadService.cs b/Lagrange.Core/Internal/Service/Message/MultiMsgUploadService.cs index 1be619593..207af4c07 100644 --- a/Lagrange.Core/Internal/Service/Message/MultiMsgUploadService.cs +++ b/Lagrange.Core/Internal/Service/Message/MultiMsgUploadService.cs @@ -18,8 +18,7 @@ protected override bool Build(MultiMsgUploadEvent input, BotKeystore keystore, B { if (input.Chains == null) throw new ArgumentNullException(nameof(input.Chains)); - var msgPacker = new MessagePacker(keystore.Uid ?? ""); - var msgBody = input.Chains.Select(msgPacker.BuildFake).ToList(); + var msgBody = input.Chains.Select(x => MessagePacker.BuildFake(x, keystore.Uid ?? "")).ToList(); var longMsgResult = new LongMsgResult { Action = new LongMsgAction diff --git a/Lagrange.Core/Internal/Service/Message/SendMessageService.cs b/Lagrange.Core/Internal/Service/Message/SendMessageService.cs index 9c0ca0a06..6e74529d0 100644 --- a/Lagrange.Core/Internal/Service/Message/SendMessageService.cs +++ b/Lagrange.Core/Internal/Service/Message/SendMessageService.cs @@ -15,8 +15,7 @@ internal class SendMessageService : BaseService protected override bool Build(SendMessageEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out BinaryPacket output, out List? extraPackets) { - var packer = new MessagePacker(keystore.Uid ?? throw new Exception("No UID found in keystore")); - var packet = packer.Build(input.Chain); + var packet = MessagePacker.Build(input.Chain, keystore.Uid ?? throw new Exception("No UID found in keystore")); using var stream = new MemoryStream(); Serializer.Serialize(stream, packet); diff --git a/Lagrange.Core/Message/MessagePacker.cs b/Lagrange.Core/Message/MessagePacker.cs index cd80aa6ab..19d78dc71 100644 --- a/Lagrange.Core/Message/MessagePacker.cs +++ b/Lagrange.Core/Message/MessagePacker.cs @@ -19,14 +19,12 @@ namespace Lagrange.Core.Message; /// /// Pack up message into the Protobuf /// -internal class MessagePacker +internal static class MessagePacker { private static readonly Dictionary> EntityToElem; private static readonly Dictionary Factory; private static readonly List MsgFactory; - - private readonly string _selfUid; - + static MessagePacker() { EntityToElem = new Dictionary>(); @@ -56,19 +54,14 @@ static MessagePacker() MsgFactory = assembly.GetImplementations().Select(type => (IMessageEntity)type.CreateInstance()).ToList(); } - - public MessagePacker(string selfUid) - { - _selfUid = selfUid; - } - public Internal.Packets.Message.Message Build(MessageChain chain) + public static Internal.Packets.Message.Message Build(MessageChain chain, string selfUid) { var message = BuildPacketBase(chain); foreach (var entity in chain) { - entity.SetSelfUid(_selfUid); + entity.SetSelfUid(selfUid); if (message.Body != null) { @@ -86,13 +79,13 @@ public Internal.Packets.Message.Message Build(MessageChain chain) return message; } - public PushMsgBody BuildFake(MessageChain chain) + public static PushMsgBody BuildFake(MessageChain chain, string selfUid) { var message = BuildFakePacketBase(chain); foreach (var entity in chain) { - entity.SetSelfUid(_selfUid); + entity.SetSelfUid(selfUid); if (message.Body != null) {