fix: process SeStrings correctly

This commit is contained in:
Anna 2022-02-16 01:52:13 -05:00
parent a219f86833
commit 8fa00a8c95
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
2 changed files with 21 additions and 5 deletions

View File

@ -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.Receiver = receiver;
this.ContentId = contentId;
@ -62,8 +62,8 @@ internal class Message {
this.Code = BsonMapper.Global.ToObject<ChatCode>(code);
this.Sender = BsonMapper.Global.Deserialize<List<Chunk>>(sender);
this.Content = BsonMapper.Global.Deserialize<List<Chunk>>(content);
this.SenderSource = BsonMapper.Global.ToObject<SeString>(senderSource);
this.ContentSource = BsonMapper.Global.ToObject<SeString>(contentSource);
this.SenderSource = BsonMapper.Global.Deserialize<SeString>(senderSource);
this.ContentSource = BsonMapper.Global.Deserialize<SeString>(contentSource);
this.SortCode = BsonMapper.Global.ToObject<SortCode>(sortCode);
foreach (var chunk in this.Sender.Concat(this.Content)) {

View File

@ -52,8 +52,8 @@ internal class Store : IDisposable {
doc["Code"].AsDocument,
doc["Sender"].AsArray,
doc["Content"].AsArray,
doc["SenderSource"].AsDocument,
doc["ContentSource"].AsDocument,
doc["SenderSource"],
doc["ContentSource"],
doc["SortCode"].AsDocument
));
BsonMapper.Global.RegisterType<Payload?>(
@ -88,6 +88,22 @@ internal class Store : IDisposable {
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(
type => (int) type,
bson => (ChatType) bson.AsInt32