* LCIMFileMessage.cs:
* LCIMAudioMessage.cs: * LCIMImageMessage.cs: * LCIMVideoMessage.cs: chore: 完善富媒体消息
parent
c66ce32f9a
commit
63552e17de
|
@ -24,7 +24,8 @@ namespace LeanCloud.Realtime {
|
||||||
Dictionary<string, object> data = base.Encode();
|
Dictionary<string, object> data = base.Encode();
|
||||||
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
||||||
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration)) {
|
if (File.MetaData != null &&
|
||||||
|
File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration)) {
|
||||||
metaData[MessageDataMetaDurationKey] = duration;
|
metaData[MessageDataMetaDurationKey] = duration;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
@ -32,6 +33,10 @@ namespace LeanCloud.Realtime {
|
||||||
|
|
||||||
internal override void Decode(Dictionary<string, object> msgData) {
|
internal override void Decode(Dictionary<string, object> msgData) {
|
||||||
base.Decode(msgData);
|
base.Decode(msgData);
|
||||||
|
|
||||||
|
if (File.MetaData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration) &&
|
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration) &&
|
||||||
double.TryParse(duration as string, out double d)) {
|
double.TryParse(duration as string, out double d)) {
|
||||||
Duration = d;
|
Duration = d;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using LeanCloud.Storage;
|
using LeanCloud.Storage;
|
||||||
|
|
||||||
|
@ -18,21 +19,14 @@ namespace LeanCloud.Realtime {
|
||||||
/// 文件大小
|
/// 文件大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Size {
|
public int Size {
|
||||||
get {
|
get; private set;
|
||||||
if (int.TryParse(File.MetaData[MessageDataMetaSizeKey] as string, out int size)) {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件类型
|
/// 文件扩展名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Format {
|
public string Format {
|
||||||
get {
|
get; private set;
|
||||||
return File.MimeType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -58,18 +52,47 @@ namespace LeanCloud.Realtime {
|
||||||
if (File == null) {
|
if (File == null) {
|
||||||
throw new Exception("File MUST NOT be null before sent.");
|
throw new Exception("File MUST NOT be null before sent.");
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(File.ObjectId)) {
|
||||||
|
throw new Exception("File MUST be saved before sent.");
|
||||||
|
}
|
||||||
Dictionary<string, object> fileData = new Dictionary<string, object> {
|
Dictionary<string, object> fileData = new Dictionary<string, object> {
|
||||||
{ MessageDataObjectIdKey, File.ObjectId },
|
{ MessageDataObjectIdKey, File.ObjectId }
|
||||||
{ MessageDataUrlKey, File.Url },
|
|
||||||
{ MessageDataMetaDataKey, new Dictionary<string, object> {
|
|
||||||
{ MessageDataMetaNameKey, File.Name },
|
|
||||||
{ MessageDataMetaFormatKey, File.MimeType }
|
|
||||||
} }
|
|
||||||
};
|
};
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaSizeKey, out object size)) {
|
// 链接
|
||||||
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
if (!string.IsNullOrEmpty(File.Url)) {
|
||||||
|
fileData[MessageDataUrlKey] = File.Url;
|
||||||
|
}
|
||||||
|
// 元数据
|
||||||
|
Dictionary<string, object> metaData = new Dictionary<string, object>();
|
||||||
|
// 文件名
|
||||||
|
if (!string.IsNullOrEmpty(File.Name)) {
|
||||||
|
metaData[MessageDataMetaNameKey] = File.Name;
|
||||||
|
}
|
||||||
|
// 文件扩展名
|
||||||
|
string format = null;
|
||||||
|
if (File.MetaData != null &&
|
||||||
|
File.MetaData.TryGetValue(MessageDataMetaFormatKey, out object f)) {
|
||||||
|
// 优先使用用户设置值
|
||||||
|
format = f as string;
|
||||||
|
} else if (File.Name != null &&
|
||||||
|
!string.IsNullOrEmpty(Path.GetExtension(File.Name))) {
|
||||||
|
// 根据文件名推测
|
||||||
|
format = Path.GetExtension(File.Name)?.Replace(".", string.Empty);
|
||||||
|
} else if (File.Url != null &&
|
||||||
|
!string.IsNullOrEmpty(Path.GetExtension(File.Url))) {
|
||||||
|
// 根据 url 推测
|
||||||
|
format = Path.GetExtension(File.Url)?.Replace(".", string.Empty);
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(format)) {
|
||||||
|
metaData[MessageDataMetaFormatKey] = format;
|
||||||
|
}
|
||||||
|
// 文件大小
|
||||||
|
if (File.MetaData != null &&
|
||||||
|
File.MetaData.TryGetValue(MessageDataMetaSizeKey, out object size)) {
|
||||||
metaData[MessageDataMetaSizeKey] = size;
|
metaData[MessageDataMetaSizeKey] = size;
|
||||||
}
|
}
|
||||||
|
fileData[MessageDataMetaDataKey] = metaData;
|
||||||
|
|
||||||
Dictionary<string, object> data = base.Encode();
|
Dictionary<string, object> data = base.Encode();
|
||||||
data[MessageFileKey] = fileData;
|
data[MessageFileKey] = fileData;
|
||||||
return data;
|
return data;
|
||||||
|
@ -80,6 +103,9 @@ namespace LeanCloud.Realtime {
|
||||||
|
|
||||||
if (msgData.TryGetValue(MessageFileKey, out object fileDataObject)) {
|
if (msgData.TryGetValue(MessageFileKey, out object fileDataObject)) {
|
||||||
Dictionary<string, object> fileData = fileDataObject as Dictionary<string, object>;
|
Dictionary<string, object> fileData = fileDataObject as Dictionary<string, object>;
|
||||||
|
if (fileData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (fileData.TryGetValue(MessageDataObjectIdKey, out object objectIdObject)) {
|
if (fileData.TryGetValue(MessageDataObjectIdKey, out object objectIdObject)) {
|
||||||
string objectId = objectIdObject as string;
|
string objectId = objectIdObject as string;
|
||||||
File = LCObject.CreateWithoutData(LCFile.CLASS_NAME, objectId) as LCFile;
|
File = LCObject.CreateWithoutData(LCFile.CLASS_NAME, objectId) as LCFile;
|
||||||
|
@ -88,9 +114,19 @@ namespace LeanCloud.Realtime {
|
||||||
}
|
}
|
||||||
if (fileData.TryGetValue(MessageDataMetaDataKey, out object metaData)) {
|
if (fileData.TryGetValue(MessageDataMetaDataKey, out object metaData)) {
|
||||||
File.MetaData = metaData as Dictionary<string, object>;
|
File.MetaData = metaData as Dictionary<string, object>;
|
||||||
|
if (File.MetaData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaNameKey, out object name)) {
|
if (File.MetaData.TryGetValue(MessageDataMetaNameKey, out object name)) {
|
||||||
File.Name = name as string;
|
File.Name = name as string;
|
||||||
}
|
}
|
||||||
|
if (File.MetaData.TryGetValue(MessageDataMetaSizeKey, out object size) &&
|
||||||
|
int.TryParse(size as string, out int s)) {
|
||||||
|
Size = s;
|
||||||
|
}
|
||||||
|
if (File.MetaData.TryGetValue(MessageDataMetaFormatKey, out object format)) {
|
||||||
|
Format = format as string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,17 +31,23 @@ namespace LeanCloud.Realtime {
|
||||||
Dictionary<string, object> data = base.Encode();
|
Dictionary<string, object> data = base.Encode();
|
||||||
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
||||||
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
|
if (File.MetaData != null) {
|
||||||
metaData[MessageDataMetaWidthKey] = width;
|
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
|
||||||
}
|
metaData[MessageDataMetaWidthKey] = width;
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height)) {
|
}
|
||||||
metaData[MessageDataMetaHeightKey] = height;
|
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height)) {
|
||||||
|
metaData[MessageDataMetaHeightKey] = height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void Decode(Dictionary<string, object> msgData) {
|
internal override void Decode(Dictionary<string, object> msgData) {
|
||||||
base.Decode(msgData);
|
base.Decode(msgData);
|
||||||
|
|
||||||
|
if (File.MetaData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
|
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
|
||||||
int.TryParse(width as string, out int w)) {
|
int.TryParse(width as string, out int w)) {
|
||||||
Width = w;
|
Width = w;
|
||||||
|
|
|
@ -38,20 +38,26 @@ namespace LeanCloud.Realtime {
|
||||||
Dictionary<string, object> data = base.Encode();
|
Dictionary<string, object> data = base.Encode();
|
||||||
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
||||||
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
|
if (File.MetaData != null) {
|
||||||
metaData[MessageDataMetaWidthKey] = width;
|
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
|
||||||
}
|
metaData[MessageDataMetaWidthKey] = width;
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height)) {
|
}
|
||||||
metaData[MessageDataMetaHeightKey] = height;
|
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height)) {
|
||||||
}
|
metaData[MessageDataMetaHeightKey] = height;
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration)) {
|
}
|
||||||
metaData[MessageDataMetaDurationKey] = duration;
|
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration)) {
|
||||||
|
metaData[MessageDataMetaDurationKey] = duration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override void Decode(Dictionary<string, object> msgData) {
|
internal override void Decode(Dictionary<string, object> msgData) {
|
||||||
base.Decode(msgData);
|
base.Decode(msgData);
|
||||||
|
|
||||||
|
if (File.MetaData == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
|
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
|
||||||
int.TryParse(width as string, out int w)) {
|
int.TryParse(width as string, out int w)) {
|
||||||
Width = w;
|
Width = w;
|
||||||
|
|
Loading…
Reference in New Issue