private void handleMessageFromServer(ClientMessage message) {
    switch (message.getMessageType()) {
    case CONVERSATION:
      ClientConversationMessage conversationMessage = (ClientConversationMessage) message;
      if (messageListener != null) {
        messageListener.displayMessage(conversationMessage.getSourceUser(), conversationMessage.getMessageToSend());
      }
      break;
    case LOGIN_RESPONSE:
      LoginResponseMessage loginResponse = (LoginResponseMessage) message;
      handleLoginResponse(loginResponse);
      break;
    case REGISTER_RESPONSE:
      RegisterResponseMessage registerResponse = (RegisterResponseMessage) message;
      handleRegisterResponse(registerResponse);
      break;
    case USER_CAME_ONLINE:
      UserCameOnlineMessage userCameOnlineMessage = (UserCameOnlineMessage) message;
      if (friendsManagerListener != null) {
        Friend friend = loggedInUser.getFriendByUsername(userCameOnlineMessage.getUsername());
        friend.setIsOnline(true);
        friendsManagerListener.userCameOnline(userCameOnlineMessage.getUsername());
      }
      break;
    case USER_WENT_OFFLINE:
      UserWentOfflineMessage userWentOfflineMessage = (UserWentOfflineMessage) message;
      if (friendsManagerListener != null) {
        Friend friend = loggedInUser.getFriendByUsername(userWentOfflineMessage.getUsername());
        friend.setIsOnline(false);
        friendsManagerListener.userWentOffline(userWentOfflineMessage.getUsername());
      }
      break;
    case FRIEND_REQUEST:
      FriendRequestMessage friendRequestMessage = (FriendRequestMessage) message;
      if (friendRequestListener != null) {
        friendRequestListener.newFriendRequest(friendRequestMessage.getFriendRequst());
      }
      break;
    case ADD_FRIEND_RESPONSE:
      AddFriendResponseMessage addFriendResponse = (AddFriendResponseMessage) message;
      if (friendRequestListener != null) {
        if (addFriendResponse.isSuccessful()) {
          friendRequestListener.requestSentSuccessful(addFriendResponse.getMessage());
        }
        else {
          friendRequestListener.requestSentFailed(addFriendResponse.getMessage());
        }
      }
      break;
    case NEW_FRIEND:
      NewFriendMessage newFriendMessage = (NewFriendMessage) message;
      loggedInUser.addFriend(newFriendMessage.getFriend());
      if (friendsManagerListener != null) {
        friendsManagerListener.newFriendAdded(newFriendMessage.getFriend());
      }
      break;
    case SERVER_STOPPED:
      if (serverMessageListener != null) {
        serverMessageListener.ServerStopped();
      }
      break;
    default: // do nothing
    }
  }