diff --git a/RTM/RTM/Public/AVIMConversationQuery.cs b/RTM/RTM/Public/AVIMConversationQuery.cs
index 6b1a375..d5f7284 100644
--- a/RTM/RTM/Public/AVIMConversationQuery.cs
+++ b/RTM/RTM/Public/AVIMConversationQuery.cs
@@ -3,110 +3,80 @@ using LeanCloud.Storage.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using System.Text.RegularExpressions;
-namespace LeanCloud.Realtime
-{
+namespace LeanCloud.Realtime {
///
/// 对话查询类
///
- public class AVIMConversationQuery
- {
+ public class AVIMConversationQuery {
internal AVIMClient CurrentClient { get; set; }
- internal AVIMConversationQuery(AVIMClient _currentClient)
- : base()
- {
- CurrentClient = _currentClient;
- }
-
- bool compact;
- bool withLastMessageRefreshed;
-
+ QueryCombinedCondition condition;
- ///
- /// Creates the instance.
- ///
- /// The instance.
- /// Where.
- /// Replacement order by.
- /// Then by.
- /// Skip.
- /// Limit.
- /// Includes.
- /// Selected keys.
- /// Redirect class name for key.
- public AVIMConversationQuery CreateInstance(
- IDictionary where = null,
- IEnumerable replacementOrderBy = null,
- IEnumerable thenBy = null,
- int? skip = null,
- int? limit = null,
- IEnumerable includes = null,
- IEnumerable selectedKeys = null,
- String redirectClassNameForKey = null)
- {
- var rtn = new AVIMConversationQuery(this, where, replacementOrderBy, thenBy, skip, limit, includes);
- rtn.CurrentClient = this.CurrentClient;
- rtn.compact = this.compact;
- rtn.withLastMessageRefreshed = this.withLastMessageRefreshed;
- return rtn;
+ public AVIMConversationQuery() {
+ condition = new QueryCombinedCondition();
}
- ///
- /// Withs the last message refreshed.
- ///
- /// The last message refreshed.
- /// If set to true enabled.
- public AVIMConversationQuery WithLastMessageRefreshed(bool enabled)
- {
- this.withLastMessageRefreshed = enabled;
- return this;
- }
-
- public AVIMConversationQuery Compact(bool enabled)
- {
- this.compact = enabled;
- return this;
- }
-
-
- internal ConversationCommand GenerateQueryCommand()
- {
+ internal ConversationCommand GenerateQueryCommand() {
var cmd = new ConversationCommand();
-
- var queryParameters = this.BuildParameters(false);
- if (queryParameters != null)
- {
- if (queryParameters.Keys.Contains("where"))
- cmd.Where(queryParameters["where"]);
- if (queryParameters.Keys.Contains("skip"))
- cmd.Skip(int.Parse(queryParameters["skip"].ToString()));
-
- if (queryParameters.Keys.Contains("limit"))
- cmd.Limit(int.Parse(queryParameters["limit"].ToString()));
-
- if (queryParameters.Keys.Contains("sort"))
- cmd.Sort(queryParameters["order"].ToString());
+ var queryParameters = BuildParameters();
+ if (queryParameters != null) {
+ if (queryParameters.TryGetValue("where", out object where)) {
+ cmd.Where(where);
+ }
+ if (queryParameters.TryGetValue("skip", out object skip)) {
+ cmd.Skip((int)skip);
+ }
+ if (queryParameters.TryGetValue("limit", out object limit)) {
+ cmd.Limit((int)limit);
+ }
+ if (queryParameters.TryGetValue("order", out object order)) {
+ cmd.Sort(order.ToString());
+ }
}
return cmd;
}
- public Task CountAsync(CancellationToken cancellationToken = default) {
+ #region Combined Query
+
+ public static AVIMConversationQuery And(IEnumerable queries) {
+ AVIMConversationQuery composition = new AVIMConversationQuery();
+ if (queries != null) {
+ foreach (AVIMConversationQuery query in queries) {
+ composition.condition.AddCondition(query.condition);
+ }
+ }
+ return composition;
+ }
+
+ public static AVIMConversationQuery Or(IEnumerable queries) {
+ AVIMConversationQuery composition = new AVIMConversationQuery {
+ condition = new QueryCombinedCondition(QueryCombinedCondition.OR)
+ };
+ if (queries != null) {
+ foreach (AVIMConversationQuery query in queries) {
+ composition.condition.AddCondition(query.condition);
+ }
+ }
+ return composition;
+ }
+
+ #endregion
+
+ public Task CountAsync() {
var convCmd = GenerateQueryCommand();
convCmd.Count();
convCmd.Limit(0);
var cmd = convCmd.Option("query");
- return CurrentClient.RunCommandAsync(convCmd).OnSuccess(t =>
- {
+ return CurrentClient.RunCommandAsync(convCmd).OnSuccess(t => {
var result = t.Result.Item2;
- if (result.ContainsKey("count"))
- {
+ if (result.ContainsKey("count")) {
return int.Parse(result["count"].ToString());
}
return 0;
@@ -117,24 +87,16 @@ namespace LeanCloud.Realtime
///
/// 查找符合条件的对话
///
- ///
///
- public Task> FindAsync(CancellationToken cancellationToken = default)
- {
- var convCmd = this.GenerateQueryCommand().Option("query");
- return CurrentClient.RunCommandAsync(convCmd).OnSuccess(t =>
- {
+ public Task> FindAsync() {
+ var convCmd = GenerateQueryCommand().Option("query");
+ return CurrentClient.RunCommandAsync(convCmd).OnSuccess(t => {
var result = t.Result.Item2;
IList rtn = new List();
- var conList = result["results"] as IList