* LCIMConversation.cs:

* LCIMMessageSendOptions.cs:

* LCIMMessageController.cs: chore: 支持发送消息选项
oneRain 2020-04-16 15:13:56 +08:00
parent 95acf35e65
commit 50120e181f
3 changed files with 69 additions and 3 deletions

View File

@ -254,11 +254,15 @@ namespace LeanCloud.Realtime {
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public async Task<LCIMMessage> Send(LCIMMessage message) {
public async Task<LCIMMessage> Send(LCIMMessage message,
LCIMMessageSendOptions options = null) {
if (message == null) {
throw new ArgumentNullException(nameof(message));
}
await Client.MessageController.Send(Id, message);
if (options == null) {
options = LCIMMessageSendOptions.Default;
}
await Client.MessageController.Send(Id, message, options);
return message;
}

View File

@ -21,7 +21,8 @@ namespace LeanCloud.Realtime.Internal.Controller {
/// <param name="message"></param>
/// <returns></returns>
internal async Task<LCIMMessage> Send(string convId,
LCIMMessage message) {
LCIMMessage message,
LCIMMessageSendOptions options) {
DirectCommand direct = new DirectCommand {
FromPeerId = Client.Id,
Cid = convId,
@ -33,8 +34,24 @@ namespace LeanCloud.Realtime.Internal.Controller {
} else {
throw new ArgumentException("Message MUST BE LCIMTypedMessage or LCIMBinaryMessage.");
}
// 暂态消息
if (options.Transient) {
direct.Transient = options.Transient;
}
// 消息接收回执
if (options.Receipt) {
direct.R = options.Receipt;
}
// 遗愿消息
if (options.Will) {
direct.Will = options.Will;
}
GenericCommand command = NewCommand(CommandType.Direct);
command.DirectMessage = direct;
// 优先级
if (command.Priority > 0) {
command.Priority = (int)options.Priority;
}
GenericCommand response = await Client.Connection.SendRequest(command);
// 消息发送应答
AckCommand ack = response.AckMessage;

View File

@ -0,0 +1,45 @@
namespace LeanCloud.Realtime {
/// <summary>
/// 消息优先级
/// </summary>
public enum LCIMMessagePriority {
Hight = 1,
Normal = 2,
Low = 3
}
/// <summary>
/// 发送消息选项
/// </summary>
public class LCIMMessageSendOptions {
/// <summary>
/// 是否作为暂态消息发送
/// </summary>
public bool Transient {
get; set;
}
/// <summary>
/// 是否需要消息回执,仅在普通对话中有效
/// </summary>
public bool Receipt {
get; set;
}
/// <summary>
/// 是否作为遗愿消息发送
/// </summary>
public bool Will {
get; set;
}
/// <summary>
/// 消息优先级,仅在暂态对话中有效
/// </summary>
public LCIMMessagePriority Priority {
get; set;
}
public static LCIMMessageSendOptions Default = new LCIMMessageSendOptions();
}
}