/// <summary> /// 向目标对话发送消息 /// </summary> /// <param name="conversation">目标对话</param> /// <param name="message">消息体</param> /// <param name="options">消息的发送选项,包含了一些特殊的标记<see cref="AVIMSendOptions"/></param> /// <returns></returns> public Task <IAVIMMessage> SendMessageAsync( AVIMConversation conversation, IAVIMMessage message, AVIMSendOptions options) { if (this.LinkedRealtime.State != AVRealtime.Status.Online) { throw new Exception("未能连接到服务器,无法发送消息。"); } var messageBody = message.Serialize(); message.ConversationId = conversation.ConversationId; message.FromClientId = this.ClientId; var cmd = new MessageCommand() .Message(messageBody) .ConvId(conversation.ConversationId) .Receipt(options.Receipt) .Transient(options.Transient) .Priority(options.Priority) .Will(options.Will) .MentionAll(message.MentionAll); if (message is AVIMMessage) { cmd = ((AVIMMessage)message).BeforeSend(cmd); } if (options.PushData != null) { cmd = cmd.PushData(options.PushData); } if (message.MentionList != null) { cmd = cmd.Mention(message.MentionList); } var directCmd = cmd.PeerId(this.ClientId); return(this.RunCommandAsync(directCmd).OnSuccess(t => { var response = t.Result.Item2; message.Id = response["uid"].ToString(); message.ServerTimestamp = long.Parse(response["t"].ToString()); return message; })); }
public PatchCommand Modify(IAVIMMessage oldMessage, IAVIMMessage newMessage) { var patch = new Patch() { ConvId = oldMessage.ConversationId, From = oldMessage.FromClientId, MessageId = oldMessage.Id, MetaTimestamp = oldMessage.ServerTimestamp, Recall = false, PatchTimestamp = DateTime.Now.UnixTimeStampSeconds(), PatchData = newMessage.Serialize() }; this.Patches.Add(patch); this.Argument("patches", this.EncodePatches()); return(new PatchCommand(this, this.Patches)); }
/// <summary> /// 向目标对话发送消息 /// </summary> /// <param name="conversation">目标对话</param> /// <param name="message">消息体</param> /// <param name="options">消息的发送选项,包含了一些特殊的标记<see cref="AVIMSendOptions"/></param> /// <returns></returns> public Task <IAVIMMessage> SendMessageAsync( AVIMConversation conversation, IAVIMMessage message, AVIMSendOptions options = default(AVIMSendOptions)) { var messageBody = message.Serialize(); message.ConversationId = conversation.ConversationId; message.FromClientId = this.ClientId; var cmd = new MessageCommand() .Message(messageBody) .ConvId(conversation.ConversationId) .Receipt(options.Receipt) .Transient(options.Transient) .Priority(options.Priority) .Will(options.Will); if (options.PushData != null) { cmd.PushData(options.PushData); } var directCmd = cmd.PeerId(this.ClientId); return(AVRealtime.AVIMCommandRunner.RunCommandAsync(directCmd).ContinueWith <IAVIMMessage>(t => { if (t.IsFaulted) { throw t.Exception; } else { var response = t.Result.Item2; message.Id = response["uid"].ToString(); message.ServerTimestamp = long.Parse(response["t"].ToString()); return message; } })); }