/** * Adds a roster entry to the packet. * * @param rosterEntry a roster entry to add. */ public void addRosterEntry(RosterEntry rosterEntry) { // Obtain a String[] from the roster entry groups name List<String> groupNamesList = new ArrayList<String>(); String[] groupNames; for (RosterGroup group : rosterEntry.getGroups()) { groupNamesList.add(group.getName()); } groupNames = groupNamesList.toArray(new String[groupNamesList.size()]); // Create a new Entry based on the rosterEntry and add it to the packet RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getUser(), rosterEntry.getName(), groupNames); addRosterEntry(remoteRosterEntry); }
public HashMap<Jid, Presence.Type> getContacts() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } String groupName = "Buddies"; RosterGroup group = roster.getGroup(groupName); if (group == null) { roster.createGroup(groupName); group = roster.getGroup(groupName); } HashMap<Jid, Presence.Type> buddies = new HashMap<>(); List<RosterEntry> entries = group.getEntries(); for (RosterEntry entry : entries) { BareJid jid = entry.getJid(); Presence.Type status = roster.getPresence(jid).getType(); buddies.put(jid, status); } return buddies; }
public HashMap<Jid, Presence.Type> getContactsWithSubscriptionPending() throws SmackException.NotLoggedInException, InterruptedException, SmackException.NotConnectedException { Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection()); if (!roster.isLoaded()) { roster.reloadAndWait(); } String groupName = "Buddies"; RosterGroup group = roster.getGroup(groupName); if (group == null) { roster.createGroup(groupName); group = roster.getGroup(groupName); } HashMap<Jid, Presence.Type> buddiesPending = new HashMap<>(); List<RosterEntry> entries = group.getEntries(); for (RosterEntry entry : entries) { if (entry.isSubscriptionPending()) { BareJid jid = entry.getJid(); Presence.Type status = roster.getPresence(jid).getType(); buddiesPending.put(jid, status); } } return buddiesPending; }
/** * Sends a roster group to userID. All the entries of the group will be sent to the * target user. * * @param rosterGroup the roster group to send * @param targetUserID the user that will receive the roster entries * @throws NotConnectedException */ public void send(RosterGroup rosterGroup, String targetUserID) throws NotConnectedException { // Create a new message to send the roster Message msg = new Message(targetUserID); // Create a RosterExchange Package and add it to the message RosterExchange rosterExchange = new RosterExchange(); for (RosterEntry entry : rosterGroup.getEntries()) { rosterExchange.addRosterEntry(entry); } msg.addExtension(rosterExchange); XMPPConnection connection = weakRefConnection.get(); // Send the message that contains the roster connection.sendStanza(msg); }
@Override protected void doRemoveContactFromListAsync(Contact contact, ContactList list) { // FIXME synchronize this to executor thread if (mConnection == null) return; String address = contact.getAddress().getAddress(); //otherwise, send unsub message and delete from local contact database org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence( org.jivesoftware.smack.packet.Presence.Type.unsubscribe); presence.setTo(address); sendPacket(presence); presence = new org.jivesoftware.smack.packet.Presence( org.jivesoftware.smack.packet.Presence.Type.unsubscribed); presence.setTo(address); sendPacket(presence); try { RosterEntry entry = mRoster.getEntry(JidCreate.bareFrom(address)); RosterGroup group = mRoster.getGroup(list.getName()); if (entry != null) { if (group == null) { debug(TAG, "could not find group " + list.getName() + " in roster"); if (mRoster != null) mRoster.removeEntry(entry); } else { group.removeEntry(entry); entry = mRoster.getEntry(JidCreate.bareFrom(address)); // Remove from Roster if this is the last group if (entry != null && entry.getGroups().size() <= 1) mRoster.removeEntry(entry); } } } catch (Exception e) { debug(TAG, "remove entry failed: " + e.getMessage()); throw new RuntimeException(e); } notifyContactListUpdated(list, ContactListListener.LIST_CONTACT_REMOVED, contact); }