public void sentAdvertise(Advertise advertise) {
   Iterator it = connectedUsers.keySet().iterator();
   while (it.hasNext()) {
     try {
       Object object = it.next();
       ClientInterface client = connectedUsers.get(object);
       client.receiveAdvertis(advertise);
     } catch (RemoteException ex) {
       Logger.getLogger(ServerImplementation.class.getName()).log(Level.SEVERE, null, ex);
     }
   }
 }
  @Override
  public boolean addContact(int user_Id, String eMail) throws RemoteException {
    boolean done = dataBaseOpeartions.addList(user_Id, eMail);

    User user = dataBaseOpeartions.getUser(eMail);
    User user1 = dataBaseOpeartions.getUser(user_Id);

    ClientInterface ci = connectedUsers.get(user.getId());

    ClientInterface me = connectedUsers.get(user_Id);
    if (connectedUsers.containsKey(user.getId()))
      ci.userNotificationadd(user1, me, user1.getStatus());
    if (connectedUsers.containsKey(user_Id)) me.userNotificationadd(user, ci, user.getStatus());

    return done;
  }
  @Override
  public FirstConnect login(String eMail, String passWord, ClientInterface client)
      throws RemoteException {

    User user = dataBaseOpeartions.checkUser(eMail, passWord);

    FirstConnect firstConnect = new FirstConnect();
    if (user != null) {
      try {
        if (!users.contains(user)) users.add(user);
        dataBaseOpeartions.changeStatues(user.getId(), "online");
        user.setStatus("online");
        connectedUsers.put(user.getId(), client);
        ArrayList<User> myFreiends = getContacts(user.getId());
        HashMap<Integer, ClientInterface> myOnlineUser = new HashMap<>();
        for (User user1 : myFreiends) {

          if (connectedUsers.containsKey(user1.getId())) {
            myOnlineUser.put(user1.getId(), connectedUsers.get(user1.getId()));
          }
        }

        Iterator onlineuser = myOnlineUser.keySet().iterator();
        while (onlineuser.hasNext()) {
          Object object = onlineuser.next();
          ClientInterface clients = myOnlineUser.get(object);
          clients.userNotification(
              user.id, client, user.getStatus()); // get online statues away buzy
        }

        firstConnect.setRequestses(dataBaseOpeartions.getfrFriendRequestses(user.id));
        firstConnect.userConnected = myOnlineUser;
        firstConnect.myUser = myFreiends;
        firstConnect.user = user;
        firstConnect.advertise = controller.advertise;
        firstConnect.messages = dataBaseOpeartions.getOfflineMessage(user.id);
      } catch (SQLException ex) {
        Logger.getLogger(ServerImplementation.class.getName()).log(Level.SEVERE, null, ex);
      }

    } else {
      return null;
    }

    //  JOptionPane.showMessageDialog(null, "abdo");
    return firstConnect;
  }
  @Override
  public void changeOnlineStatus(int id, int status) throws RemoteException {
    dataBaseOpeartions.changeonlineStatues(id, status);

    ArrayList<User> myFreiends = getContacts(id);
    HashMap<Integer, ClientInterface> myOnlineUser = new HashMap<>();

    for (User user1 : myFreiends) {

      if (connectedUsers.containsKey(user1.getId())) {
        myOnlineUser.put(user1.getId(), connectedUsers.get(user1.getId()));
      }
    }

    Iterator onlineuser = myOnlineUser.keySet().iterator();
    while (onlineuser.hasNext()) {
      Object object = onlineuser.next();
      ClientInterface clients = myOnlineUser.get(object);
      clients.userNotificationstatues(id, status);
    }
  }
  @Override
  public boolean checkAddContact(int user_Id, String eMail) throws RemoteException {

    User user = dataBaseOpeartions.getUser(eMail);
    User user1 = dataBaseOpeartions.getUser(user_Id);

    if (user != null) {
      if (connectedUsers.containsKey(user.getId())) {
        System.out.println("abdosooasosoos");
        ClientInterface ci = connectedUsers.get(user.getId());
        ci.acceptFriend(user1.getfName(), user1.getEmail());
        return true;

      } else {
        System.out.println("abdo offline");
        dataBaseOpeartions.addRequestFriend(user.getId(), user1.getfName(), user1.getEmail());
        return true;
      }
    } else {
      return false;
    }
  }
 @Override
 public void leaveGroupt(int me, int userid, int chatgroupid) throws RemoteException {
   ClientInterface ci = connectedUsers.get(userid);
   ci.leaveGroupt(me, chatgroupid);
 }
 @Override
 public void receivechatfromGroupingChatt(int id, int groupid, String message)
     throws RemoteException {
   ClientInterface ci = connectedUsers.get(id);
   ci.recivegroupChatFromServer(groupid, message);
 }