* LCIMLocationMessage.cs: chore: 完善地理位置消息序列化

* LCIMTypedMessage.cs:
oneRain 2020-04-28 12:13:03 +08:00
parent 8a036a6354
commit 5d0c5a32e6
2 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using LeanCloud.Storage; using LeanCloud.Storage;
namespace LeanCloud.Realtime { namespace LeanCloud.Realtime {
@ -21,6 +22,9 @@ namespace LeanCloud.Realtime {
} }
internal override Dictionary<string, object> Encode() { internal override Dictionary<string, object> Encode() {
if (Location == null) {
throw new ArgumentNullException(nameof(Location));
}
Dictionary<string, object> data = base.Encode(); Dictionary<string, object> data = base.Encode();
Dictionary<string, object> locationData = new Dictionary<string, object> { Dictionary<string, object> locationData = new Dictionary<string, object> {
{ MessageDataLongitudeKey, Location.Longitude }, { MessageDataLongitudeKey, Location.Longitude },
@ -34,6 +38,9 @@ namespace LeanCloud.Realtime {
base.Decode(msgData); base.Decode(msgData);
if (msgData.TryGetValue(MessageLocationKey, out object val)) { if (msgData.TryGetValue(MessageLocationKey, out object val)) {
Dictionary<string, object> locationData = val as Dictionary<string, object>; Dictionary<string, object> locationData = val as Dictionary<string, object>;
if (locationData == null) {
return;
}
double latitude = 0, longitude = 0; double latitude = 0, longitude = 0;
if (locationData.TryGetValue(MessageDataLatitudeKey, out object lat) && if (locationData.TryGetValue(MessageDataLatitudeKey, out object lat) &&
double.TryParse(lat as string, out double la)) { double.TryParse(lat as string, out double la)) {

View File

@ -125,6 +125,7 @@ namespace LeanCloud.Realtime {
// 未注册的类型消息 // 未注册的类型消息
message = new LCIMTypedMessage(); message = new LCIMTypedMessage();
} }
// 已知类型消息的固定
message.MessageType = msgType; message.MessageType = msgType;
if (msgData.TryGetValue(MessageAttributesKey, out object attrObj)) { if (msgData.TryGetValue(MessageAttributesKey, out object attrObj)) {
message.customProperties = LCDecoder.Decode(attrObj) as Dictionary<string, object>; message.customProperties = LCDecoder.Decode(attrObj) as Dictionary<string, object>;