コード例 #1
0
        private void ContactAction(string login)
        {
            if (!ConversationWindows.Any(cmv => cmv.Recipeint == login))
            {
                var conversationWindow    = new ConversationWindow();
                var conversationViewModel = new ConversationViewModel(_logicClient);
                conversationViewModel.OnRequestClose += (s, ee) =>
                {
                    conversationWindow.Close();
                    DeleteFromConversationList(conversationViewModel.Recipeint);
                };
                conversationViewModel.Initialize(login);
                conversationWindow.DataContext = conversationViewModel;
                conversationWindow.Show();

                ConversationWindows.Add(conversationViewModel);
            }
        }
コード例 #2
0
        public void ProceedCommand(object sender, RepeaterEventArgs e)
        {
            if (e.Type == ActionTypes.ContactList)
            {
                if (e.Result)
                {
                    var users = (List <User>)e.Data;

                    DispatchService.Invoke(() =>
                    {
                        Contacts.Clear();
                        users.ForEach(u =>
                        {
                            var contactViewModel =
                                new ContactViewModel(new ContactModel
                            {
                                Login          = u.Login,
                                Status         = u.Status,
                                StatusImageUri = getStatusImage(u.Status)
                            });
                            Contacts.Add(contactViewModel);
                        });
                    });
                }
            }
            else if (e.Type == ActionTypes.Message)
            {
                if (e.Result)
                {
                    var messageReq = (MessageReq)e.Data;
                    if (!ConversationWindows.Any(cmv => cmv.Recipeint == messageReq.Login))
                    {
                        DispatchService.Invoke(() =>
                        {
                            var conversationWindow                = new ConversationWindow();
                            var conversationViewModel             = new ConversationViewModel(_logicClient);
                            conversationViewModel.OnRequestClose += (s, ee) =>
                            {
                                conversationWindow.Close();
                                DeleteFromConversationList(conversationViewModel.Recipeint);
                            };

                            var messageModel = new MessageModel
                            {
                                DateTimeDelivery = messageReq.SendTime.ToString("yy-MM-dd hh:dd"),
                                Message          = messageReq.Message,
                                Sender           = messageReq.Login,
                                Image            = GetImageFromAttach(messageReq.Attachment)
                            };
                            conversationViewModel.Initialize(messageReq.Login);
                            conversationViewModel.AddMessage(messageModel);
                            conversationWindow.DataContext = conversationViewModel;
                            conversationWindow.Show();

                            ConversationWindows.Add(conversationViewModel);
                        });
                    }
                }
            }
            else if (e.Type == ActionTypes.PresenceNotification)
            {
                var presenceNotification = (PresenceStatusNotification)e.Data;

                ContactViewModel contact = Contacts.SingleOrDefault(c => c.Login == presenceNotification.Login);
                if (contact != null)
                {
                    contact.Status         = presenceNotification.PresenceStatus;
                    contact.StatusImageUri = getStatusImage(presenceNotification.PresenceStatus);
                }
            }
        }