public ConversationViewModel(AVIMConversation avConversation)
     : this()
 {
     this._avConversation = avConversation;
     this._avConversation.PropertyChanged += _avConversation_PropertyChanged;
     RefreshUI();
 }
 public Conversation()
 {
     InitializeComponent();
     DataContext = App.ViewModel.SelectedConversationVM;
     conversation = App.ViewModel.SelectedConversationVM.AVConversation;
     messages = App.ViewModel.SelectedConversationVM.Messages;
     conversation.OnMessageReceived += AVConversation_OnMessageRecieved;
     conversation.OnTextMessageReceived += conversation_OnTextMessageReceived;
     conversation.OnImageMessageReceived += conversation_OnImageMessageReceived;
 }
        private async void selfClient_OnMessageReceieved(object sender, AVIMOnMessageReceivedEventArgs e)
        {
            var flag = currentConversation != null;
            await e.Conversation.FetchAsync();
            currentConversation = await selfClient.GetQuery().GetAsync(e.Conversation.ConversationId);
            if (flag)
            {
                flag = e.Conversation.ConversationId == currentConversation.ConversationId;
            }
            if (flag)
            {
                RefreshUI(() =>
                {
                    CacheMessage(e.Conversation, e.Message);
                });
            }
            else
            {
                CacheMessage(e.Conversation, e.Message);
            }

        }
        private void lbx_conversations_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selection = (AVIMConversation)lbx_conversations.SelectedItem;
            currentConversation = selection;
            membersInConversation = new BindingList<string>(selection.MemberIds);
            lbx_members.DataSource = membersInConversation;
            if (!historyDictionary.ContainsKey(selection.ConversationId))
            {
                historyDictionary.Add(selection.ConversationId, new BindingList<string>());
            }

            lbx_history.DataSource = historyDictionary[selection.ConversationId];
            Log("当前选择对话为: " + selection.Name + ",对话最后更新的时间为:" + selection.UpdatedAt.Value.ToShortTimeString());
        }
        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 + " 发送的消息;");
            });

        }
 internal static AVIMOnMembersChangedEventArgs GenerateConversationMembersChangedArgs(IDictionary<string, object> e, List<Tuple<object, EventHandler<AVIMOnMembersChangedEventArgs>>> eventHandlers)
 {
     AVIMConversation conversation = new AVIMConversation
     {
         ConversationId = e.CaptureValueFromDictionary<string>("cid")
     };
     AVIMOnMembersChangedEventArgs aVIMOnMembersChangedEventArgs = null;
     GenerateAVIMOnMembersChangedEventArgs[] array = new GenerateAVIMOnMembersChangedEventArgs[]
     {
         (IDictionary<string, object> e1) => new AVIMOnMembersChangedEventArgs
         {
             Conversation = conversation,
             AffectedType = AVIMConversationEventType.Joined,
             Oprator = e.CaptureValueFromDictionary<string>("initBy"),
             AffectedMembers = null
         },
         (IDictionary<string, object> e2) => new AVIMOnMembersChangedEventArgs
         {
             Conversation = conversation,
             AffectedType = AVIMConversationEventType.Left,
             Oprator = e.CaptureValueFromDictionary<string>("initBy"),
             AffectedMembers = null
         },
         (IDictionary<string, object> e3) => new AVIMOnMembersChangedEventArgs
         {
             Conversation = conversation,
             AffectedType = AVIMConversationEventType.MembersJoined,
             Oprator = e.CaptureValueFromDictionary<string>("initBy"),
             AffectedMembers = e.CaptureListFromDictionary<string>("m")
         },
         (IDictionary<string, object> e4) => new AVIMOnMembersChangedEventArgs
         {
             Conversation = conversation,
             AffectedType = AVIMConversationEventType.MembersLeft,
             Oprator = e.CaptureValueFromDictionary<string>("initBy"),
             AffectedMembers = e.CaptureListFromDictionary<string>("m")
         },
         (IDictionary<string, object> e5) => new AVIMOnMembersChangedEventArgs
         {
             Conversation = conversation,
             AffectedType = AVIMConversationEventType.Invited,
             Oprator = e.CaptureValueFromDictionary<string>("initBy")
         },
         (IDictionary<string, object> e6) => new AVIMOnMembersChangedEventArgs
         {
             Conversation = conversation,
             AffectedType = AVIMConversationEventType.Kicked,
             Oprator = e.CaptureValueFromDictionary<string>("initBy")
         }
     };
     string[] array2 = new string[]
     {
         "joined",
         "left",
         "members-joined",
         "members-left",
         "added",
         "removed"
     };
     string text = e.CaptureValueFromDictionary<string>("op");
     int num = Array.IndexOf<string>(array2, text);
     if (num > 0)
     {
         GenerateAVIMOnMembersChangedEventArgs generateAVIMOnMembersChangedEventArgs = array[num];
         aVIMOnMembersChangedEventArgs = generateAVIMOnMembersChangedEventArgs(e);
         if (eventHandlers != null)
         {
             Tuple<object, EventHandler<AVIMOnMembersChangedEventArgs>> tuple = eventHandlers[num];
             if (tuple != null && tuple.Item2 != null)
             {
                 tuple.Item2.Invoke(eventHandlers[num].Item1, aVIMOnMembersChangedEventArgs);
             }
         }
     }
     return aVIMOnMembersChangedEventArgs;
 }