chore: conversation
parent
bf2af41565
commit
5eae6cfe76
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace LeanCloud.Realtime {
|
||||
public class LCIMChatRoom : LCIMConversation {
|
||||
public LCIMChatRoom() {
|
||||
public LCIMChatRoom(LCIMClient client) : base(client) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using LeanCloud.Realtime.Protocol;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
public class LCIMConversation {
|
||||
|
@ -34,8 +36,10 @@ namespace LeanCloud.Realtime {
|
|||
|
||||
public virtual bool IsTransient => false;
|
||||
|
||||
public LCIMConversation() {
|
||||
private readonly LCIMClient client;
|
||||
|
||||
internal LCIMConversation(LCIMClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void Set(string key, object value) {
|
||||
|
@ -114,5 +118,23 @@ namespace LeanCloud.Realtime {
|
|||
public async Task<List<LCIMConversationMemberInfo>> GetAllMemberInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
MemberIdList = conv.M.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace LeanCloud.Realtime {
|
||||
public class LCIMTemporaryConversation : LCIMConversation {
|
||||
public LCIMTemporaryConversation() {
|
||||
public LCIMTemporaryConversation(LCIMClient client) : base(client) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace LeanCloud.Realtime {
|
|||
|
||||
private LCWebSocketClient client;
|
||||
|
||||
private Dictionary<string, LCIMConversation> conversationDict;
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户被加入某个对话的黑名单
|
||||
/// </summary>
|
||||
|
@ -68,6 +70,7 @@ namespace LeanCloud.Realtime {
|
|||
|
||||
public LCIMClient(string clientId) {
|
||||
this.clientId = clientId;
|
||||
conversationDict = new Dictionary<string, LCIMConversation>();
|
||||
}
|
||||
|
||||
public async Task Open() {
|
||||
|
@ -132,9 +135,9 @@ namespace LeanCloud.Realtime {
|
|||
}
|
||||
command.ConvMessage = conv;
|
||||
GenericCommand response = await client.SendRequest(command);
|
||||
// TODO 实例化对话对象
|
||||
|
||||
LCIMConversation conversation = new LCIMConversation();
|
||||
LCIMConversation conversation = new LCIMConversation(this);
|
||||
conversation.MergeFrom(response.ConvMessage);
|
||||
conversationDict[conversation.Id] = conversation;
|
||||
return conversation;
|
||||
}
|
||||
|
||||
|
@ -174,11 +177,17 @@ namespace LeanCloud.Realtime {
|
|||
}
|
||||
|
||||
private void OnConversationJoined(ConvCommand conv) {
|
||||
OnInvited?.Invoke(null, conv.InitBy);
|
||||
if (conversationDict.TryGetValue(conv.Cid, out LCIMConversation conversation)) {
|
||||
conversation.MergeFrom(conv);
|
||||
}
|
||||
OnInvited?.Invoke(conversation, conv.InitBy);
|
||||
}
|
||||
|
||||
private void OnConversationMembersJoined(ConvCommand conv) {
|
||||
OnMembersJoined?.Invoke(null, conv.M.ToList(), conv.InitBy);
|
||||
if (conversationDict.TryGetValue(conv.Cid, out LCIMConversation conversation)) {
|
||||
conversation.MergeFrom(conv);
|
||||
}
|
||||
OnMembersJoined?.Invoke(conversation, conv.M.ToList(), conv.InitBy);
|
||||
}
|
||||
|
||||
private GenericCommand NewCommand(CommandType cmd, OpType op) {
|
||||
|
|
|
@ -30,10 +30,14 @@ namespace Realtime.Test {
|
|||
|
||||
client.OnInvited = (conv, initBy) => {
|
||||
TestContext.WriteLine($"on invited: {initBy}");
|
||||
TestContext.WriteLine(conv.CreatorId);
|
||||
};
|
||||
|
||||
client.OnMembersJoined = (conv, memberList, initBy) => {
|
||||
TestContext.WriteLine($"on members joined: {initBy}");
|
||||
foreach (string memberId in conv.MemberIdList) {
|
||||
TestContext.WriteLine(memberId);
|
||||
}
|
||||
tcs.SetResult(null);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue