Esempio n. 1
0
  private void removeSharedGroupFromRoster(Group group, String username) {
    // Get the group users to remove from the user's roster
    Collection<String> users = new HashSet<String>(group.getMembers());
    users.addAll(group.getAdmins());

    // Get the roster of the user from which we need to remove the shared group users
    Roster userRoster = (Roster) CacheManager.getCache("username2roster").get(username);

    // Iterate on all the group users and update their rosters
    for (String userToRemove : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToRemove);
      // Only update rosters in memory
      if (roster != null) {
        roster.deleteSharedUser(group, username);
      }
      // Update the roster of the user
      if (userRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToRemove);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          userRoster.deleteSharedUser(userToRemove, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }
  @Override
  public void disconnected(boolean onError) {
    final XMPPConnection connection = myFacade.getConnection();

    LOG.info("Jabber disconnected: " + connection.getUser());
    connection.removePacketListener(mySubscribeListener);
    mySubscribeListener = null;
    connection.removePacketListener(myMessageListener);
    myMessageListener = null;

    final Roster roster = connection.getRoster();
    if (roster != null) {
      roster.removeRosterListener(myRosterListener);
    }
    myRosterListener = null;

    myIDEtalkUsers.clear();
    myUser2Presence.clear();
    myUser2Thread.clear();

    if (onError && reconnectEnabledAndNotStarted()) {
      LOG.warn(getMsg("jabber.server.was.disconnected", myReconnectTimeout / 1000));
      myReconnectProcess = myIdeFacade.runOnPooledThread(new MyReconnectRunnable());
    }
  }
Esempio n. 3
0
  /**
   * Notification that a Group user has been added. Update the group users' roster accordingly.
   *
   * @param group the group where the user was added.
   * @param addedUser the username of the user that has been added to the group.
   */
  private void groupUserAdded(Group group, String addedUser) {
    // Get all the affected users
    Collection<String> users = getAffectedUsers(group);
    // Get the roster of the added user.
    Roster addedUserRoster = (Roster) CacheManager.getCache("username2roster").get(addedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      if (!addedUser.equals(userToUpdate)) {
        // Get the roster to update
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
        // Only update rosters in memory
        if (roster != null) {
          roster.addSharedUser(group, addedUser);
        }
        // Update the roster of the newly added group user.
        if (addedUserRoster != null) {
          try {
            User user = UserManager.getInstance().getUser(userToUpdate);
            Collection<Group> groups = GroupManager.getInstance().getGroups(user);
            addedUserRoster.addSharedUser(userToUpdate, groups, group);
          } catch (UserNotFoundException e) {
          }
        }
      }
    }
  }
    /**
     * <code>receivedPacket</code> of PacketListener handler, this filters for jabber:iq:auth
     * extensions, then broadcasts those events on a special RosterListener interface.
     *
     * @param p incoming <code>PacketEvent</code>
     */
    public void receivedPacket(PacketEvent p) {
      if (!(p.getPacket() instanceof InfoQuery)) return;
      Enumeration e = ((InfoQuery) p.getPacket()).Extensions();
      Extension ext;
      if ((e == null) || (!e.hasMoreElements())) return;

      ext = (Extension) e.nextElement();

      if (!(ext instanceof Roster)) return;

      // TODO: add code to modify current roster image based on
      // new data. Replacement is basically shown by if the type is not
      // 'result' of the IQ
      Roster rext = (Roster) ext;

      if (((InfoQuery) p.getPacket()).getType().equals("result")) {
        // the results of a get will be the results of a full fetch
        Enumeration enumx = rext.items();
        currentRoster.clear();
        while (enumx.hasMoreElements()) {
          RosterItem ri = (RosterItem) enumx.nextElement();
          currentRoster.put(ri.getJID(), ri);
        }
        fireUserRosterReplaced(rext);
      } else {
        Enumeration enumx = rext.items();
        while (enumx.hasMoreElements()) {
          RosterItem ri = (RosterItem) enumx.nextElement();
          currentRoster.put(ri.getJID(), ri);
        }

        fireUserRosterChanged(rext);
      }
    }
Esempio n. 5
0
    @Override
    public void actionPerformed(ActionEvent evt) {
      if (pluginModel.isDownloadingList()) return;

      boolean downloadSource = jEdit.getBooleanProperty("plugin-manager.downloadSource");
      boolean installUser = jEdit.getBooleanProperty("plugin-manager.installUser");
      Roster roster = new Roster();
      String installDirectory;
      if (installUser) {
        installDirectory = MiscUtilities.constructPath(jEdit.getSettingsDirectory(), "jars");
      } else {
        installDirectory = MiscUtilities.constructPath(jEdit.getJEditHome(), "jars");
      }

      int length = pluginModel.entries.size();
      int instcount = 0;
      for (int i = 0; i < length; i++) {
        Entry entry = (Entry) pluginModel.entries.get(i);
        if (entry.install) {
          entry.plugin.install(roster, installDirectory, downloadSource);
          if (updates)
            entry
                .plugin
                .getCompatibleBranch()
                .satisfyDependencies(roster, installDirectory, downloadSource);
          instcount++;
        }
      }

      if (roster.isEmpty()) return;

      boolean cancel = false;
      if (updates && roster.getOperationCount() > instcount)
        if (GUIUtilities.confirm(
                window,
                "install-plugins.depend",
                null,
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE)
            == JOptionPane.CANCEL_OPTION) cancel = true;

      if (!cancel) {
        new PluginManagerProgress(window, roster);

        roster.performOperationsInAWTThread(window);
        pluginModel.update();
      }
    }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdOk) {
      String jid = getString(tJid);
      if (jid != null) {
        String name = getString(tNick);
        String group = group(tGrpList.getSelectedIndex());
        if (group == null) group = getString(tGroup);

        try {
          int gSel = tGrpList.getSelectedIndex();
          if (gSel != tGrpList.size() - 1) {
            group = (gSel > 0) ? tGrpList.getString(gSel) : null; // nokia fix
          }
        } catch (Exception e) {
        } // nokia fix

        // сохранение контакта
        boolean ask[] = new boolean[1];
        tAskSubscrCheckBox.getSelectedFlags(ask);
        roster.storeContact(jid, name, group, ask[0]);
        destroyView();
        return;
      }
    }

    if (c == cmdCancel) destroyView();
  }
