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