Exemplo n.º 1
0
 public ContactViewModel(User user, ContactViewModel parent)
 {
     User = user;
     IsOnline = user.Online;
     Status = user.Online ? "Online" : "Offline";
     _parent = parent;
 }
Exemplo n.º 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;
 }
Exemplo n.º 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 } });
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 10
0
 private void OnUserOffline(User user)
 {
     // Mark user as offline
 }
Exemplo n.º 11
0
 public Task<IEnumerable<Message>> GetConversations(User user)
 {
     return _chat.Invoke<IEnumerable<Message>>("GetConversations", user);
 }
Exemplo n.º 12
0
 public Task<IEnumerable<Message>> GetConversation(User user, User contact)
 {
     return _chat.Invoke<IEnumerable<Message>>("GetConversation", user, contact);
 }
Exemplo n.º 13
0
 public IEnumerable<Message> GetConversations(User user)
 {
     var result = getConversations(_db, user).ToList();
     return result;
 }
Exemplo n.º 14
0
 public ContactViewModel(User user)
 {
     User = user;
     IsOnline = user.Online;
     Status = user.Online ? "Online" : "Offline";
 }
Exemplo n.º 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));
                }
            }
        }
Exemplo n.º 16
0
 public OpenChatEventArgs(User contact)
 {
     Contact = contact;
 }
Exemplo n.º 17
0
 public ChatSessionEventArgs(User user, Message message)
 {
     Contact = user;
     Message = message;
 }
Exemplo n.º 18
0
 public IEnumerable<Message> GetConversation(User user, User contact)
 {
     return _db.GetConversation(user, contact);
 }
Exemplo n.º 19
0
 public ChatSessionViewModel(User user)
 {
     Contact = user;
     Conversation = new ObservableCollection<Message>();
 }
Exemplo n.º 20
0
 public IEnumerable<Message> GetConversations(User user)
 {
     var conversations = _db.GetConversations(user).ToList();
     conversations.ForEach(m => m.Contact = GetUser(m.To));
     return conversations;
 }
Exemplo n.º 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));
         }
     }
 }