Esempio n. 7
0
  Collection<String> getSharedUsersForRoster(Group group, Roster roster) {
    String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
    String groupNames = group.getProperties().get("sharedRoster.groupList");

    // Answer an empty collection if the group is not being shown in users' rosters
    if (!"onlyGroup".equals(showInRoster) && !"everybody".equals(showInRoster)) {
      return new ArrayList<String>();
    }

    // Add the users of the group
    Collection<String> users = new HashSet<String>(group.getMembers());
    users.addAll(group.getAdmins());

    // Check if anyone can see this shared group
    if ("everybody".equals(showInRoster)) {
      // If the user of the roster belongs to the public group then we should return all users
      // in the system since they all need to be in the roster with subscription "from"
      if (group.isUser(roster.getUsername())) {
        // Add all users in the system
        for (User user : UserManager.getInstance().getUsers()) {
          users.add(user.getUsername());
        }
      }
    } else {
      // Add the users that may see the group
      Collection<Group> groupList = parseGroups(groupNames);
      for (Group groupInList : groupList) {
        users.addAll(groupInList.getMembers());
        users.addAll(groupInList.getAdmins());
      }
    }
    return users;
  }
Esempio n. 8
0
  /**
   * Removes the entire roster of a given user. This is necessary when a user account is being
   * deleted from the server.
   *
   * @param user the user.
   */
  public void deleteRoster(JID user) {
    try {
      String username = user.getNode();
      // Get the roster of the deleted user
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(username);
      if (roster == null) {
        // Not in cache so load a new one:
        roster = new Roster(username);
      }
      // Remove each roster item from the user's roster
      for (RosterItem item : roster.getRosterItems()) {
        try {
          roster.deleteRosterItem(item.getJid(), false);
        } catch (SharedGroupException e) {
          // Do nothing. We shouldn't have this exception since we disabled the checkings
        }
      }
      // Remove the cached roster from memory
      CacheManager.getCache("username2roster").remove(username);

      // Get the rosters that have a reference to the deleted user
      RosterItemProvider rosteItemProvider = RosterItemProvider.getInstance();
      Iterator<String> usernames = rosteItemProvider.getUsernames(user.toBareJID());
      while (usernames.hasNext()) {
        username = usernames.next();
        // Get the roster that has a reference to the deleted user
        roster = (Roster) CacheManager.getCache("username2roster").get(username);
        if (roster == null) {
          // Not in cache so load a new one:
          roster = new Roster(username);
        }
        // Remove the deleted user reference from this roster
        try {
          roster.deleteRosterItem(user, false);
        } catch (SharedGroupException e) {
          // Do nothing. We shouldn't have this exception since we disabled the checkings
        }
      }
    } catch (UnsupportedOperationException e) {
      // Do nothing
    }
  }
