diff --git a/ChatTwo/Message.cs b/ChatTwo/Message.cs index 3615738..54db588 100755 --- a/ChatTwo/Message.cs +++ b/ChatTwo/Message.cs @@ -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(code); this.Sender = BsonMapper.Global.Deserialize>(sender); this.Content = BsonMapper.Global.Deserialize>(content); - this.SenderSource = BsonMapper.Global.ToObject(senderSource); - this.ContentSource = BsonMapper.Global.ToObject(contentSource); + this.SenderSource = BsonMapper.Global.Deserialize(senderSource); + this.ContentSource = BsonMapper.Global.Deserialize(contentSource); this.SortCode = BsonMapper.Global.ToObject(sortCode); foreach (var chunk in this.Sender.Concat(this.Content)) { diff --git a/ChatTwo/Store.cs b/ChatTwo/Store.cs index 96c9985..dc04067 100755 --- a/ChatTwo/Store.cs +++ b/ChatTwo/Store.cs @@ -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( @@ -88,6 +88,22 @@ internal class Store : IDisposable { return Payload.Decode(new BinaryReader(new MemoryStream(bson.AsBinary))); }); + BsonMapper.Global.RegisterType( + 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