Java Code Examples for org.jivesoftware.smack.roster.Roster#isLoaded()

The following examples show how to use org.jivesoftware.smack.roster.Roster#isLoaded() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 6 votes vote down vote up
public void removeContact(String jidString)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    BareJid jid = JidCreate.bareFrom(jidString);
    roster.removeEntry(roster.getEntry(jid));

    Presence presence = new Presence(Presence.Type.unsubscribe);
    presence.setTo(JidCreate.from(jidString));
    XMPPSession.getInstance().sendStanza(presence);
}
 
Example 2
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 6 votes vote down vote up
public void addContact(String jidString)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }

    BareJid jid = JidCreate.bareFrom(jidString);
    String name = XMPPUtils.fromJIDToUserName(jidString);
    String[] groups = new String[]{"Buddies"};

    roster.createEntry(jid, name, groups);
    roster.sendSubscriptionRequest(jid);
}
 
Example 3
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public void removeAllContacts()
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException {
    Roster roster = Roster.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    if (!roster.isLoaded()) {
        roster.reloadAndWait();
    }
    for (RosterEntry entry : roster.getEntries()) {
        roster.removeEntry(entry);
        Presence presence = new Presence(Presence.Type.unsubscribe);
        presence.setTo(entry.getJid());
        XMPPSession.getInstance().sendStanza(presence);
    }
}
 
Example 4
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
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;
}