feat: support compact, withLastMessage
parent
bf5e49f40e
commit
6ace14fa0f
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using LeanCloud.Storage;
|
|
||||||
|
|
||||||
namespace LeanCloud.Realtime {
|
namespace LeanCloud.Realtime {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -470,6 +469,17 @@ namespace LeanCloud.Realtime {
|
||||||
await Client.ConversationController.FetchReciptTimestamp(Id);
|
await Client.ConversationController.FetchReciptTimestamp(Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fetch conversation from server.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<LCIMConversation> Fetch() {
|
||||||
|
LCIMConversationQuery query = new LCIMConversationQuery(Client);
|
||||||
|
query.WhereEqualTo("objectId", Id);
|
||||||
|
await query.Find();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
internal static bool IsTemporayConversation(string convId) {
|
internal static bool IsTemporayConversation(string convId) {
|
||||||
return convId.StartsWith("_tmp:");
|
return convId.StartsWith("_tmp:");
|
||||||
}
|
}
|
||||||
|
@ -504,9 +514,28 @@ namespace LeanCloud.Realtime {
|
||||||
IEnumerable<string> ids = (muo as IList<object>).Cast<string>();
|
IEnumerable<string> ids = (muo as IList<object>).Cast<string>();
|
||||||
mutedIds = new HashSet<string>(ids);
|
mutedIds = new HashSet<string>(ids);
|
||||||
}
|
}
|
||||||
//if (conv.TryGetValue("lm", out object lmo)) {
|
if (conv.TryGetValue("msg", out object msgo)) {
|
||||||
// LastMessageAt = (DateTime)LCDecoder.Decode(lmo);
|
if (conv.TryGetValue("bin", out object bino)) {
|
||||||
//}
|
string msg = msgo as string;
|
||||||
|
bool bin = (bool)bino;
|
||||||
|
if (bin) {
|
||||||
|
byte[] bytes = Convert.FromBase64String(msg);
|
||||||
|
LastMessage = LCIMBinaryMessage.Deserialize(bytes);
|
||||||
|
} else {
|
||||||
|
LastMessage = LCIMTypedMessage.Deserialize(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LastMessage.ConversationId = Id;
|
||||||
|
if (conv.TryGetValue("msg_mid", out object msgId)) {
|
||||||
|
LastMessage.Id = msgId as string;
|
||||||
|
}
|
||||||
|
if (conv.TryGetValue("msg_from", out object msgFrom)) {
|
||||||
|
LastMessage.FromClientId = msgFrom as string;
|
||||||
|
}
|
||||||
|
if (conv.TryGetValue("msg_timestamp", out object timestamp)) {
|
||||||
|
LastMessage.SentTimestamp = (long)timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void MergeInfo(Dictionary<string, object> attr) {
|
internal void MergeInfo(Dictionary<string, object> attr) {
|
||||||
|
|
|
@ -5,12 +5,29 @@ using LeanCloud.Storage.Internal.Query;
|
||||||
|
|
||||||
namespace LeanCloud.Realtime {
|
namespace LeanCloud.Realtime {
|
||||||
public class LCIMConversationQuery {
|
public class LCIMConversationQuery {
|
||||||
|
internal const int CompactFlag = 0x1;
|
||||||
|
internal const int WithLastMessageFlag = 0x2;
|
||||||
|
|
||||||
internal LCCompositionalCondition Condition {
|
internal LCCompositionalCondition Condition {
|
||||||
get; private set;
|
get; private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly LCIMClient client;
|
private readonly LCIMClient client;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ignore the members of conversation.
|
||||||
|
/// </summary>
|
||||||
|
public bool Compact {
|
||||||
|
get; set;
|
||||||
|
} = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// With the last message.
|
||||||
|
/// </summary>
|
||||||
|
public bool WithLastMessageRefreshed {
|
||||||
|
get; set;
|
||||||
|
} = false;
|
||||||
|
|
||||||
public LCIMConversationQuery(LCIMClient client) {
|
public LCIMConversationQuery(LCIMClient client) {
|
||||||
Condition = new LCCompositionalCondition();
|
Condition = new LCCompositionalCondition();
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
@ -250,10 +267,6 @@ namespace LeanCloud.Realtime {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WithLastMessageRefreshed {
|
|
||||||
get; set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a list of LCObjects matching this query.
|
/// Retrieves a list of LCObjects matching this query.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -355,6 +355,22 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
||||||
LCLogger.Error(e);
|
LCLogger.Error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int flag = 0;
|
||||||
|
if (query.Compact) {
|
||||||
|
flag += LCIMConversationQuery.CompactFlag;
|
||||||
|
}
|
||||||
|
if (query.WithLastMessageRefreshed) {
|
||||||
|
flag += LCIMConversationQuery.WithLastMessageFlag;
|
||||||
|
}
|
||||||
|
if (flag > 0) {
|
||||||
|
convMessage.Flag = flag;
|
||||||
|
}
|
||||||
|
convMessage.Skip = query.Condition.Skip;
|
||||||
|
convMessage.Limit = query.Condition.Limit;
|
||||||
|
string orders = query.Condition.BuildOrders();
|
||||||
|
if (!string.IsNullOrEmpty(orders)) {
|
||||||
|
convMessage.Sort = orders;
|
||||||
|
}
|
||||||
command.ConvMessage = convMessage;
|
command.ConvMessage = convMessage;
|
||||||
GenericCommand response = await Connection.SendRequest(command);
|
GenericCommand response = await Connection.SendRequest(command);
|
||||||
JsonObjectMessage results = response.ConvMessage.Results;
|
JsonObjectMessage results = response.ConvMessage.Results;
|
||||||
|
|
|
@ -212,14 +212,17 @@ namespace LeanCloud.Storage.Internal.Query {
|
||||||
if (conditionList != null && conditionList.Count > 0) {
|
if (conditionList != null && conditionList.Count > 0) {
|
||||||
dict["where"] = JsonConvert.SerializeObject(Encode());
|
dict["where"] = JsonConvert.SerializeObject(Encode());
|
||||||
}
|
}
|
||||||
if (orderByList != null && orderByList.Count > 0) {
|
string order = BuildOrders();
|
||||||
dict["order"] = string.Join(",", orderByList);
|
if (!string.IsNullOrEmpty(order)) {
|
||||||
|
dict["order"] = order;
|
||||||
}
|
}
|
||||||
if (includes != null && includes.Count > 0) {
|
string includes = BuildIncludes();
|
||||||
dict["include"] = string.Join(",", includes);
|
if (!string.IsNullOrEmpty(includes)) {
|
||||||
|
dict["include"] = includes;
|
||||||
}
|
}
|
||||||
if (selectedKeys != null && selectedKeys.Count > 0) {
|
string keys = BuildKeys();
|
||||||
dict["keys"] = string.Join(",", selectedKeys);
|
if (!string.IsNullOrEmpty(keys)) {
|
||||||
|
dict["keys"] = keys;
|
||||||
}
|
}
|
||||||
if (IncludeACL) {
|
if (IncludeACL) {
|
||||||
dict["returnACL"] = "true";
|
dict["returnACL"] = "true";
|
||||||
|
@ -233,5 +236,26 @@ namespace LeanCloud.Storage.Internal.Query {
|
||||||
}
|
}
|
||||||
return JsonConvert.SerializeObject(Encode());
|
return JsonConvert.SerializeObject(Encode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string BuildOrders() {
|
||||||
|
if (orderByList != null && orderByList.Count > 0) {
|
||||||
|
return string.Join(",", orderByList);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string BuildIncludes() {
|
||||||
|
if (includes != null && includes.Count > 0) {
|
||||||
|
return string.Join(",", includes);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string BuildKeys() {
|
||||||
|
if (selectedKeys != null && selectedKeys.Count > 0) {
|
||||||
|
return string.Join(",", selectedKeys);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue