2020-03-12 16:23:21 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-03-13 17:22:46 +08:00
|
|
|
|
using System.Linq;
|
2020-03-27 15:52:34 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
2020-03-19 15:12:50 +08:00
|
|
|
|
using LeanCloud.Storage;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
|
|
|
|
|
namespace LeanCloud.Realtime {
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 普通对话
|
|
|
|
|
/// </summary>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public class LCIMConversation {
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对话 Id
|
|
|
|
|
/// </summary>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public string Id {
|
2020-03-30 16:51:14 +08:00
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否唯一
|
|
|
|
|
/// </summary>
|
2020-03-30 16:51:14 +08:00
|
|
|
|
public bool Unique {
|
|
|
|
|
get; internal set;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 唯一 Id
|
|
|
|
|
/// </summary>
|
2020-03-23 16:46:27 +08:00
|
|
|
|
public string UniqueId {
|
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对话名称
|
|
|
|
|
/// </summary>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public string Name {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
get {
|
|
|
|
|
return this["name"] as string;
|
2020-03-30 16:51:14 +08:00
|
|
|
|
}
|
|
|
|
|
internal set {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
this["name"] = value;
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建者 Id
|
|
|
|
|
/// </summary>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public string CreatorId {
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 成员 Id
|
|
|
|
|
/// </summary>
|
2020-03-30 16:51:14 +08:00
|
|
|
|
public ReadOnlyCollection<string> MemberIds {
|
2020-03-27 15:52:34 +08:00
|
|
|
|
get {
|
|
|
|
|
return new ReadOnlyCollection<string>(ids.ToList());
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 静音成员 Id
|
|
|
|
|
/// </summary>
|
2020-03-27 15:52:34 +08:00
|
|
|
|
public ReadOnlyCollection<string> MutedMemberIds {
|
|
|
|
|
get {
|
|
|
|
|
return new ReadOnlyCollection<string>(mutedIds.ToList());
|
|
|
|
|
}
|
2020-03-23 16:46:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 未读消息数量
|
|
|
|
|
/// </summary>
|
2020-03-24 17:42:04 +08:00
|
|
|
|
public int Unread {
|
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最新的一条消息
|
|
|
|
|
/// </summary>
|
2020-03-24 17:42:04 +08:00
|
|
|
|
public LCIMMessage LastMessage {
|
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建时间
|
|
|
|
|
/// </summary>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public DateTime CreatedAt {
|
2020-03-19 15:12:50 +08:00
|
|
|
|
get; internal set;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新时间
|
|
|
|
|
/// </summary>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public DateTime UpdatedAt {
|
2020-03-19 15:12:50 +08:00
|
|
|
|
get; internal set;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最新送达消息时间戳
|
|
|
|
|
/// </summary>
|
2020-04-13 12:05:33 +08:00
|
|
|
|
public long LastDeliveredTimestamp {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最新送达消息时间
|
|
|
|
|
/// </summary>
|
2020-04-13 12:05:33 +08:00
|
|
|
|
public DateTime LastDeliveredAt {
|
|
|
|
|
get {
|
|
|
|
|
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(LastDeliveredTimestamp);
|
|
|
|
|
return dateTimeOffset.DateTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最新已读消息时间戳
|
|
|
|
|
/// </summary>
|
2020-04-13 12:05:33 +08:00
|
|
|
|
public long LastReadTimestamp {
|
|
|
|
|
get; internal set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 最新已读消息时间
|
|
|
|
|
/// </summary>
|
2020-04-13 12:05:33 +08:00
|
|
|
|
public DateTime LastReadAt {
|
|
|
|
|
get {
|
|
|
|
|
DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(LastReadTimestamp);
|
|
|
|
|
return dateTimeOffset.DateTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置/获取对话属性
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-17 11:41:38 +08:00
|
|
|
|
public object this[string key] {
|
|
|
|
|
get {
|
|
|
|
|
return customProperties[key];
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
customProperties[key] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否已静音
|
|
|
|
|
/// </summary>
|
2020-03-17 11:41:38 +08:00
|
|
|
|
public bool IsMute {
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
|
2020-03-25 16:42:30 +08:00
|
|
|
|
protected LCIMClient Client {
|
|
|
|
|
get; private set;
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
|
2020-04-16 11:38:22 +08:00
|
|
|
|
private readonly Dictionary<string, object> customProperties;
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
2020-03-27 15:52:34 +08:00
|
|
|
|
internal HashSet<string> ids;
|
|
|
|
|
|
|
|
|
|
internal HashSet<string> mutedIds;
|
|
|
|
|
|
2020-03-13 17:22:46 +08:00
|
|
|
|
internal LCIMConversation(LCIMClient client) {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
Client = client;
|
2020-03-17 11:41:38 +08:00
|
|
|
|
customProperties = new Dictionary<string, object>();
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取对话人数,或暂态对话的在线人数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-03-19 15:12:50 +08:00
|
|
|
|
public async Task<int> GetMembersCount() {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.GetMembersCount(Id);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-24 17:42:04 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将该会话标记为已读
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task Read() {
|
2020-03-24 17:42:04 +08:00
|
|
|
|
if (LastMessage == null) {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-16 11:38:22 +08:00
|
|
|
|
await Client.MessageController.Read(Id, LastMessage);
|
2020-03-25 16:42:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改对话属性
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="attributes"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task UpdateInfo(Dictionary<string, object> attributes) {
|
|
|
|
|
if (attributes == null || attributes.Count == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(attributes));
|
|
|
|
|
}
|
|
|
|
|
Dictionary<string, object> updatedAttr = await Client.ConversationController.UpdateInfo(Id, attributes);
|
|
|
|
|
if (updatedAttr != null) {
|
|
|
|
|
MergeInfo(updatedAttr);
|
2020-03-17 11:41:38 +08:00
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加用户到对话
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clientIds">用户 Id</param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task<LCIMPartiallySuccessResult> AddMembers(IEnumerable<string> clientIds) {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
if (clientIds == null || clientIds.Count() == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(clientIds));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.AddMembers(Id, clientIds);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="removeIds">用户 Id</param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task<LCIMPartiallySuccessResult> RemoveMembers(IEnumerable<string> removeIds) {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
if (removeIds == null || removeIds.Count() == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(removeIds));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.RemoveMembers(Id, removeIds);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加入对话
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task Join() {
|
|
|
|
|
LCIMPartiallySuccessResult result = await AddMembers(new string[] { Client.Id });
|
2020-03-19 15:12:50 +08:00
|
|
|
|
if (!result.IsSuccess) {
|
|
|
|
|
LCIMOperationFailure error = result.FailureList[0];
|
|
|
|
|
throw new LCException(error.Code, error.Reason);
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 离开对话
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task Quit() {
|
|
|
|
|
LCIMPartiallySuccessResult result = await RemoveMembers(new string[] { Client.Id });
|
2020-03-19 15:12:50 +08:00
|
|
|
|
if (!result.IsSuccess) {
|
|
|
|
|
LCIMOperationFailure error = result.FailureList[0];
|
|
|
|
|
throw new LCException(error.Code, error.Reason);
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发送消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-04-16 15:13:56 +08:00
|
|
|
|
public async Task<LCIMMessage> Send(LCIMMessage message,
|
|
|
|
|
LCIMMessageSendOptions options = null) {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
if (message == null) {
|
|
|
|
|
throw new ArgumentNullException(nameof(message));
|
|
|
|
|
}
|
2020-04-16 15:13:56 +08:00
|
|
|
|
if (options == null) {
|
|
|
|
|
options = LCIMMessageSendOptions.Default;
|
|
|
|
|
}
|
|
|
|
|
await Client.MessageController.Send(Id, message, options);
|
2020-04-23 09:52:32 +08:00
|
|
|
|
LastMessage = message;
|
2020-03-16 11:50:49 +08:00
|
|
|
|
return message;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 静音
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task Mute() {
|
|
|
|
|
await Client.ConversationController.Mute(Id);
|
2020-03-17 11:41:38 +08:00
|
|
|
|
IsMute = true;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消静音
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task Unmute() {
|
|
|
|
|
await Client.ConversationController.Unmute(Id);
|
2020-03-17 11:41:38 +08:00
|
|
|
|
IsMute = false;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 禁言
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clientIds"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-17 16:17:19 +08:00
|
|
|
|
public async Task<LCIMPartiallySuccessResult> MuteMembers(IEnumerable<string> clientIds) {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
if (clientIds == null || clientIds.Count() == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(clientIds));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.MuteMembers(Id, clientIds);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消禁言
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clientIdList"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-17 16:17:19 +08:00
|
|
|
|
public async Task<LCIMPartiallySuccessResult> UnmuteMembers(IEnumerable<string> clientIds) {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
if (clientIds == null || clientIds.Count() == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(clientIds));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.UnmuteMembers(Id, clientIds);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:41:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将用户加入黑名单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clientIds"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-17 16:17:19 +08:00
|
|
|
|
public async Task<LCIMPartiallySuccessResult> BlockMembers(IEnumerable<string> clientIds) {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
if (clientIds == null || clientIds.Count() == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(clientIds));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.BlockMembers(Id, clientIds);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 12:05:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将用户移除黑名单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clientIds"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-17 16:17:19 +08:00
|
|
|
|
public async Task<LCIMPartiallySuccessResult> UnblockMembers(IEnumerable<string> clientIds) {
|
|
|
|
|
if (clientIds == null || clientIds.Count() == 0) {
|
|
|
|
|
throw new ArgumentNullException(nameof(clientIds));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.UnblockMembers(Id, clientIds);
|
2020-03-17 16:17:19 +08:00
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
|
2020-03-17 16:17:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 撤回消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task RecallMessage(LCIMMessage message) {
|
2020-03-17 16:17:19 +08:00
|
|
|
|
if (message == null) {
|
|
|
|
|
throw new ArgumentNullException(nameof(message));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
await Client.MessageController.RecallMessage(Id, message);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 16:17:19 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改消息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="oldMessage"></param>
|
|
|
|
|
/// <param name="newMessage"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-25 16:42:30 +08:00
|
|
|
|
public async Task UpdateMessage(LCIMMessage oldMessage, LCIMMessage newMessage) {
|
2020-03-17 16:17:19 +08:00
|
|
|
|
if (oldMessage == null) {
|
|
|
|
|
throw new ArgumentNullException(nameof(oldMessage));
|
|
|
|
|
}
|
|
|
|
|
if (newMessage == null) {
|
|
|
|
|
throw new ArgumentNullException(nameof(newMessage));
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
await Client.MessageController.UpdateMessage(Id, oldMessage, newMessage);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 16:42:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新对话中成员的角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="memberId"></param>
|
|
|
|
|
/// <param name="role"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task UpdateMemberRole(string memberId, string role) {
|
2020-03-17 16:17:19 +08:00
|
|
|
|
if (string.IsNullOrEmpty(memberId)) {
|
|
|
|
|
throw new ArgumentNullException(nameof(memberId));
|
|
|
|
|
}
|
|
|
|
|
if (role != LCIMConversationMemberInfo.Manager && role != LCIMConversationMemberInfo.Member) {
|
|
|
|
|
throw new ArgumentException("role MUST be Manager Or Memebr");
|
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
await Client.ConversationController.UpdateMemberRole(Id, memberId, role);
|
|
|
|
|
}
|
2020-03-17 16:17:19 +08:00
|
|
|
|
|
2020-03-25 16:42:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取对话中成员的角色(只返回管理员)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2020-03-27 15:52:34 +08:00
|
|
|
|
public async Task<ReadOnlyCollection<LCIMConversationMemberInfo>> GetAllMemberInfo() {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.GetAllMemberInfo(Id);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 16:42:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取对话中指定成员的角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="memberId"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-03-12 16:23:21 +08:00
|
|
|
|
public async Task<LCIMConversationMemberInfo> GetMemberInfo(string memberId) {
|
2020-03-17 11:41:38 +08:00
|
|
|
|
if (string.IsNullOrEmpty(memberId)) {
|
|
|
|
|
throw new ArgumentNullException(nameof(memberId));
|
|
|
|
|
}
|
2020-03-27 15:52:34 +08:00
|
|
|
|
ReadOnlyCollection<LCIMConversationMemberInfo> members = await GetAllMemberInfo();
|
2020-03-17 16:17:19 +08:00
|
|
|
|
foreach (LCIMConversationMemberInfo member in members) {
|
|
|
|
|
if (member.MemberId == memberId) {
|
|
|
|
|
return member;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 15:52:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询禁言用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="limit"></param>
|
|
|
|
|
/// <param name="next"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<LCIMPageResult> QueryMutedMembers(int limit = 10,
|
|
|
|
|
string next = null) {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.QueryMutedMembers(Id, limit, next);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 15:52:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询黑名单用户
|
|
|
|
|
/// </summary>
|
2020-04-13 12:05:33 +08:00
|
|
|
|
/// <param name="limit">限制</param>
|
|
|
|
|
/// <param name="next">其实用户 Id</param>
|
2020-03-27 15:52:34 +08:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<LCIMPageResult> QueryBlockedMembers(int limit = 10,
|
|
|
|
|
string next = null) {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.ConversationController.QueryBlockedMembers(Id, limit, next);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 12:05:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询聊天记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="start">起点</param>
|
|
|
|
|
/// <param name="end">终点</param>
|
|
|
|
|
/// <param name="direction">查找方向</param>
|
|
|
|
|
/// <param name="limit">限制</param>
|
|
|
|
|
/// <param name="messageType">消息类型</param>
|
|
|
|
|
/// <returns></returns>
|
2020-04-16 11:38:22 +08:00
|
|
|
|
public async Task<ReadOnlyCollection<LCIMMessage>> QueryMessages(LCIMMessageQueryEndpoint start = null,
|
2020-03-24 17:42:04 +08:00
|
|
|
|
LCIMMessageQueryEndpoint end = null,
|
|
|
|
|
LCIMMessageQueryDirection direction = LCIMMessageQueryDirection.NewToOld,
|
|
|
|
|
int limit = 20,
|
|
|
|
|
int messageType = 0) {
|
2020-03-25 16:42:30 +08:00
|
|
|
|
return await Client.MessageController.QueryMessages(Id, start, end, direction, limit, messageType);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
2020-03-13 17:22:46 +08:00
|
|
|
|
|
2020-04-13 12:05:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取会话已收/已读时间戳
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task FetchReciptTimestamps() {
|
|
|
|
|
await Client.ConversationController.FetchReciptTimestamp(Id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 16:08:35 +08:00
|
|
|
|
internal static bool IsTemporayConversation(string convId) {
|
|
|
|
|
return convId.StartsWith("_tmp:");
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 16:21:32 +08:00
|
|
|
|
internal void MergeFrom(Dictionary<string, object> conv) {
|
|
|
|
|
if (conv.TryGetValue("objectId", out object idObj)) {
|
|
|
|
|
Id = idObj as string;
|
|
|
|
|
}
|
2020-03-30 16:51:14 +08:00
|
|
|
|
if (conv.TryGetValue("unique", out object uniqueObj)) {
|
|
|
|
|
Unique = (bool)uniqueObj;
|
|
|
|
|
}
|
2020-03-23 16:46:27 +08:00
|
|
|
|
if (conv.TryGetValue("uniqueId", out object uniqueIdObj)) {
|
|
|
|
|
UniqueId = uniqueIdObj as string;
|
|
|
|
|
}
|
|
|
|
|
if (conv.TryGetValue("createdAt", out object createdAtObj)) {
|
|
|
|
|
CreatedAt = DateTime.Parse(createdAtObj.ToString());
|
|
|
|
|
}
|
|
|
|
|
if (conv.TryGetValue("updatedAt", out object updatedAtObj)) {
|
|
|
|
|
UpdatedAt = DateTime.Parse(updatedAtObj.ToString());
|
|
|
|
|
}
|
|
|
|
|
if (conv.TryGetValue("c", out object co)) {
|
|
|
|
|
CreatorId = co as string;
|
|
|
|
|
}
|
|
|
|
|
if (conv.TryGetValue("m", out object mo)) {
|
2020-03-30 16:51:14 +08:00
|
|
|
|
IEnumerable<string> ids = (mo as IList<object>).Cast<string>();
|
|
|
|
|
this.ids = new HashSet<string>(ids);
|
2020-03-23 16:46:27 +08:00
|
|
|
|
}
|
|
|
|
|
if (conv.TryGetValue("mu", out object muo)) {
|
2020-03-30 16:51:14 +08:00
|
|
|
|
IEnumerable<string> ids = (muo as IList<object>).Cast<string>();
|
|
|
|
|
mutedIds = new HashSet<string>(ids);
|
|
|
|
|
}
|
2020-04-13 12:05:33 +08:00
|
|
|
|
//if (conv.TryGetValue("lm", out object lmo)) {
|
|
|
|
|
// LastMessageAt = (DateTime)LCDecoder.Decode(lmo);
|
|
|
|
|
//}
|
2020-03-23 16:21:32 +08:00
|
|
|
|
}
|
2020-03-25 16:42:30 +08:00
|
|
|
|
|
|
|
|
|
internal void MergeInfo(Dictionary<string, object> attr) {
|
|
|
|
|
if (attr == null || attr.Count == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
foreach (KeyValuePair<string, object> kv in attr) {
|
|
|
|
|
customProperties[kv.Key] = kv.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|