* LCIMConversationController.cs:

* LCIMConversation.cs: chore: 支持消息分发状态查询
oneRain 2020-04-13 12:05:33 +08:00
parent b89709b21d
commit 35c66d65cf
2 changed files with 59 additions and 6 deletions

View File

@ -61,10 +61,28 @@ namespace LeanCloud.Realtime {
get; internal set; get; internal set;
} }
public DateTime LastMessageAt { public long LastDeliveredTimestamp {
get; internal set; get; internal set;
} }
public DateTime LastDeliveredAt {
get {
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(LastDeliveredTimestamp);
return dateTimeOffset.DateTime;
}
}
public long LastReadTimestamp {
get; internal set;
}
public DateTime LastReadAt {
get {
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(LastReadTimestamp);
return dateTimeOffset.DateTime;
}
}
public object this[string key] { public object this[string key] {
get { get {
return customProperties[key]; return customProperties[key];
@ -243,6 +261,11 @@ namespace LeanCloud.Realtime {
return await Client.ConversationController.BlockMembers(Id, clientIds); return await Client.ConversationController.BlockMembers(Id, clientIds);
} }
/// <summary>
/// 将用户移除黑名单
/// </summary>
/// <param name="clientIds"></param>
/// <returns></returns>
public async Task<LCIMPartiallySuccessResult> UnblockMembers(IEnumerable<string> clientIds) { public async Task<LCIMPartiallySuccessResult> UnblockMembers(IEnumerable<string> clientIds) {
if (clientIds == null || clientIds.Count() == 0) { if (clientIds == null || clientIds.Count() == 0) {
throw new ArgumentNullException(nameof(clientIds)); throw new ArgumentNullException(nameof(clientIds));
@ -334,14 +357,23 @@ namespace LeanCloud.Realtime {
/// <summary> /// <summary>
/// 查询黑名单用户 /// 查询黑名单用户
/// </summary> /// </summary>
/// <param name="limit"></param> /// <param name="limit">限制</param>
/// <param name="next"></param> /// <param name="next">其实用户 Id</param>
/// <returns></returns> /// <returns></returns>
public async Task<LCIMPageResult> QueryBlockedMembers(int limit = 10, public async Task<LCIMPageResult> QueryBlockedMembers(int limit = 10,
string next = null) { string next = null) {
return await Client.ConversationController.QueryBlockedMembers(Id, limit, next); return await Client.ConversationController.QueryBlockedMembers(Id, limit, next);
} }
/// <summary>
/// 查询聊天记录
/// </summary>
/// <param name="start">起点</param>
/// <param name="end">终点</param>
/// <param name="direction">查找方向</param>
/// <param name="limit">限制</param>
/// <param name="messageType">消息类型</param>
/// <returns></returns>
public async Task<List<LCIMMessage>> QueryMessages(LCIMMessageQueryEndpoint start = null, public async Task<List<LCIMMessage>> QueryMessages(LCIMMessageQueryEndpoint start = null,
LCIMMessageQueryEndpoint end = null, LCIMMessageQueryEndpoint end = null,
LCIMMessageQueryDirection direction = LCIMMessageQueryDirection.NewToOld, LCIMMessageQueryDirection direction = LCIMMessageQueryDirection.NewToOld,
@ -350,6 +382,14 @@ namespace LeanCloud.Realtime {
return await Client.MessageController.QueryMessages(Id, start, end, direction, limit, messageType); return await Client.MessageController.QueryMessages(Id, start, end, direction, limit, messageType);
} }
/// <summary>
/// 获取会话已收/已读时间戳
/// </summary>
/// <returns></returns>
public async Task FetchReciptTimestamps() {
await Client.ConversationController.FetchReciptTimestamp(Id);
}
internal static bool IsTemporayConversation(string convId) { internal static bool IsTemporayConversation(string convId) {
return convId.StartsWith("_tmp:"); return convId.StartsWith("_tmp:");
} }
@ -381,9 +421,9 @@ 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("lm", out object lmo)) {
LastMessageAt = (DateTime)LCDecoder.Decode(lmo); // LastMessageAt = (DateTime)LCDecoder.Decode(lmo);
} //}
} }
internal void MergeInfo(Dictionary<string, object> attr) { internal void MergeInfo(Dictionary<string, object> attr) {

View File

@ -498,6 +498,19 @@ namespace LeanCloud.Realtime.Internal.Controller {
return convList; return convList;
} }
internal async Task FetchReciptTimestamp(string convId) {
ConvCommand convCommand = new ConvCommand {
Cid = convId
};
GenericCommand request = Client.NewCommand(CommandType.Conv, OpType.MaxRead);
request.ConvMessage = convCommand;
GenericCommand response = await Connection.SendRequest(request);
convCommand = response.ConvMessage;
LCIMConversation conversation = await Client.GetOrQueryConversation(convCommand.Cid);
conversation.LastDeliveredTimestamp = convCommand.MaxAckTimestamp;
conversation.LastReadTimestamp = convCommand.MaxReadTimestamp;
}
private LCIMPartiallySuccessResult NewPartiallySuccessResult(IEnumerable<string> succesfulIds, private LCIMPartiallySuccessResult NewPartiallySuccessResult(IEnumerable<string> succesfulIds,
IEnumerable<ErrorCommand> errors) { IEnumerable<ErrorCommand> errors) {
LCIMPartiallySuccessResult result = new LCIMPartiallySuccessResult { LCIMPartiallySuccessResult result = new LCIMPartiallySuccessResult {