using System;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using LeanCloud.Storage.Internal.Query;
using LeanCloud.Realtime.Protocol;
namespace LeanCloud.Realtime {
public class LCIMConversationQuery {
private LCCompositionalCondition condition;
private LCIMClient client;
public LCIMConversationQuery(LCIMClient client) {
condition = new LCCompositionalCondition();
this.client = client;
}
///
/// 等于
///
///
///
///
public LCIMConversationQuery WhereEqualTo(string key, object value) {
condition.WhereEqualTo(key, value);
return this;
}
///
/// 不等于
///
///
///
///
public LCIMConversationQuery WhereNotEqualTo(string key, object value) {
condition.WhereNotEqualTo(key, value);
return this;
}
///
/// 包含
///
///
///
///
public LCIMConversationQuery WhereContainedIn(string key, IEnumerable values) {
condition.WhereContainedIn(key, values);
return this;
}
///
/// 包含全部
///
///
///
///
public LCIMConversationQuery WhereContainsAll(string key, IEnumerable values) {
condition.WhereContainsAll(key, values);
return this;
}
///
/// 存在
///
///
///
public LCIMConversationQuery WhereExists(string key) {
condition.WhereExists(key);
return this;
}
///
/// 不存在
///
///
///
public LCIMConversationQuery WhereDoesNotExist(string key) {
condition.WhereDoesNotExist(key);
return this;
}
///
/// 长度等于
///
///
///
///
public LCIMConversationQuery WhereSizeEqualTo(string key, int size) {
condition.WhereSizeEqualTo(key, size);
return this;
}
///
/// 大于
///
///
///
///
public LCIMConversationQuery WhereGreaterThan(string key, object value) {
condition.WhereGreaterThan(key, value);
return this;
}
///
/// 大于等于
///
///
///
///
public LCIMConversationQuery WhereGreaterThanOrEqualTo(string key, object value) {
condition.WhereGreaterThanOrEqualTo(key, value);
return this;
}
///
/// 小于
///
///
///
///
public LCIMConversationQuery WhereLessThan(string key, object value) {
condition.WhereLessThan(key, value);
return this;
}
///
/// 小于等于
///
///
///
///
public LCIMConversationQuery WhereLessThanOrEqualTo(string key, object value) {
condition.WhereLessThanOrEqualTo(key, value);
return this;
}
///
/// 前缀
///
///
///
///
public LCIMConversationQuery WhereStartsWith(string key, string prefix) {
condition.WhereStartsWith(key, prefix);
return this;
}
///
/// 后缀
///
///
///
///
public LCIMConversationQuery WhereEndsWith(string key, string suffix) {
condition.WhereEndsWith(key, suffix);
return this;
}
///
/// 字符串包含
///
///
///
///
public LCIMConversationQuery WhereContains(string key, string subString) {
condition.WhereContains(key, subString);
return this;
}
///
/// 按 key 升序
///
///
///
public LCIMConversationQuery OrderBy(string key) {
condition.OrderBy(key);
return this;
}
///
/// 按 key 降序
///
///
///
public LCIMConversationQuery OrderByDescending(string key) {
condition.OrderByDescending(key);
return this;
}
///
/// 拉取 key 的完整对象
///
///
///
public LCIMConversationQuery Include(string key) {
condition.Include(key);
return this;
}
///
/// 包含 key
///
///
///
public LCIMConversationQuery Select(string key) {
condition.Select(key);
return this;
}
///
/// 跳过
///
///
///
public LCIMConversationQuery Skip(int value) {
condition.Skip = value;
return this;
}
///
/// 限制数量
///
///
///
public LCIMConversationQuery Limit(int value) {
condition.Limit = value;
return this;
}
public bool WithLastMessageRefreshed {
get; set;
}
public async Task> Find() {
GenericCommand command = new GenericCommand {
Cmd = CommandType.Conv,
Op = OpType.Query,
AppId = LCApplication.AppId,
PeerId = client.ClientId,
};
ConvCommand conv = new ConvCommand();
string where = condition.BuildWhere();
if (!string.IsNullOrEmpty(where)) {
conv.Where = JsonObjectMessage.Parser.ParseJson(where);
}
command.ConvMessage = conv;
GenericCommand response = await client.connection.SendRequest(command);
JsonObjectMessage results = response.ConvMessage.Results;
List convList = null;
// TODO 反序列化
return convList;
}
}
}