* LCIMConversation.cs:

* LCIMConversationQuery.cs:

* RealtimeConsole.csproj: chore: 支持对话的查询和反序列化
oneRain 2020-03-23 16:46:27 +08:00
parent 92ee97d236
commit 5dcdc56f56
3 changed files with 43 additions and 10 deletions

View File

@ -14,6 +14,10 @@ namespace LeanCloud.Realtime {
get; set;
}
public string UniqueId {
get; internal set;
}
public string Name {
get {
return this["name"] as string;
@ -30,6 +34,10 @@ namespace LeanCloud.Realtime {
get; internal set;
}
public List<string> MutedMemberIdList {
get; internal set;
}
public DateTime CreatedAt {
get; internal set;
}
@ -506,11 +514,24 @@ namespace LeanCloud.Realtime {
if (conv.TryGetValue("objectId", out object idObj)) {
Id = idObj as string;
}
if (conv.TryGetValue("unique", out object uniqueObj)) {
if (conv.TryGetValue("uniqueId", out object uniqueIdObj)) {
UniqueId = uniqueIdObj as string;
}
if (conv.TryGetValue("createdAt", out object createdAtObj)) {
CreatedAt = DateTime.Parse(createdAtObj.ToString());
}
if (conv.TryGetValue("updatedAt", out object updatedAtObj)) {
UpdatedAt = DateTime.Parse(updatedAtObj.ToString());
}
if (conv.TryGetValue("c", out object co)) {
CreatorId = co as string;
}
if (conv.TryGetValue("m", out object mo)) {
MemberIdList = mo as List<string>;
}
if (conv.TryGetValue("mu", out object muo)) {
MutedMemberIdList = muo as List<string>;
}
}
}
}

View File

@ -1,9 +1,11 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using LeanCloud.Storage.Internal.Query;
using LeanCloud.Realtime.Protocol;
using LeanCloud.Storage.Internal;
using LeanCloud.Storage.Internal.Codec;
using Newtonsoft.Json;
namespace LeanCloud.Realtime {
public class LCIMConversationQuery {
@ -242,14 +244,22 @@ namespace LeanCloud.Realtime {
ConvCommand conv = new ConvCommand();
string where = condition.BuildWhere();
if (!string.IsNullOrEmpty(where)) {
conv.Where = JsonObjectMessage.Parser.ParseJson(where);
conv.Where = new JsonObjectMessage {
Data = where
};
}
command.ConvMessage = conv;
GenericCommand response = await client.connection.SendRequest(command);
JsonObjectMessage results = response.ConvMessage.Results;
List<LCIMConversation> convList = null;
// TODO 反序列化
List<object> convs = JsonConvert.DeserializeObject<List<object>>(results.Data, new LCJsonConverter());
List<LCIMConversation> convList = new List<LCIMConversation>(convs.Count);
foreach (object c in convs) {
Dictionary<string, object> cd = c as Dictionary<string, object>;
string convId = cd["objectId"] as string;
LCIMConversation conversation = client.GetOrCreateConversation(convId);
conversation.MergeFrom(cd);
convList.Add(conversation);
}
return convList;
}
}

View File

@ -8,6 +8,7 @@
<RootNamespace>RealtimeConsole</RootNamespace>
<AssemblyName>RealtimeConsole</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<ReleaseVersion>0.1.0</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -49,6 +50,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LocalSignatureFactory.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\Common.csproj">