test: 增加未读测试

oneRain 2020-04-27 11:54:01 +08:00
parent a7ccccb368
commit 9dd7a19e03
2 changed files with 27 additions and 9 deletions

View File

@ -158,7 +158,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
request.LogsMessage = logs; request.LogsMessage = logs;
GenericCommand response = await Client.Connection.SendRequest(request); GenericCommand response = await Client.Connection.SendRequest(request);
// 反序列化聊天记录 // 反序列化聊天记录
ReadOnlyCollection<LCIMMessage> messages = response.LogsMessage.Logs.Select(item => { return response.LogsMessage.Logs.Select(item => {
LCIMMessage message; LCIMMessage message;
if (item.Bin) { if (item.Bin) {
// 二进制消息 // 二进制消息
@ -179,14 +179,6 @@ namespace LeanCloud.Realtime.Internal.Controller {
message.MentionIdList = item.MentionPids.ToList(); message.MentionIdList = item.MentionPids.ToList();
return message; return message;
}).ToList().AsReadOnly(); }).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;
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using NUnit.Framework; using NUnit.Framework;
using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using LeanCloud; using LeanCloud;
@ -145,5 +146,30 @@ namespace Realtime.Test {
WriteLine(message.Id); WriteLine(message.Id);
} }
} }
[Test]
[Order(5)]
public async Task Unread() {
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
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;
}
} }
} }