fix: process SeStrings correctly
This commit is contained in:
parent
a219f86833
commit
8fa00a8c95
|
@ -54,7 +54,7 @@ internal class Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Message(ObjectId id, ulong receiver, ulong contentId, DateTime date, BsonDocument code, BsonArray sender, BsonArray content, BsonDocument senderSource, BsonDocument contentSource, BsonDocument sortCode) {
|
internal Message(ObjectId id, ulong receiver, ulong contentId, DateTime date, BsonDocument code, BsonArray sender, BsonArray content, BsonValue senderSource, BsonValue contentSource, BsonDocument sortCode) {
|
||||||
this.Id = id;
|
this.Id = id;
|
||||||
this.Receiver = receiver;
|
this.Receiver = receiver;
|
||||||
this.ContentId = contentId;
|
this.ContentId = contentId;
|
||||||
|
@ -62,8 +62,8 @@ internal class Message {
|
||||||
this.Code = BsonMapper.Global.ToObject<ChatCode>(code);
|
this.Code = BsonMapper.Global.ToObject<ChatCode>(code);
|
||||||
this.Sender = BsonMapper.Global.Deserialize<List<Chunk>>(sender);
|
this.Sender = BsonMapper.Global.Deserialize<List<Chunk>>(sender);
|
||||||
this.Content = BsonMapper.Global.Deserialize<List<Chunk>>(content);
|
this.Content = BsonMapper.Global.Deserialize<List<Chunk>>(content);
|
||||||
this.SenderSource = BsonMapper.Global.ToObject<SeString>(senderSource);
|
this.SenderSource = BsonMapper.Global.Deserialize<SeString>(senderSource);
|
||||||
this.ContentSource = BsonMapper.Global.ToObject<SeString>(contentSource);
|
this.ContentSource = BsonMapper.Global.Deserialize<SeString>(contentSource);
|
||||||
this.SortCode = BsonMapper.Global.ToObject<SortCode>(sortCode);
|
this.SortCode = BsonMapper.Global.ToObject<SortCode>(sortCode);
|
||||||
|
|
||||||
foreach (var chunk in this.Sender.Concat(this.Content)) {
|
foreach (var chunk in this.Sender.Concat(this.Content)) {
|
||||||
|
|
|
@ -52,8 +52,8 @@ internal class Store : IDisposable {
|
||||||
doc["Code"].AsDocument,
|
doc["Code"].AsDocument,
|
||||||
doc["Sender"].AsArray,
|
doc["Sender"].AsArray,
|
||||||
doc["Content"].AsArray,
|
doc["Content"].AsArray,
|
||||||
doc["SenderSource"].AsDocument,
|
doc["SenderSource"],
|
||||||
doc["ContentSource"].AsDocument,
|
doc["ContentSource"],
|
||||||
doc["SortCode"].AsDocument
|
doc["SortCode"].AsDocument
|
||||||
));
|
));
|
||||||
BsonMapper.Global.RegisterType<Payload?>(
|
BsonMapper.Global.RegisterType<Payload?>(
|
||||||
|
@ -88,6 +88,22 @@ internal class Store : IDisposable {
|
||||||
|
|
||||||
return Payload.Decode(new BinaryReader(new MemoryStream(bson.AsBinary)));
|
return Payload.Decode(new BinaryReader(new MemoryStream(bson.AsBinary)));
|
||||||
});
|
});
|
||||||
|
BsonMapper.Global.RegisterType<SeString?>(
|
||||||
|
seString => seString == null
|
||||||
|
? null
|
||||||
|
: new BsonArray(seString.Payloads.Select(payload => new BsonValue(payload.Encode()))),
|
||||||
|
bson => {
|
||||||
|
if (bson.IsNull) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var array = bson.IsArray ? bson.AsArray : bson["Payloads"].AsArray;
|
||||||
|
var payloads = array
|
||||||
|
.Select(payload => Payload.Decode(new BinaryReader(new MemoryStream(payload.AsBinary))))
|
||||||
|
.ToList();
|
||||||
|
return new SeString(payloads);
|
||||||
|
}
|
||||||
|
);
|
||||||
BsonMapper.Global.RegisterType(
|
BsonMapper.Global.RegisterType(
|
||||||
type => (int) type,
|
type => (int) type,
|
||||||
bson => (ChatType) bson.AsInt32
|
bson => (ChatType) bson.AsInt32
|
||||||
|
|
Loading…
Reference in New Issue