Пример #1
0
 public ContactViewModel(User user, ContactViewModel parent)
 {
     User = user;
     IsOnline = user.Online;
     Status = user.Online ? "Online" : "Offline";
     _parent = parent;
 }
Пример #2
0
 public IEnumerable<Message> GetConversation(User user, User contact)
 {
     var result = getConversation(_db, user, contact).ToList();
     result.ForEach(msg => msg.IsMine = (msg.From == user.Name));
     result.ForEach(msg => msg.Initiator = (msg.From == user.Name) ? user : contact);
     result.ForEach(msg => msg.Contact = (msg.To == user.Name) ? user : contact);
     return result;
 }
Пример #3
0
 public MockChatViewModel()
 {
     Contact = new User { Email = "*****@*****.**", Name = "user1", Online = true };
     Conversation = new ObservableCollection<Message>();
     Conversation.Add(new Message { Id = -1, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 1", From = "user", To = "user1", IsMine = true, Initiator = new User { Email = "*****@*****.**", Name = "user", Online = true }, Contact = new User { Email = "*****@*****.**", Name = "user1", Online = true } });
     Conversation.Add(new Message { Id = -2, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 2", From = "user1", To = "user", IsMine = false, Contact = new User { Email = "*****@*****.**", Name = "user", Online = true }, Initiator = new User { Email = "*****@*****.**", Name = "user1", Online = true } });
     Conversation.Add(new Message { Id = -3, DateReceived = DateTime.Now.AddMinutes(-2), Value = "Test Message 3", From = "user", To = "user1", IsMine = true, Initiator = new User { Email = "*****@*****.**", Name = "user", Online = true }, Contact = new User { Email = "*****@*****.**", Name = "user1", Online = true } });
 }
Пример #4
0
 public void LoadConversation(User contact, IEnumerable<Message> conversation)
 {
     ChatSessionViewModel chatSession;
     if(_chatSessions.TryGetValue(contact.Name, out chatSession))
     {
         var union = conversation.Union(chatSession.Conversation);
         chatSession.Conversation = new ObservableCollection<Message>(union);
     }
 }
Пример #5
0
 public ChatSessionViewModel StartNewSession(User contact, User initiator)
 {
     var viewModel = new ChatSessionViewModel(contact);
     viewModel.Initiator = initiator;
     viewModel.SendMessage += OnSendMessage;
     viewModel.ChatSessionClosed += OnChatSessionClosed;
     _chatSessions.Add(contact.Name, viewModel);
     return viewModel;
 }
Пример #6
0
 public void AddMessage(Message message, User initiator)
 {
     ChatSessionViewModel chatSession;
     if (!_chatSessions.TryGetValue(message.From, out chatSession))
     {
         chatSession = StartNewSession(message.Initiator, initiator);
         chatSession.OpenChat();
     }
     chatSession.MessageReceived(message);
 }
 public void StartNewSession(User user, User initiator)
 {
     var viewModel = new ChatSessionViewModel(user);
     viewModel.Initiator = initiator;
     viewModel.SendMessage += OnSendMessage;
     var chatView = new ChatViewDialog();
     chatView.BindViewModel(viewModel);
     chatView.Show();
     _chatSessions.Add(viewModel);
 }
Пример #8
0
 public void StartNewSession(User contact, User initiator)
 {
     var viewModel = new ChatSessionViewModel(contact);
     viewModel.Initiator = initiator;
     viewModel.SendMessage += OnSendMessage;
     var chatView = ServiceProvider.Instance.Get<IChatDialog>();
     chatView.BindViewModel(viewModel);
     chatView.Show();
     _chatSessions.Add(viewModel);
 }
 public void AddMessage(Message message, User initiator)
 {
     if (_chatSessions.SingleOrDefault(c => c.User.Name == message.From.Name) == null)
     {
         StartNewSession(message.From, initiator);
         _chatSessions.SingleOrDefault(c => c.User.Name == message.From.Name).MessageReceived(message);
     }
     else
     {
         _chatSessions.SingleOrDefault(c => c.User.Name == message.From.Name).MessageReceived(message);
     }
 }
Пример #10
0
 private void OnUserOffline(User user)
 {
     // Mark user as offline
 }
Пример #11
0
 public Task<IEnumerable<Message>> GetConversations(User user)
 {
     return _chat.Invoke<IEnumerable<Message>>("GetConversations", user);
 }
Пример #12
0
 public Task<IEnumerable<Message>> GetConversation(User user, User contact)
 {
     return _chat.Invoke<IEnumerable<Message>>("GetConversation", user, contact);
 }
Пример #13
0
 public IEnumerable<Message> GetConversations(User user)
 {
     var result = getConversations(_db, user).ToList();
     return result;
 }
Пример #14
0
 public ContactViewModel(User user)
 {
     User = user;
     IsOnline = user.Online;
     Status = user.Online ? "Online" : "Offline";
 }
Пример #15
0
        private void OnUserStatusChange(User user)
        {
            // Mark user as online/offline
            if (Contacts != null)
            {
                var contact = Contacts.FirstOrDefault(u => u.User.Name == user.Name);
                if (contact != null)
                {
                    // For the contact list to register that the contact has changed status,
                    // have to remove and re-add the contact again
                    Contacts.Remove(contact);
                }
                Contacts.Add(new ContactViewModel(user, Me));
            }

            if (Conversations != null)
            {
                var conversation = Conversations.FirstOrDefault(u => u.User.Name == user.Name);
                if (conversation != null)
                {
                    Conversations.Remove(conversation);
                    Conversations.Add(new ContactViewModel(user, conversation.Message, Me));
                }
            }
        }
Пример #16
0
 public OpenChatEventArgs(User contact)
 {
     Contact = contact;
 }
Пример #17
0
 public ChatSessionEventArgs(User user, Message message)
 {
     Contact = user;
     Message = message;
 }
Пример #18
0
 public IEnumerable<Message> GetConversation(User user, User contact)
 {
     return _db.GetConversation(user, contact);
 }
Пример #19
0
 public ChatSessionViewModel(User user)
 {
     Contact = user;
     Conversation = new ObservableCollection<Message>();
 }
Пример #20
0
 public IEnumerable<Message> GetConversations(User user)
 {
     var conversations = _db.GetConversations(user).ToList();
     conversations.ForEach(m => m.Contact = GetUser(m.To));
     return conversations;
 }
Пример #21
0
 private void OnUserOnline(User user)
 {
     // Mark user as online
 }
 private void OnUserStatusChange(User user)
 {
     //Mark user as online/offline
     if (Contacts != null)
     {
         var contact = Contacts.SingleOrDefault(u => u.User.Name == user.Name);
         if (contact != null)
         {
             Contacts.Remove(contact);
             Contacts.Add(new ContactViewModel(user, Me));
         }
     }
 }