new RosterItem(addedUser, RosterItem.SUB_BOTH, RosterItem.ASK_NONE, RosterItem.RECV_NONE, nickname, null); rosterItems.put(item.getJid().toBareJID(), item); newItem = true; } catch (UserNotFoundException ex) { item.setSubStatus(RosterItem.SUB_BOTH); for (Group group : groups) { if (rosterManager.isGroupVisible(group, getUserJID())) { item.addSharedGroup(group); item.addInvisibleSharedGroup(group); prevSubscription = item.getSubStatus(); item.setSubStatus(RosterItem.SUB_FROM); item.addSharedGroup(group); item.setSubStatus(RosterItem.SUB_TO); if (item.getSubStatus() == RosterItem.SUB_FROM) { item.addInvisibleSharedGroup(addedGroup); item.getSubStatus() == RosterItem.SUB_FROM) { item.setSubStatus(RosterItem.SUB_BOTH); } else if (prevSubscription == RosterItem.SUB_FROM && item.getSubStatus() == RosterItem.SUB_TO) {
if (item.isOnlyShared() && item.getSubStatus() == RosterItem.SUB_FROM) { continue; org.xmpp.packet.Roster.Ask ask = getAskStatus(item.getAskStatus()); org.xmpp.packet.Roster.Subscription sub = org.xmpp.packet.Roster.Subscription.valueOf(item.getSubStatus() .getName()); List<String> groups = new ArrayList<>(item.getGroups()); if (groups.contains(null)) { Log.warn("A group is null in roster item: " + item.getJid() + " of user: " + getUsername()); for (Group sharedGroup : item.getSharedGroups()) { String displayName = sharedGroup.getProperties().get("sharedRoster.displayName"); if (displayName != null) { if (item.getSubStatus() != RosterItem.SUB_NONE || item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE && !isSubscriptionRejected(item)) { roster.addItem(item.getJid(), item.getNickname(), ask, sub, groups);
if (implicitFrom.remove(item.getJid().toBareJID()) != null) { rosterItems.put(item.getJid().toBareJID(), item); if (rosterItems.putIfAbsent(item.getJid().toBareJID(), item) == null) { rosterItems.remove(item.getJid().toBareJID()); if (item.getSubStatus() != RosterItem.SUB_NONE) { throw new UserNotFoundException(item.getJid().toBareJID()); if (item.getID() == 0) { if (item.isShared()) { if (item.isOnlyShared()) { String defaultContactName; try { defaultContactName = UserNameManager.getUserName(item.getJid()); } catch (UserNotFoundException e) { defaultContactName = item.getNickname(); if (defaultContactName.equals(item.getNickname())) { return; if (item.getSubStatus() != RosterItem.SUB_NONE || item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE && !isSubscriptionRejected(item)) { broadcast(item, true);
/** * Returns true if roster item represents a rejected subscription request. * * @param item The roster item. * @return True, if the roster item represents a rejected subscription request. */ private static boolean isSubscriptionRejected(RosterItem item) { return item.getSubStatus() == RosterItem.SUB_NONE && item.getRecvStatus() == RosterItem.RECV_NONE && item.getAskStatus() == RosterItem.AskType.NONE; }
/** * Returns a roster item if the specified user has a subscription of type FROM to this * user and the susbcription only exists due to some shared groups or otherwise * <tt>null</tt>. This method assumes that this user does not have a subscription to * the contact. In other words, this method will not check if there should be a subscription * of type TO ot BOTH. * * @param user the contact to check if he is subscribed to the presence of this user. * @return a roster item if the specified user has a subscription of type FROM to this * user and the susbcription only exists due to some shared groups or otherwise null. */ private RosterItem getImplicitRosterItem(JID user) { Set<String> invisibleSharedGroups = implicitFrom.get(user.toBareJID()); if (invisibleSharedGroups != null) { RosterItem rosterItem = new RosterItem(user, RosterItem.SUB_FROM, RosterItem.ASK_NONE, RosterItem.RECV_NONE, "", null); rosterItem.setInvisibleSharedGroupsNames(invisibleSharedGroups); return rosterItem; } return null; }
/** * Create a roster item from the data in another one. * * @param item Item that contains the info of the roster item. */ public RosterItem(org.xmpp.packet.Roster.Item item) { this(item.getJID(), getSubType(item), getAskStatus(item), RosterItem.RECV_NONE, item.getName(), new LinkedList<>(item.getGroups())); }
if (group.isUser(item.getJid())) { item.addSharedGroup(group); item.setSubStatus(RosterItem.SUB_BOTH); rosterItems.put(item.getJid().toBareJID(), item); Collection<Group> itemGroups = new ArrayList<>(); String nickname = ""; RosterItem item = new RosterItem(jid, RosterItem.SUB_TO, RosterItem.ASK_NONE, RosterItem.RECV_NONE, nickname, null); item.addSharedGroup(group); itemGroups.add(group); } else { item.addInvisibleSharedGroup(group); item.setSubStatus(RosterItem.SUB_BOTH); } else { item.setSubStatus(RosterItem.SUB_FROM); if (item.getSubStatus() != RosterItem.SUB_FROM) { item.setNickname(UserNameManager.getUserName(jid)); rosterItems.put(item.getJid().toBareJID(), item); } else { .put(item.getJid().toBareJID(), item.getInvisibleSharedGroupsNames());
int groupSize = item.getSharedGroups().size() + item.getInvisibleSharedGroups().size(); if (item.isOnlyShared() && groupSize == 1) { if (!item.getSharedGroups().contains(sharedGroup) && !item.getInvisibleSharedGroups().contains(sharedGroup)) { return; } else { item.removeSharedGroup(sharedGroup); if (item.isOnlyShared()) { Collection<Group> userGroups = GroupManager.getInstance().getGroups(getUserJID()); Collection<Group> sharedGroups = new ArrayList<>(); sharedGroups.addAll(item.getSharedGroups()); if (rosterManager.hasMutualVisibility(getUsername(), userGroups, deletedUser, sharedGroups)) { item.setSubStatus(RosterItem.SUB_BOTH); } else if (item.getSharedGroups().isEmpty() && !item.getInvisibleSharedGroups().isEmpty()) { item.setSubStatus(RosterItem.SUB_FROM); } else { item.setSubStatus(RosterItem.SUB_TO);
@Override public RosterItem createItem(String username, RosterItem item) throws UserAlreadyExistsException { Connection con = null; PreparedStatement pstmt = null; try { long rosterID = SequenceManager.nextID(JiveConstants.ROSTER); con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(CREATE_ROSTER_ITEM); pstmt.setString(1, username); pstmt.setLong(2, rosterID); pstmt.setString(3, item.getJid().toBareJID()); pstmt.setInt(4, item.getSubStatus().getValue()); pstmt.setInt(5, item.getAskStatus().getValue()); pstmt.setInt(6, item.getRecvStatus().getValue()); pstmt.setString(7, item.getNickname()); pstmt.executeUpdate(); item.setID(rosterID); insertGroups(rosterID, item.getGroups().iterator(), con); } catch (SQLException e) { Log.warn("Error trying to insert a new row in ofRoster", e); throw new UserAlreadyExistsException(item.getJid().toBareJID()); } finally { DbConnectionManager.closeConnection(pstmt, con); } return item; }
/** * Determine and call the update method based on the item's subscription state. * <p/> * * @param item The item to be updated * @param action The new state change request * @param isSending True if the roster owner of the item is sending the new state change request */ private static void updateState(RosterItem item, Presence.Type action, boolean isSending) { Change change = getStateChange(item.getSubStatus(), action, isSending); if (change.getNewAsk() != null && change.getNewAsk() != item.getAskStatus()) { item.setAskStatus(change.getNewAsk()); } if (change.getNewSub() != null && change.getNewSub() != item.getSubStatus()) { item.setSubStatus(change.getNewSub()); } if (change.getNewRecv() != null && change.getNewRecv() != item.getRecvStatus()) { item.setRecvStatus(change.getNewRecv()); } }
@Override public void updateItem(String username, RosterItem item) { Connection con = null; PreparedStatement pstmt = null; long rosterID = item.getID(); try { con = DbConnectionManager.getConnection(); // Update existing roster item pstmt = con.prepareStatement(UPDATE_ROSTER_ITEM); pstmt.setInt(1, item.getSubStatus().getValue()); pstmt.setInt(2, item.getAskStatus().getValue()); pstmt.setInt(3, item.getRecvStatus().getValue()); pstmt.setString(4, item.getNickname()); pstmt.setLong(5, rosterID); pstmt.executeUpdate(); // Close now the statement (do not wait to be GC'ed) DbConnectionManager.fastcloseStmt(pstmt); // Delete old group list pstmt = con.prepareStatement(DELETE_ROSTER_ITEM_GROUPS); pstmt.setLong(1, rosterID); pstmt.executeUpdate(); insertGroups(rosterID, item.getGroups().iterator(), con); } catch (SQLException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } finally { DbConnectionManager.closeConnection(pstmt, con); } }
if (doChecking && itemToRemove != null && !itemToRemove.getSharedGroups().isEmpty()) { throw new SharedGroupException("Cannot remove contact that belongs to a shared group"); RosterItem.SubType subType = itemToRemove.getSubStatus(); Presence presence = new Presence(); presence.setFrom(XMPPServer.getInstance().createJID(username, null)); presence.setTo(itemToRemove.getJid()); presence.setType(Presence.Type.unsubscribe); XMPPServer.getInstance().getPacketRouter().route(presence); Presence presence = new Presence(); presence.setFrom(XMPPServer.getInstance().createJID(username, null)); presence.setTo(itemToRemove.getJid()); presence.setType(Presence.Type.unsubscribed); XMPPServer.getInstance().getPacketRouter().route(presence); if (item.getID() > 0) { RosterManager.getRosterItemProvider().deleteItem(username, item.getID());
@Override public void run() { // Send the last published items for the contacts on availableSessionJID's roster. try { final XMPPServer server = XMPPServer.getInstance(); final Roster roster = server.getRosterManager().getRoster(availableSessionJID.getNode()); for (final RosterItem item : roster.getRosterItems()) { if (server.isLocal(item.getJid()) && (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO)) { PEPService pepService = pepServiceManager.getPEPService(item.getJid().toBareJID()); if (pepService != null) { pepService.sendLastPublishedItems(availableSessionJID); } } } } catch (UserNotFoundException e) { // Do nothing } } }
Roster roster = rosterManager.getRoster(username); for (RosterItem item : roster.getRosterItems()) { if (item.getRecvStatus() == RosterItem.RECV_SUBSCRIBE) { session.process(createSubscribePresence(item.getJid(), session.getAddress().asBareJID(), true)); } else if (item.getRecvStatus() == RosterItem.RECV_UNSUBSCRIBE) { session.process(createSubscribePresence(item.getJid(), session.getAddress().asBareJID(), false)); if (item.getSubStatus() == RosterItem.SUB_TO || item.getSubStatus() == RosterItem.SUB_BOTH) { presenceManager.probePresence(session.getAddress(), item.getJid());
while (rs.next()) { RosterItem item = new RosterItem(rs.getLong(2), new JID(rs.getString(1)), RosterItem.SubType.getTypeFromInt(rs.getInt(3)), itemsByID.put(item.getID(), item); rs = pstmt.executeQuery(); while (rs.next()) { itemsByID.get(rs.getLong(1)).getGroups().add(rs.getString(2));
contactGroups = item.getGroups(); contactSubscription = item.getSubStatus();
@Override public void contactDeleted(Roster roster, RosterItem item) { JID rosterOwner = XMPPServer.getInstance().createJID(roster.getUsername(), null); JID deletedContact = item.getJid(); cancelSubscriptionToPEPService(deletedContact, rosterOwner); }
org.xmpp.packet.Roster.Subscription.none, groups); RosterItem rosterItem = new RosterItem(item);
if (group.isUser(item.getJid())) { item.addSharedGroup(group); item.setSubStatus(RosterItem.SUB_BOTH); rosterItems.put(item.getJid().toBareJID(), item); Collection<Group> itemGroups = new ArrayList<>(); String nickname = ""; RosterItem item = new RosterItem(jid, RosterItem.SUB_TO, RosterItem.ASK_NONE, RosterItem.RECV_NONE, nickname, null); item.addSharedGroup(group); itemGroups.add(group); } else { item.addInvisibleSharedGroup(group); item.setSubStatus(RosterItem.SUB_BOTH); } else { item.setSubStatus(RosterItem.SUB_FROM); if (item.getSubStatus() != RosterItem.SUB_FROM) { item.setNickname(UserNameManager.getUserName(jid)); rosterItems.put(item.getJid().toBareJID(), item); } else { .put(item.getJid().toBareJID(), item.getInvisibleSharedGroupsNames());
int groupSize = item.getSharedGroups().size() + item.getInvisibleSharedGroups().size(); if (item.isOnlyShared() && groupSize == 1 && item.removeSharedGroup(deletedGroup); if (!rosterManager.isGroupVisible(group, getUserJID())) { item.removeSharedGroup(group); if (item.isOnlyShared()) { Collection<Group> userGroups = GroupManager.getInstance().getGroups(getUserJID()); item.setSubStatus(RosterItem.SUB_BOTH); } else { item.setSubStatus(RosterItem.SUB_FROM); item.setSubStatus(RosterItem.SUB_TO);