From e8d6f66941b86000747d0b18b7cd26f1aa7f2e06 Mon Sep 17 00:00:00 2001 From: leancloud-bot Date: Tue, 20 Jun 2023 14:24:57 +0800 Subject: [PATCH] fix: merge props after creating conv --- Realtime/Realtime.Test/Client.cs | 12 ++++++++++-- .../Controller/LCIMConversationController.cs | 1 + .../Realtime/Public/Conversation/LCIMConversation.cs | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Realtime/Realtime.Test/Client.cs b/Realtime/Realtime.Test/Client.cs index b6b0b3dd..99dbfb1f 100644 --- a/Realtime/Realtime.Test/Client.cs +++ b/Realtime/Realtime.Test/Client.cs @@ -2,6 +2,7 @@ using System; using System.Threading.Tasks; using System.Collections.ObjectModel; +using System.Collections.Generic; using LeanCloud; using LeanCloud.Realtime; using LeanCloud.Storage; @@ -63,7 +64,11 @@ public async Task CreateConversation() { WriteLine(conv.CreatorId); }; + string name = Guid.NewGuid().ToString(); + client.OnMembersJoined = (conv, memberList, initBy) => { + WriteLine($"custom id: {conv["custom_id"]}"); + Assert.AreEqual(conv["custom_id"], name); WriteLine($"on members joined: {initBy}"); foreach (string memberId in conv.MemberIds) { WriteLine(memberId); @@ -71,8 +76,11 @@ public async Task CreateConversation() { tcs.SetResult(null); }; - string name = Guid.NewGuid().ToString(); - LCIMConversation conversation = await client.CreateConversation(new string[] { "world" }, name: name, unique: false); + Dictionary props = new Dictionary { + { "custom_id", name } + }; + LCIMConversation conversation = await client.CreateConversation(new string[] { "world" }, + name: name, unique: false, properties: props); await tcs.Task; } diff --git a/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs b/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs index 1e1d272c..51515a62 100644 --- a/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs +++ b/Realtime/Realtime/Internal/Controller/LCIMConversationController.cs @@ -76,6 +76,7 @@ internal async Task CreateConv( } else { conversation = new LCIMConversation(Client); } + conversation.MergeFrom(properties); Client.ConversationDict[convId] = conversation; } // 合并请求数据 diff --git a/Realtime/Realtime/Public/Conversation/LCIMConversation.cs b/Realtime/Realtime/Public/Conversation/LCIMConversation.cs index 42f7f573..c35b6d1b 100644 --- a/Realtime/Realtime/Public/Conversation/LCIMConversation.cs +++ b/Realtime/Realtime/Public/Conversation/LCIMConversation.cs @@ -491,6 +491,10 @@ internal static bool IsTemporayConversation(string convId) { } internal void MergeFrom(Dictionary conv) { + if (conv == null) { + return; + } + foreach (KeyValuePair kv in conv) { if (kv.Key == "objectId") { Id = kv.Value as string;