From 5dcdc56f56a16670c64ba301199deb9fa97b8481 Mon Sep 17 00:00:00 2001 From: oneRain Date: Mon, 23 Mar 2020 16:46:27 +0800 Subject: [PATCH] * LCIMConversation.cs: * LCIMConversationQuery.cs: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * RealtimeConsole.csproj: chore: 支持对话的查询和反序列化 --- Realtime/Conversation/LCIMConversation.cs | 29 ++++++++++++++++--- .../Conversation/LCIMConversationQuery.cs | 22 ++++++++++---- Test/RealtimeConsole/RealtimeConsole.csproj | 2 ++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Realtime/Conversation/LCIMConversation.cs b/Realtime/Conversation/LCIMConversation.cs index e10c7cf..bb02d54 100644 --- a/Realtime/Conversation/LCIMConversation.cs +++ b/Realtime/Conversation/LCIMConversation.cs @@ -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 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; + } + if (conv.TryGetValue("mu", out object muo)) { + MutedMemberIdList = muo as List; } - } } } diff --git a/Realtime/Conversation/LCIMConversationQuery.cs b/Realtime/Conversation/LCIMConversationQuery.cs index 95e6535..072c3b8 100644 --- a/Realtime/Conversation/LCIMConversationQuery.cs +++ b/Realtime/Conversation/LCIMConversationQuery.cs @@ -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 convList = null; - // TODO 反序列化 - + List convs = JsonConvert.DeserializeObject>(results.Data, new LCJsonConverter()); + List convList = new List(convs.Count); + foreach (object c in convs) { + Dictionary cd = c as Dictionary; + string convId = cd["objectId"] as string; + LCIMConversation conversation = client.GetOrCreateConversation(convId); + conversation.MergeFrom(cd); + convList.Add(conversation); + } return convList; } } diff --git a/Test/RealtimeConsole/RealtimeConsole.csproj b/Test/RealtimeConsole/RealtimeConsole.csproj index 455b9f0..a31c966 100644 --- a/Test/RealtimeConsole/RealtimeConsole.csproj +++ b/Test/RealtimeConsole/RealtimeConsole.csproj @@ -8,6 +8,7 @@ RealtimeConsole RealtimeConsole v4.7.2 + 0.1.0 true @@ -49,6 +50,7 @@ +