private void notifyFriendsLoggedIn(User user) { User[] friends = userRepository.getFriends(user); Console.WriteLine("notify logged friends " + friends.Count()); foreach (User us in friends) { if (loggedClients.ContainsKey(us.Id)) { IChatObserver chatClient = loggedClients[us.Id]; chatClient.friendLoggedIn(user); } } }
private void notifyFriendsLoggedIn(User user) { IEnumerable <User> friends = userRepository.getFriendsOf(user); Console.WriteLine("notify logged friends " + friends.Count()); foreach (User us in friends) { if (loggedClients.ContainsKey(us.Id)) { IChatObserver chatClient = loggedClients[us.Id]; Task.Run(() => chatClient.friendLoggedIn(user)); } } }
private void handleUpdate(UpdateResponse update) { if (update is FriendLoggedInResponse) { FriendLoggedInResponse frUpd = (FriendLoggedInResponse)update; User friend = DTOUtils.getFromDTO(frUpd.Friend); Console.WriteLine("Friend logged in " + friend); try { client.friendLoggedIn(friend); } catch (ChatException e) { Console.WriteLine(e.StackTrace); } } if (update is FriendLoggedOutResponse) { FriendLoggedOutResponse frOutRes = (FriendLoggedOutResponse)update; User friend = DTOUtils.getFromDTO(frOutRes.Friend); Console.WriteLine("Friend logged out " + friend); try { client.friendLoggedOut(friend); } catch (ChatException e) { Console.WriteLine(e.StackTrace); } } if (update is NewMessageResponse) { NewMessageResponse msgRes = (NewMessageResponse)update; Message message = DTOUtils.getFromDTO(msgRes.Message); try { client.messageReceived(message); } catch (ChatException e) { Console.WriteLine(e.StackTrace); } } }