* LCIMConversation.cs:
* LCIMConversationQuery.cs: * LCIMConversationController.cs: * Conversation.cs: chore: 完善构造对话实例
parent
60cd97c725
commit
66f3a479b4
|
@ -5,11 +5,16 @@ using System.Linq;
|
|||
using System.Collections.ObjectModel;
|
||||
using LeanCloud.Realtime.Protocol;
|
||||
using LeanCloud.Storage;
|
||||
using LeanCloud.Storage.Internal.Codec;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
public class LCIMConversation {
|
||||
public string Id {
|
||||
get; set;
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
public bool Unique {
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
public string UniqueId {
|
||||
|
@ -19,7 +24,8 @@ namespace LeanCloud.Realtime {
|
|||
public string Name {
|
||||
get {
|
||||
return this["name"] as string;
|
||||
} set {
|
||||
}
|
||||
internal set {
|
||||
this["name"] = value;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +34,7 @@ namespace LeanCloud.Realtime {
|
|||
get; set;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<string> MemberIdList {
|
||||
public ReadOnlyCollection<string> MemberIds {
|
||||
get {
|
||||
return new ReadOnlyCollection<string>(ids.ToList());
|
||||
}
|
||||
|
@ -349,28 +355,13 @@ namespace LeanCloud.Realtime {
|
|||
return convId.StartsWith("_tmp:");
|
||||
}
|
||||
|
||||
internal void MergeFrom(ConvCommand conv) {
|
||||
if (conv.HasCid) {
|
||||
Id = conv.Cid;
|
||||
}
|
||||
if (conv.HasInitBy) {
|
||||
CreatorId = conv.InitBy;
|
||||
}
|
||||
if (conv.HasCdate) {
|
||||
CreatedAt = DateTime.Parse(conv.Cdate);
|
||||
}
|
||||
if (conv.HasUdate) {
|
||||
UpdatedAt = DateTime.Parse(conv.Udate);
|
||||
}
|
||||
if (conv.M.Count > 0) {
|
||||
ids = new HashSet<string>(conv.M.ToList());
|
||||
}
|
||||
}
|
||||
|
||||
internal void MergeFrom(Dictionary<string, object> conv) {
|
||||
if (conv.TryGetValue("objectId", out object idObj)) {
|
||||
Id = idObj as string;
|
||||
}
|
||||
if (conv.TryGetValue("unique", out object uniqueObj)) {
|
||||
Unique = (bool)uniqueObj;
|
||||
}
|
||||
if (conv.TryGetValue("uniqueId", out object uniqueIdObj)) {
|
||||
UniqueId = uniqueIdObj as string;
|
||||
}
|
||||
|
@ -384,10 +375,15 @@ namespace LeanCloud.Realtime {
|
|||
CreatorId = co as string;
|
||||
}
|
||||
if (conv.TryGetValue("m", out object mo)) {
|
||||
ids = new HashSet<string>((mo as IList<object>).Cast<string>());
|
||||
IEnumerable<string> ids = (mo as IList<object>).Cast<string>();
|
||||
this.ids = new HashSet<string>(ids);
|
||||
}
|
||||
if (conv.TryGetValue("mu", out object muo)) {
|
||||
mutedIds = new HashSet<string>((muo as IList<object>).Cast<string>());
|
||||
IEnumerable<string> ids = (muo as IList<object>).Cast<string>();
|
||||
mutedIds = new HashSet<string>(ids);
|
||||
}
|
||||
if (conv.TryGetValue("lm", out object lmo)) {
|
||||
LastMessageAt = (DateTime)LCDecoder.Decode(lmo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using LeanCloud.Storage.Internal.Query;
|
||||
|
||||
|
|
|
@ -78,10 +78,15 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
Client.ConversationDict[convId] = conversation;
|
||||
}
|
||||
// 合并请求数据
|
||||
conversation.Id = convId;
|
||||
conversation.Unique = unique;
|
||||
conversation.UniqueId = response.ConvMessage.UniqueId;
|
||||
conversation.Name = name;
|
||||
conversation.ids = members != null ? new HashSet<string>(members) : null;
|
||||
// 合并服务端推送的数据
|
||||
conversation.MergeFrom(response.ConvMessage);
|
||||
conversation.CreatorId = Client.Id;
|
||||
conversation.ids = members != null ?
|
||||
new HashSet<string>(members) : new HashSet<string>();
|
||||
conversation.CreatedAt = DateTime.Parse(response.ConvMessage.Cdate);
|
||||
conversation.UpdatedAt = conversation.CreatedAt;
|
||||
return conversation;
|
||||
}
|
||||
|
||||
|
@ -457,12 +462,18 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
Dictionary<string, object> conv = item as Dictionary<string, object>;
|
||||
string convId = conv["objectId"] as string;
|
||||
if (!Client.ConversationDict.TryGetValue(convId, out LCIMConversation conversation)) {
|
||||
// TODO 解析是哪种类型的对话
|
||||
|
||||
// 解析是哪种类型的对话
|
||||
if (conv.TryGetValue("tr", out object transient) && (bool)transient == true) {
|
||||
conversation = new LCIMChatRoom(Client);
|
||||
} else if (conv.ContainsKey("tempConv") && conv.ContainsKey("tempConvTTL")) {
|
||||
conversation = new LCIMTemporaryConversation(Client);
|
||||
} else if (conv.TryGetValue("sys", out object sys) && (bool)sys == true) {
|
||||
conversation = new LCIMServiceConversation(Client);
|
||||
} else {
|
||||
conversation = new LCIMConversation(Client);
|
||||
}
|
||||
Client.ConversationDict[convId] = conversation;
|
||||
}
|
||||
|
||||
conversation.MergeFrom(conv);
|
||||
return conversation;
|
||||
}).ToList().AsReadOnly();
|
||||
|
@ -556,7 +567,6 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
/// <returns></returns>
|
||||
private async Task OnJoined(ConvCommand convMessage) {
|
||||
LCIMConversation conversation = await Client.GetOrQueryConversation(convMessage.Cid);
|
||||
conversation.MergeFrom(convMessage);
|
||||
Client.OnInvited?.Invoke(conversation, convMessage.InitBy);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Realtime.Test {
|
|||
|
||||
client.OnMembersJoined = (conv, memberList, initBy) => {
|
||||
TestContext.WriteLine($"on members joined: {initBy}");
|
||||
foreach (string memberId in conv.MemberIdList) {
|
||||
foreach (string memberId in conv.MemberIds) {
|
||||
TestContext.WriteLine(memberId);
|
||||
}
|
||||
tcs.SetResult(null);
|
||||
|
|
Loading…
Reference in New Issue