* LCIMConversation.cs:

* LCIMConversationController.cs: chore: 完善对话接口
oneRain 2020-04-24 17:41:24 +08:00
parent 99975d9f7f
commit ae8fbfa830
2 changed files with 29 additions and 10 deletions

View File

@ -164,6 +164,9 @@ namespace LeanCloud.Realtime {
internal LCIMConversation(LCIMClient client) {
Client = client;
customProperties = new Dictionary<string, object>();
ids = new HashSet<string>();
mutedIds = new HashSet<string>();
customProperties = new Dictionary<string, object>();
}
/// <summary>
@ -210,7 +213,9 @@ namespace LeanCloud.Realtime {
if (clientIds == null || clientIds.Count() == 0) {
throw new ArgumentNullException(nameof(clientIds));
}
return await Client.ConversationController.AddMembers(Id, clientIds);
LCIMPartiallySuccessResult result = await Client.ConversationController.AddMembers(Id, clientIds);
ids.UnionWith(result.SuccessfulClientIdList);
return result;
}
/// <summary>
@ -222,7 +227,9 @@ namespace LeanCloud.Realtime {
if (removeIds == null || removeIds.Count() == 0) {
throw new ArgumentNullException(nameof(removeIds));
}
return await Client.ConversationController.RemoveMembers(Id, removeIds);
LCIMPartiallySuccessResult result = await Client.ConversationController.RemoveMembers(Id, removeIds);
ids.RemoveWhere(id => result.SuccessfulClientIdList.Contains(id));
return result;
}
/// <summary>
@ -294,7 +301,11 @@ namespace LeanCloud.Realtime {
if (clientIds == null || clientIds.Count() == 0) {
throw new ArgumentNullException(nameof(clientIds));
}
return await Client.ConversationController.MuteMembers(Id, clientIds);
LCIMPartiallySuccessResult result = await Client.ConversationController.MuteMembers(Id, clientIds);
if (result.SuccessfulClientIdList != null) {
mutedIds.UnionWith(result.SuccessfulClientIdList);
}
return result;
}
/// <summary>
@ -306,7 +317,11 @@ namespace LeanCloud.Realtime {
if (clientIds == null || clientIds.Count() == 0) {
throw new ArgumentNullException(nameof(clientIds));
}
return await Client.ConversationController.UnmuteMembers(Id, clientIds);
LCIMPartiallySuccessResult result = await Client.ConversationController.UnmuteMembers(Id, clientIds);
if (result.SuccessfulClientIdList != null) {
mutedIds.RemoveWhere(id => result.SuccessfulClientIdList.Contains(id));
}
return result;
}
/// <summary>

View File

@ -375,9 +375,11 @@ namespace LeanCloud.Realtime.Internal.Controller {
string next = null) {
ConvCommand conv = new ConvCommand {
Cid = convId,
Limit = limit,
Next = next
Limit = limit
};
if (next != null) {
conv.Next = next;
}
GenericCommand request = NewCommand(CommandType.Conv, OpType.QueryShutup);
request.ConvMessage = conv;
GenericCommand response = await Client.Connection.SendRequest(request);
@ -399,9 +401,11 @@ namespace LeanCloud.Realtime.Internal.Controller {
string next = null) {
BlacklistCommand black = new BlacklistCommand {
SrcCid = convId,
Limit = limit,
Next = next
Limit = limit
};
if (next != null) {
black.Next = next;
}
GenericCommand request = NewCommand(CommandType.Blacklist, OpType.Query);
request.BlacklistMessage = black;
GenericCommand response = await Client.Connection.SendRequest(request);
@ -620,7 +624,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
private async Task OnMembersJoined(ConvCommand convMessage) {
LCIMConversation conversation = await Client.GetOrQueryConversation(convMessage.Cid);
ReadOnlyCollection<string> joinedIds = new ReadOnlyCollection<string>(convMessage.M);
conversation.ids.Union(joinedIds);
conversation.ids.UnionWith(joinedIds);
Client.OnMembersJoined?.Invoke(conversation, joinedIds, convMessage.InitBy);
}
@ -666,7 +670,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
private async Task OnMembersMuted(ConvCommand convMessage) {
LCIMConversation conversation = await Client.GetOrQueryConversation(convMessage.Cid);
ReadOnlyCollection<string> mutedMemberIds = new ReadOnlyCollection<string>(convMessage.M);
conversation.mutedIds.Union(mutedMemberIds);
conversation.mutedIds.UnionWith(mutedMemberIds);
Client.OnMembersMuted?.Invoke(conversation, mutedMemberIds, convMessage.InitBy);
}