Esempio n. 9
0
 /**
  * Returns an unmodifiable collection of the roster groups that this entry belongs to.
  *
  * @return an iterator for the groups this entry belongs to.
  */
 public Collection<RosterGroup> getGroups() {
   List<RosterGroup> results = new ArrayList<RosterGroup>();
   // Loop through all roster groups and find the ones that contain this
   // entry. This algorithm should be fine
   for (RosterGroup group : roster.getGroups()) {
     if (group.contains(this)) {
       results.add(group);
     }
   }
   return Collections.unmodifiableCollection(results);
 }
Esempio n. 10
0
  /**
   * Notification that a Group user has been deleted. Update the group users' roster accordingly.
   *
   * @param group the group from where the user was deleted.
   * @param users the users to update their rosters
   * @param deletedUser the username of the user that has been deleted from the group.
   */
  private void groupUserDeleted(Group group, Collection<String> users, String deletedUser) {
    // Get the roster of the deleted user.
    Roster deletedUserRoster = (Roster) CacheManager.getCache("username2roster").get(deletedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
      // Only update rosters in memory
      if (roster != null) {
        roster.deleteSharedUser(group, deletedUser);
      }
      // Update the roster of the newly deleted group user.
      if (deletedUserRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToUpdate);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          deletedUserRoster.deleteSharedUser(userToUpdate, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }
  public JabberTransport(
      JabberUI UI,
      JabberFacade facade,
      UserModel userModel,
      AsyncMessageDispatcher messageDispatcher,
      JabberUserFinder userFinder) {
    Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);

    // XMPPConnection.DEBUG_ENABLED = true;
    JDOMExtension.init();

    myUI = UI;
    myFacade = facade;
    myUserModel = userModel;
    myDispatcher = messageDispatcher;
    myUserFinder = userFinder;
    myIdeFacade = messageDispatcher.getIdeFacade();
    myIgnoreList = new IgnoreList(myIdeFacade);

    myFacade.addConnectionListener(this);
    getBroadcaster().addListener(myUserModelListener);
  }
Esempio n. 12
0
 /** 登陆XMPP服务器 */
 public boolean login() throws RemoteException {
   // 未建立XMPP连接
   if (!connection.isConnected()) {
     return false;
   }
   // 应经登陆过
   if (connection.isAuthenticated()) {
     return true;
   } else {
     // 开始登陆
     try {
       connection.login(account, password, imService.getString(R.string.app_name));
       if (messageListener == null) {
         messageListener = new MessageListener();
       }
       // 添加消息监听器
       connection.addPacketListener(messageListener, new PacketTypeFilter(Message.class));
       Roster roster = connection.getRoster();
       if (rosterListener == null) {
         rosterListener = new IMClientRosterListener();
       }
       // 添加花名册监听器
       roster.addRosterListener(rosterListener);
       // 获取花名册
       if (roster != null && roster.getEntries().size() > 0) {
         Uri uri = null;
         for (RosterEntry entry : roster.getEntries()) {
           // 获取联系人名片信息
           VCard vCard = new VCard();
           vCard.load(connection, entry.getUser());
           // 用户名称
           String userName = StringUtils.parseName(entry.getUser());
           // 用户备注
           String remarks = entry.getName();
           // 通讯录的名称
           String name = "";
           // 名称与备注判断
           if (userName.equals(remarks) && vCard != null) {
             // 使用联系人的昵称
             name = vCard.getNickName();
           } else {
             // 使用备注
             name = remarks;
           }
           if (vCard != null) {
             IM.saveAvatar(vCard.getAvatar(), StringUtils.parseName(entry.getUser()));
           }
           ContentValues values = new ContentValues();
           values.put(ContactsProvider.ContactColumns.ACCOUNT, entry.getUser());
           values.put(ContactsProvider.ContactColumns.NAME, name);
           String sortStr = PinYin.getPinYin(name);
           values.put(ContactsProvider.ContactColumns.SORT, sortStr);
           values.put(
               ContactsProvider.ContactColumns.SECTION,
               sortStr.substring(0, 1).toUpperCase(Locale.ENGLISH));
           // 储存联系人
           if (imService
                   .getContentResolver()
                   .update(
                       ContactsProvider.CONTACT_URI,
                       values,
                       ContactsProvider.ContactColumns.ACCOUNT + " = ?",
                       new String[] {entry.getUser()})
               == 0) {
             uri = imService.getContentResolver().insert(ContactsProvider.CONTACT_URI, values);
           }
         }
         // 发生改变,通知刷新
         if (uri != null) {
           imService.getContentResolver().notifyChange(uri, null);
         }
       }
     } catch (XMPPException e) {
       e.printStackTrace();
     } catch (SmackException e) {
       e.printStackTrace();
     } catch (IOException e) {
       e.printStackTrace();
     }
     return true;
   }
 }
Esempio n. 13
0
  public void groupModified(Group group, Map params) {
    // Do nothing if no group property has been modified
    if (!"propertyModified".equals(params.get("type"))) {
      return;
    }
    String keyChanged = (String) params.get("propertyKey");
    String originalValue = (String) params.get("originalValue");

    if ("sharedRoster.showInRoster".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.showInRoster");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Get the users of the group
      Collection<String> users = new HashSet<String>(group.getMembers());
      users.addAll(group.getAdmins());
      // Get the users whose roster will be affected
      Collection<String> affectedUsers =
          getAffectedUsers(
              group, originalValue, group.getProperties().get("sharedRoster.groupList"));
      // Remove the group members from the affected rosters
      for (String deletedUser : users) {
        groupUserDeleted(group, affectedUsers, deletedUser);
      }

      // Simulate that the group users has been added to the group. This will cause to push
      // roster items to the "affected" users for the group users
      // Collection<Group> visibleGroups = getVisibleGroups(group);
      for (String user : users) {
        groupUserAdded(group, user);
        /*for (Group visibleGroup : visibleGroups) {
            addSharedGroupToRoster(visibleGroup, user);
        }*/
      }
    } else if ("sharedRoster.groupList".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.groupList");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Get the users of the group
      Collection<String> users = new HashSet<String>(group.getMembers());
      users.addAll(group.getAdmins());
      // Get the users whose roster will be affected
      Collection<String> affectedUsers =
          getAffectedUsers(
              group, group.getProperties().get("sharedRoster.showInRoster"), originalValue);
      // Remove the group members from the affected rosters
      for (String deletedUser : users) {
        groupUserDeleted(group, affectedUsers, deletedUser);
      }

      // Simulate that the group users has been added to the group. This will cause to push
      // roster items to the "affected" users for the group users
      // Collection<Group> visibleGroups = getVisibleGroups(group);
      for (String user : users) {
        groupUserAdded(group, user);
        /*for (Group visibleGroup : visibleGroups) {
            addSharedGroupToRoster(visibleGroup, user);
        }*/
      }
    } else if ("sharedRoster.displayName".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.displayName");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Do nothing if the group is not being shown in users' rosters
      if (!isSharedGroup(group)) {
        return;
      }
      // Get all the affected users
      Collection<String> users = getAffectedUsers(group);
      // Iterate on all the affected users and update their rosters
      for (String updatedUser : users) {
        // Get the roster to update.
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(updatedUser);
        if (roster != null) {
          // Update the roster with the new group display name
          roster.shareGroupRenamed(users);
        }
      }
    }
  }