From 9dd7a19e0334fe50a2ef77d496294d6434b28bee Mon Sep 17 00:00:00 2001 From: oneRain Date: Mon, 27 Apr 2020 11:54:01 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E6=9C=AA=E8=AF=BB?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/LCIMMessageController.cs | 10 +------ Test/Realtime.Test/Message.cs | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Realtime/Internal/Controller/LCIMMessageController.cs b/Realtime/Internal/Controller/LCIMMessageController.cs index dbfd49b..8378080 100644 --- a/Realtime/Internal/Controller/LCIMMessageController.cs +++ b/Realtime/Internal/Controller/LCIMMessageController.cs @@ -158,7 +158,7 @@ namespace LeanCloud.Realtime.Internal.Controller { request.LogsMessage = logs; GenericCommand response = await Client.Connection.SendRequest(request); // 反序列化聊天记录 - ReadOnlyCollection messages = response.LogsMessage.Logs.Select(item => { + return response.LogsMessage.Logs.Select(item => { LCIMMessage message; if (item.Bin) { // 二进制消息 @@ -179,14 +179,6 @@ namespace LeanCloud.Realtime.Internal.Controller { message.MentionIdList = item.MentionPids.ToList(); return message; }).ToList().AsReadOnly(); - // 查询之后更新对话中的最后一条消息 - LCIMMessage lastMessage = messages.Last(); - LCIMConversation conversation = await Client.GetOrQueryConversation(convId); - if (conversation.LastMessage == null || - conversation.LastMessage.SentTimestamp < lastMessage.SentTimestamp) { - conversation.LastMessage = lastMessage; - } - return messages; } /// diff --git a/Test/Realtime.Test/Message.cs b/Test/Realtime.Test/Message.cs index 47d2494..3d0c2cc 100644 --- a/Test/Realtime.Test/Message.cs +++ b/Test/Realtime.Test/Message.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System; using System.Collections.ObjectModel; using System.Threading.Tasks; using LeanCloud; @@ -145,5 +146,30 @@ namespace Realtime.Test { WriteLine(message.Id); } } + + [Test] + [Order(5)] + public async Task Unread() { + TaskCompletionSource tcs = new TaskCompletionSource(); + string clientId = Guid.NewGuid().ToString(); + LCIMClient client = new LCIMClient(clientId); + LCIMConversation conversation = await m1.CreateConversation(new string[] { clientId }); + await client.Open(); + LCIMTextMessage textMessage = new LCIMTextMessage("hello"); + await conversation.Send(textMessage); + client.OnUnreadMessagesCountUpdated = (convs) => { + foreach (LCIMConversation conv in convs) { + WriteLine($"unread count: {conv.Unread}"); + Assert.AreEqual(conv.Unread, 1); + Assert.True(conv.LastMessage is LCIMTextMessage); + LCIMTextMessage textMsg = conv.LastMessage as LCIMTextMessage; + Assert.AreEqual(textMsg.Text, "hello"); + tcs.SetResult(true); + } + }; + await client.Open(); + + await tcs.Task; + } } }