Beispiel #1
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="avMessage">消息体</param>
 /// <param name="options">消息的发送选项,包含了一些特殊的标记<see cref="AVIMSendOptions"/></param>
 /// <returns></returns>
 public Task <IAVIMMessage> SendMessageAsync(IAVIMMessage avMessage, AVIMSendOptions options)
 {
     if (this.CurrentClient == null)
     {
         throw new Exception("当前对话未指定有效 AVIMClient,无法发送消息。");
     }
     return(this.CurrentClient.SendMessageAsync(this, avMessage, options));
 }
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="avMessage">消息体</param>
 /// <param name="options">消息的发送选项,包含了一些特殊的标记<see cref="AVIMSendOptions"/></param>
 /// <returns></returns>
 public Task <IAVIMMessage> SendMessageAsync(IAVIMMessage avMessage, AVIMSendOptions options)
 {
     if (this.CurrentClient == null)
     {
         throw new Exception("当前对话未指定有效 AVIMClient,无法发送消息。");
     }
     if (this.CurrentClient.LinkedRealtime.State != AVRealtime.Status.Online)
     {
         throw new Exception("未能连接到服务器,无法发送消息。");
     }
     return(this.CurrentClient.SendMessageAsync(this, avMessage, options));
 }
Beispiel #3
0
        /// <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;
            }));
        }
Beispiel #4
0
        /// <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;
                }
            }));
        }