public DemoMessage(AVIMMessage avMessage)
 {
     var user = App.ViewModel.AllContacts.Where(t => t.UserId == avMessage.FromClientId).FirstOrDefault();
     this.From = user.Nickname;
     TextContent = avMessage.MessageBody;
     this.avMessage = avMessage;
 }
 internal void CopyFromBase(AVIMMessage avMessage)
 {
     this.Id = avMessage.Id;
     this.ConversationId = avMessage.ConversationId;
     this.cmdId = avMessage.cmdId;
     this.FromClientId = avMessage.FromClientId;
     this.MessageIOType = avMessage.MessageIOType;
     this.MessageStatus = avMessage.MessageStatus;
     this.Receipt = avMessage.Receipt;
     this.ServerTimestamp = avMessage.ServerTimestamp;
     this.Transient = avMessage.Transient;
     this.typedMessageBody = AVClient.DeserializeJsonString(avMessage.MessageBody);
     this.Attributes = this.typedMessageBody[AVIMProtocol.LCATTRS] as IDictionary<string, object>;
 }
 public Task<Tuple<bool, AVIMMessage>> SendMessageAsync(AVIMMessage avMessage)
 {
     Dictionary<string, object> dictionary = new Dictionary<string, object>();
     int cmdId = AVIMCommon.NextCmdId;
     avMessage.MessageIOType = AVIMMessageIOType.AVIMMessageIOTypeOut;
     dictionary.Add("cmd", (object)"direct");
     dictionary.Add("cid", (object)this.ConversationId);
     dictionary.Add("r", (avMessage.Receipt ? 1 : 0));
     dictionary.Add("transient", (avMessage.Transient ? 1 : 0));
     dictionary.Add("msg", (object)avMessage.MessageBody);
     dictionary.Add("peerId", (object)this.CurrentClient.ClientId);
     dictionary.Add("i", (object)cmdId);
     dictionary.Add("appId", (object)AVClient.ApplicationId);
     return InternalExtensions.OnSuccess<Tuple<string, IDictionary<string, object>>, Tuple<bool, AVIMMessage>>(this.CurrentClient.OpenThenSendAsync((IDictionary<string, object>)dictionary), (Func<Task<Tuple<string, IDictionary<string, object>>>, Tuple<bool, AVIMMessage>>)(t =>
     {
         IDictionary<string, object> data = t.Result.Item2;
         AVRMProtocolUtils.CaptureValueFromDictionary<string>(data, "cmd");
         avMessage.cmdId = cmdId.ToString();
         avMessage.MessageStatus = AVIMMessageStatus.AVIMMessageStatusSent;
         avMessage.ConversationId = this.ConversationId;
         avMessage.FromClientId = this.CurrentClient.ClientId;
         avMessage.Id = AVRMProtocolUtils.CaptureValueFromDictionary<string>(data, "uid");
         avMessage.ServerTimestamp = AVRMProtocolUtils.CaptureValueFromDictionary<long>(data, "t");
         Tuple<bool, AVIMMessage> tuple = new Tuple<bool, AVIMMessage>(true, avMessage);
         this.LastMesaageAt = new DateTime?(AVPersistence.UnixTimeStampToDateTime(avMessage.ServerTimestamp));
         return tuple;
     }));
 }
 private string EscapedMessage(AVIMMessage message)
 {
     if (message is AVIMTextMessage)
     {
         return ((AVIMTextMessage)message).TextContent;
     }
     return message.MessageBody;
 }
        private void CacheMessage(AVIMConversation conversation, AVIMMessage message)
        {
            if (historyDictionary == null)
            {
                historyDictionary = new Dictionary<string, BindingList<string>>();
            }
            var record = message.FromClientId + ": " + EscapedMessage(message);
            if (historyDictionary.ContainsKey(conversation.ConversationId))
            {
                historyDictionary[conversation.ConversationId].Add(record);
            }
            else
            {
                var history = new BindingList<string>();
                history.Add(record);
                historyDictionary.Add(conversation.ConversationId, history);
            }

            RefreshUI(() =>
            {
                Log("收到 " + message.FromClientId + " 发送的消息;");
            });

        }
 private void AVConversation_OnMessageRecieved(object sender, AVIMMessage e)
 {
     DispatcherHelper.CheckBeginInvokeOnUI(() =>
     {
         messages.Add(new DemoMessage(e) { DisplayTime = DateTime.Now });
     });
 }
 public AVIMTypedMessage(AVIMMessage avMessage)
 {
 }