* 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> fileData = data[MessageFileKey] 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;
|
||||
}
|
||||
return data;
|
||||
|
@ -32,6 +33,10 @@ namespace LeanCloud.Realtime {
|
|||
|
||||
internal override void Decode(Dictionary<string, object> msgData) {
|
||||
base.Decode(msgData);
|
||||
|
||||
if (File.MetaData == null) {
|
||||
return;
|
||||
}
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration) &&
|
||||
double.TryParse(duration as string, out double d)) {
|
||||
Duration = d;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
|
@ -18,21 +19,14 @@ namespace LeanCloud.Realtime {
|
|||
/// 文件大小
|
||||
/// </summary>
|
||||
public int Size {
|
||||
get {
|
||||
if (int.TryParse(File.MetaData[MessageDataMetaSizeKey] as string, out int size)) {
|
||||
return size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件类型
|
||||
/// 文件扩展名
|
||||
/// </summary>
|
||||
public string Format {
|
||||
get {
|
||||
return File.MimeType;
|
||||
}
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -58,18 +52,47 @@ namespace LeanCloud.Realtime {
|
|||
if (File == null) {
|
||||
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> {
|
||||
{ MessageDataObjectIdKey, File.ObjectId },
|
||||
{ MessageDataUrlKey, File.Url },
|
||||
{ MessageDataMetaDataKey, new Dictionary<string, object> {
|
||||
{ MessageDataMetaNameKey, File.Name },
|
||||
{ MessageDataMetaFormatKey, File.MimeType }
|
||||
} }
|
||||
{ MessageDataObjectIdKey, File.ObjectId }
|
||||
};
|
||||
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;
|
||||
}
|
||||
fileData[MessageDataMetaDataKey] = metaData;
|
||||
|
||||
Dictionary<string, object> data = base.Encode();
|
||||
data[MessageFileKey] = fileData;
|
||||
return data;
|
||||
|
@ -80,6 +103,9 @@ namespace LeanCloud.Realtime {
|
|||
|
||||
if (msgData.TryGetValue(MessageFileKey, out object fileDataObject)) {
|
||||
Dictionary<string, object> fileData = fileDataObject as Dictionary<string, object>;
|
||||
if (fileData == null) {
|
||||
return;
|
||||
}
|
||||
if (fileData.TryGetValue(MessageDataObjectIdKey, out object objectIdObject)) {
|
||||
string objectId = objectIdObject as string;
|
||||
File = LCObject.CreateWithoutData(LCFile.CLASS_NAME, objectId) as LCFile;
|
||||
|
@ -88,9 +114,19 @@ namespace LeanCloud.Realtime {
|
|||
}
|
||||
if (fileData.TryGetValue(MessageDataMetaDataKey, out object metaData)) {
|
||||
File.MetaData = metaData as Dictionary<string, object>;
|
||||
if (File.MetaData == null) {
|
||||
return;
|
||||
}
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaNameKey, out object name)) {
|
||||
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> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
||||
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
||||
if (File.MetaData != null) {
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
|
||||
metaData[MessageDataMetaWidthKey] = width;
|
||||
}
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height)) {
|
||||
metaData[MessageDataMetaHeightKey] = height;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
internal override void Decode(Dictionary<string, object> msgData) {
|
||||
base.Decode(msgData);
|
||||
|
||||
if (File.MetaData == null) {
|
||||
return;
|
||||
}
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
|
||||
int.TryParse(width as string, out int w)) {
|
||||
Width = w;
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace LeanCloud.Realtime {
|
|||
Dictionary<string, object> data = base.Encode();
|
||||
Dictionary<string, object> fileData = data[MessageFileKey] as Dictionary<string, object>;
|
||||
Dictionary<string, object> metaData = fileData[MessageDataMetaDataKey] as Dictionary<string, object>;
|
||||
if (File.MetaData != null) {
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
|
||||
metaData[MessageDataMetaWidthKey] = width;
|
||||
}
|
||||
|
@ -47,11 +48,16 @@ namespace LeanCloud.Realtime {
|
|||
if (File.MetaData.TryGetValue(MessageDataMetaDurationKey, out object duration)) {
|
||||
metaData[MessageDataMetaDurationKey] = duration;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
internal override void Decode(Dictionary<string, object> msgData) {
|
||||
base.Decode(msgData);
|
||||
|
||||
if (File.MetaData == null) {
|
||||
return;
|
||||
}
|
||||
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
|
||||
int.TryParse(width as string, out int w)) {
|
||||
Width = w;
|
||||
|
|
Loading…
Reference in New Issue