diff --git a/Common/Common-Unity/Common-Unity.csproj b/Common/Common-Unity/Common-Unity.csproj
index 9ab3475..8cc5107 100644
--- a/Common/Common-Unity/Common-Unity.csproj
+++ b/Common/Common-Unity/Common-Unity.csproj
@@ -3,6 +3,7 @@
netstandard2.0
0.4.2
+ Common
diff --git a/LiveQuery/LiveQuery-Unity/LiveQuery-Unity.csproj b/LiveQuery/LiveQuery-Unity/LiveQuery-Unity.csproj
index b2522ba..e967d73 100644
--- a/LiveQuery/LiveQuery-Unity/LiveQuery-Unity.csproj
+++ b/LiveQuery/LiveQuery-Unity/LiveQuery-Unity.csproj
@@ -4,6 +4,7 @@
netstandard2.0
true
0.4.2
+ LiveQuery
diff --git a/Realtime/Realtime-Unity/Realtime-Unity.csproj b/Realtime/Realtime-Unity/Realtime-Unity.csproj
index 7e1a4a8..81beca1 100644
--- a/Realtime/Realtime-Unity/Realtime-Unity.csproj
+++ b/Realtime/Realtime-Unity/Realtime-Unity.csproj
@@ -4,6 +4,7 @@
netstandard2.0
0.4.2
true
+ Realtime
diff --git a/Realtime/Realtime.Test/Client.cs b/Realtime/Realtime.Test/Client.cs
index e43a7bf..6ac6774 100644
--- a/Realtime/Realtime.Test/Client.cs
+++ b/Realtime/Realtime.Test/Client.cs
@@ -10,15 +10,22 @@ using static NUnit.Framework.TestContext;
namespace Realtime.Test {
public class Client {
+ private const string USERNAME1 = "username1";
+ private const string PASSWORD1 = "password1";
+
+ private const string USERNAME2 = "username2";
+ private const string PASSWORD2 = "password2";
+
[SetUp]
- public void SetUp() {
- LCLogger.LogDelegate += Utils.Print;
- LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
+ public async Task SetUp() {
+ Utils.SetUp();
+ await NewUser(USERNAME1, PASSWORD1);
+ await NewUser(USERNAME2, PASSWORD2);
}
[TearDown]
public void TearDown() {
- LCLogger.LogDelegate -= Utils.Print;
+ Utils.TearDown();
}
[Test]
@@ -34,12 +41,12 @@ namespace Realtime.Test {
[Test]
public async Task OpenAndCloseByLCUser() {
- LCUser user = await LCUser.Login("hello", "world");
+ LCUser user = await LCUser.Login(USERNAME1, PASSWORD1);
LCIMClient client = new LCIMClient(user);
await client.Open();
- LCUser game = await LCUser.Login("game", "play");
+ LCUser game = await LCUser.Login(USERNAME2, PASSWORD2);
LCIMClient client2 = new LCIMClient(game);
await client2.Open();
@@ -134,5 +141,21 @@ namespace Realtime.Test {
await tcs.Task;
}
+
+ private async Task NewUser(string username, string password) {
+ try {
+ await LCUser.Login(username, password);
+ } catch (LCException e) {
+ if (e.Code == 211) {
+ LCUser user1 = new LCUser {
+ Username = username,
+ Password = password
+ };
+ await user1.SignUp();
+ } else {
+ throw e;
+ }
+ }
+ }
}
}
diff --git a/Realtime/Realtime.Test/Conversation.cs b/Realtime/Realtime.Test/Conversation.cs
index 31f34cc..cf4050f 100644
--- a/Realtime/Realtime.Test/Conversation.cs
+++ b/Realtime/Realtime.Test/Conversation.cs
@@ -16,8 +16,7 @@ namespace Realtime.Test {
[SetUp]
public async Task SetUp() {
- LCLogger.LogDelegate += Utils.Print;
- LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
+ Utils.SetUp();
c1 = new LCIMClient(Guid.NewGuid().ToString());
await c1.Open();
c2 = new LCIMClient(Guid.NewGuid().ToString());
@@ -32,7 +31,7 @@ namespace Realtime.Test {
await c1.Close();
await c2.Close();
await lean.Close();
- LCLogger.LogDelegate -= Utils.Print;
+ Utils.TearDown();
}
[Test]
diff --git a/Realtime/Realtime.Test/ConversationQuery.cs b/Realtime/Realtime.Test/ConversationQuery.cs
index 4741ceb..dfdd125 100644
--- a/Realtime/Realtime.Test/ConversationQuery.cs
+++ b/Realtime/Realtime.Test/ConversationQuery.cs
@@ -1,27 +1,24 @@
using NUnit.Framework;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
-using LeanCloud;
-using LeanCloud.Common;
using LeanCloud.Realtime;
namespace Realtime.Test {
public class ConversationQuery {
- private string clientId = "hello123";
+ private readonly string clientId = "m1";
private LCIMClient client;
[SetUp]
public async Task SetUp() {
- LCLogger.LogDelegate += Utils.Print;
- LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
+ Utils.SetUp();
client = new LCIMClient(clientId);
await client.Open();
}
[TearDown]
public async Task TearDown() {
- LCLogger.LogDelegate -= Utils.Print;
await client.Close();
+ Utils.TearDown();
}
[Test]
@@ -36,7 +33,7 @@ namespace Realtime.Test {
[Test]
public async Task QueryMemberConversation() {
- string memberId = "cc1";
+ string memberId = "m1";
LCIMConversationQuery query = new LCIMConversationQuery(client);
query.WhereEqualTo("m", memberId);
ReadOnlyCollection conversations = await query.Find();
@@ -45,5 +42,34 @@ namespace Realtime.Test {
Assert.True(conversation.MemberIds.Contains(memberId));
}
}
+
+ [Test]
+ public async Task QueryCompact() {
+ string memberId = "m1";
+ LCIMConversationQuery query = new LCIMConversationQuery(client)
+ .WhereEqualTo("m", memberId);
+ query.Compact = true;
+ ReadOnlyCollection conversations = await query.Find();
+ foreach (LCIMConversation conversation in conversations) {
+ Assert.True(conversation.MemberIds.Count == 0);
+ await conversation.Fetch();
+ Assert.True(conversation.MemberIds.Count > 0);
+ }
+ }
+
+ [Test]
+ public async Task QueryWithLastMessage() {
+ string memberId = "m1";
+ LCIMConversationQuery query = new LCIMConversationQuery(client)
+ .WhereEqualTo("m", memberId);
+ query.WithLastMessageRefreshed = true;
+ ReadOnlyCollection conversations = await query.Find();
+ foreach (LCIMConversation conversation in conversations) {
+ Assert.True(!string.IsNullOrEmpty(conversation.LastMessage.Id));
+ if (conversation.LastMessage is LCIMBinaryMessage binaryMessage) {
+ TestContext.WriteLine(System.Text.Encoding.UTF8.GetString(binaryMessage.Data));
+ }
+ }
+ }
}
}
diff --git a/Realtime/Realtime.Test/Message.cs b/Realtime/Realtime.Test/Message.cs
index fefb78f..5fa81dc 100644
--- a/Realtime/Realtime.Test/Message.cs
+++ b/Realtime/Realtime.Test/Message.cs
@@ -32,8 +32,7 @@ namespace Realtime.Test {
[SetUp]
public async Task SetUp() {
- LCLogger.LogDelegate += Utils.Print;
- LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
+ Utils.SetUp();
m1 = new LCIMClient("m1");
m2 = new LCIMClient("m2");
await m1.Open();
@@ -45,7 +44,7 @@ namespace Realtime.Test {
public async Task TearDown() {
await m1.Close();
await m2.Close();
- LCLogger.LogDelegate -= Utils.Print;
+ Utils.TearDown();
}
[Test]
@@ -76,17 +75,19 @@ namespace Realtime.Test {
Assert.NotNull(textMessage.Id);
LCFile image = new LCFile("hello", "../../../../../assets/hello.png");
- await image.Save();
LCIMImageMessage imageMessage = new LCIMImageMessage(image);
await conversation.Send(imageMessage);
Assert.NotNull(imageMessage.Id);
LCFile file = new LCFile("apk", "../../../../../assets/test.apk");
- await file.Save();
LCIMFileMessage fileMessage = new LCIMFileMessage(file);
await conversation.Send(fileMessage);
Assert.NotNull(fileMessage.Id);
+ LCIMBinaryMessage binaryMessage = new LCIMBinaryMessage(System.Text.Encoding.UTF8.GetBytes("LeanCloud"));
+ await conversation.Send(binaryMessage);
+ Assert.NotNull(binaryMessage.Id);
+
await tcs.Task;
}
@@ -152,7 +153,7 @@ namespace Realtime.Test {
[Test]
[Order(4)]
public async Task Query() {
- ReadOnlyCollection messages = await conversation.QueryMessages();
+ ReadOnlyCollection messages = await conversation.QueryMessages(messageType: -6);
Assert.Greater(messages.Count, 0);
foreach (LCIMMessage message in messages) {
Assert.AreEqual(message.ConversationId, conversation.Id);
diff --git a/Realtime/Realtime.Test/Throttle.cs b/Realtime/Realtime.Test/Throttle.cs
index b0f5efa..0f6d475 100644
--- a/Realtime/Realtime.Test/Throttle.cs
+++ b/Realtime/Realtime.Test/Throttle.cs
@@ -1,7 +1,6 @@
using NUnit.Framework;
using System;
using System.Threading.Tasks;
-using LeanCloud;
using LeanCloud.Realtime;
using LeanCloud.Realtime.Internal.Protocol;
@@ -14,8 +13,7 @@ namespace Realtime.Test {
[SetUp]
public async Task SetUp() {
- LCLogger.LogDelegate += Utils.Print;
- LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
+ Utils.SetUp();
c1 = new LCIMClient(Guid.NewGuid().ToString());
c2 = new LCIMClient(Guid.NewGuid().ToString());
await c1.Open();
@@ -28,7 +26,7 @@ namespace Realtime.Test {
public async Task TearDown() {
await c1.Close();
await c2.Close();
- LCLogger.LogDelegate -= Utils.Print;
+ Utils.TearDown();
}
[Test]
diff --git a/Realtime/Realtime.Test/Utils.cs b/Realtime/Realtime.Test/Utils.cs
index 70aa219..77e42d4 100644
--- a/Realtime/Realtime.Test/Utils.cs
+++ b/Realtime/Realtime.Test/Utils.cs
@@ -1,10 +1,18 @@
using System;
using LeanCloud;
-using LeanCloud.Common;
using NUnit.Framework;
namespace Realtime.Test {
public static class Utils {
+ internal static void SetUp() {
+ LCLogger.LogDelegate += Print;
+ LCApplication.Initialize("3zWMOXuO9iSdnjXM942i6DdI-gzGzoHsz", "bkwiNq4Tj417eUaHlTWS5sPm", "https://3zwmoxuo.lc-cn-n1-shared.com");
+ }
+
+ internal static void TearDown() {
+ LCLogger.LogDelegate -= Print;
+ }
+
internal static void Print(LCLogLevel level, string info) {
switch (level) {
case LCLogLevel.Debug:
diff --git a/Realtime/Realtime/Conversation/LCIMChatRoom.cs b/Realtime/Realtime/Conversation/LCIMChatRoom.cs
index 6bccd42..5b77f92 100644
--- a/Realtime/Realtime/Conversation/LCIMChatRoom.cs
+++ b/Realtime/Realtime/Conversation/LCIMChatRoom.cs
@@ -28,5 +28,9 @@ namespace LeanCloud.Realtime {
public override Task AddMembers(IEnumerable clientIds) {
throw new Exception("Add members is not allowed in chat room.");
}
+
+ public override Task Read() {
+ return Task.CompletedTask;
+ }
}
}
diff --git a/Realtime/Realtime/Conversation/LCIMConversation.cs b/Realtime/Realtime/Conversation/LCIMConversation.cs
index b0a65f4..c2553d5 100644
--- a/Realtime/Realtime/Conversation/LCIMConversation.cs
+++ b/Realtime/Realtime/Conversation/LCIMConversation.cs
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System.Collections.ObjectModel;
-using LeanCloud.Storage;
namespace LeanCloud.Realtime {
///
@@ -180,9 +179,8 @@ namespace LeanCloud.Realtime {
///
/// Mark the last message of this conversation as read.
///
- ///
///
- public async Task Read() {
+ public virtual async Task Read() {
if (LastMessage == null) {
return;
}
@@ -260,10 +258,13 @@ namespace LeanCloud.Realtime {
}
}
+
+
///
/// Sends a message in this conversation.
///
/// The message to send.
+ /// The options of sending message.
///
public async Task Send(LCIMMessage message,
LCIMMessageSendOptions options = null) {
@@ -273,6 +274,7 @@ namespace LeanCloud.Realtime {
if (options == null) {
options = LCIMMessageSendOptions.Default;
}
+ await message.PrepareSend();
await Client.MessageController.Send(Id, message, options);
LastMessage = message;
return message;
@@ -450,7 +452,7 @@ namespace LeanCloud.Realtime {
/// Start message ID.
/// End message ID.
/// Query direction (defaults to NewToOld).
- /// Limits the number of returned results. Its default value is 20.
+ /// Limits the number of returned results. Its default value is 100.
/// The message type to query. The default value is 0 (text message).
///
public async Task> QueryMessages(LCIMMessageQueryEndpoint start = null,
@@ -469,6 +471,17 @@ namespace LeanCloud.Realtime {
await Client.ConversationController.FetchReciptTimestamp(Id);
}
+ ///
+ /// Fetch conversation from server.
+ ///
+ ///
+ public async Task Fetch() {
+ LCIMConversationQuery query = new LCIMConversationQuery(Client);
+ query.WhereEqualTo("objectId", Id);
+ await query.Find();
+ return this;
+ }
+
internal static bool IsTemporayConversation(string convId) {
return convId.StartsWith("_tmp:");
}
@@ -503,9 +516,28 @@ namespace LeanCloud.Realtime {
IEnumerable ids = (muo as IList
///
///
- public static async Task RequestPasswordRestBySmsCode(string mobile) {
+ public static async Task RequestPasswordResetBySmsCode(string mobile) {
if (string.IsNullOrEmpty(mobile)) {
throw new ArgumentNullException(nameof(mobile));
}