feat: support compact, withLastMessage
parent
bf5e49f40e
commit
6ace14fa0f
|
@ -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 {
|
||||
/// <summary>
|
||||
|
@ -470,6 +469,17 @@ namespace LeanCloud.Realtime {
|
|||
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) {
|
||||
return convId.StartsWith("_tmp:");
|
||||
}
|
||||
|
@ -504,9 +514,28 @@ namespace LeanCloud.Realtime {
|
|||
IEnumerable<string> ids = (muo as IList<object>).Cast<string>();
|
||||
mutedIds = new HashSet<string>(ids);
|
||||
}
|
||||
//if (conv.TryGetValue("lm", out object lmo)) {
|
||||
// LastMessageAt = (DateTime)LCDecoder.Decode(lmo);
|
||||
//}
|
||||
if (conv.TryGetValue("msg", out object msgo)) {
|
||||
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) {
|
||||
|
|
|
@ -5,12 +5,29 @@ using LeanCloud.Storage.Internal.Query;
|
|||
|
||||
namespace LeanCloud.Realtime {
|
||||
public class LCIMConversationQuery {
|
||||
internal const int CompactFlag = 0x1;
|
||||
internal const int WithLastMessageFlag = 0x2;
|
||||
|
||||
internal LCCompositionalCondition Condition {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
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) {
|
||||
Condition = new LCCompositionalCondition();
|
||||
this.client = client;
|
||||
|
@ -250,10 +267,6 @@ namespace LeanCloud.Realtime {
|
|||
return this;
|
||||
}
|
||||
|
||||
public bool WithLastMessageRefreshed {
|
||||
get; set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a list of LCObjects matching this query.
|
||||
/// </summary>
|
||||
|
|
|
@ -355,6 +355,22 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
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;
|
||||
GenericCommand response = await Connection.SendRequest(command);
|
||||
JsonObjectMessage results = response.ConvMessage.Results;
|
||||
|
|
|
@ -212,14 +212,17 @@ namespace LeanCloud.Storage.Internal.Query {
|
|||
if (conditionList != null && conditionList.Count > 0) {
|
||||
dict["where"] = JsonConvert.SerializeObject(Encode());
|
||||
}
|
||||
if (orderByList != null && orderByList.Count > 0) {
|
||||
dict["order"] = string.Join(",", orderByList);
|
||||
string order = BuildOrders();
|
||||
if (!string.IsNullOrEmpty(order)) {
|
||||
dict["order"] = order;
|
||||
}
|
||||
if (includes != null && includes.Count > 0) {
|
||||
dict["include"] = string.Join(",", includes);
|
||||
string includes = BuildIncludes();
|
||||
if (!string.IsNullOrEmpty(includes)) {
|
||||
dict["include"] = includes;
|
||||
}
|
||||
if (selectedKeys != null && selectedKeys.Count > 0) {
|
||||
dict["keys"] = string.Join(",", selectedKeys);
|
||||
string keys = BuildKeys();
|
||||
if (!string.IsNullOrEmpty(keys)) {
|
||||
dict["keys"] = keys;
|
||||
}
|
||||
if (IncludeACL) {
|
||||
dict["returnACL"] = "true";
|
||||
|
@ -233,5 +236,26 @@ namespace LeanCloud.Storage.Internal.Query {
|
|||
}
|
||||
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