Search in sources :

Example 41 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method setGroups.

public void setGroups(AccountJid account, UserJid user, Collection<String> groups) throws NetworkException {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return;
    }
    final RosterEntry entry = roster.getEntry(user.getJid().asBareJid());
    if (entry == null) {
        return;
    }
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.set);
    RosterPacket.Item item = new RosterPacket.Item(user.getBareJid(), entry.getName());
    for (String group : groups) {
        item.addGroupName(group);
    }
    packet.addRosterItem(item);
    StanzaSender.sendStanza(account, packet);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionItem(com.xabber.android.data.connection.ConnectionItem) MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) Roster(org.jivesoftware.smack.roster.Roster) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 42 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method setName.

public void setName(AccountJid account, UserJid user, final String name) {
    final Roster roster = getRoster(account);
    if (roster == null) {
        return;
    }
    final RosterEntry entry = roster.getEntry(user.getJid().asBareJid());
    if (entry == null) {
        return;
    }
    try {
        entry.setName(name.trim());
    } catch (SmackException.NotConnectedException e) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
    } catch (SmackException.NoResponseException e) {
        Application.getInstance().onError(R.string.CONNECTION_FAILED);
    } catch (XMPPException.XMPPErrorException e) {
        Application.getInstance().onError(R.string.XMPP_EXCEPTION);
    } catch (InterruptedException e) {
        LogManager.exception(LOG_TAG, e);
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) SmackException(org.jivesoftware.smack.SmackException) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPException(org.jivesoftware.smack.XMPPException)

Example 43 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method onContactsAdded.

void onContactsAdded(final AccountJid account, Collection<Jid> addresses) {
    final Roster roster = RosterManager.getInstance().getRoster(account);
    final Collection<RosterContact> newContacts = new ArrayList<>(addresses.size());
    for (Jid jid : addresses) {
        RosterEntry entry = roster.getEntry(jid.asBareJid());
        try {
            RosterContact contact = convertRosterEntryToRosterContact(account, roster, entry);
            rosterContacts.put(account.toString(), contact.getUser().getBareJid().toString(), contact);
            newContacts.add(contact);
            LastActivityInteractor.getInstance().requestLastActivityAsync(account, UserJid.from(jid));
        } catch (UserJid.UserJidCreateException e) {
            LogManager.exception(LOG_TAG, e);
        }
    }
    Application.getInstance().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            RosterCacheManager.saveContact(account, newContacts);
        }
    });
    onContactsChanged(newContacts);
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 44 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project xabber-android by redsolution.

the class RosterManager method createGroupForUnfiledEntries.

private void createGroupForUnfiledEntries(String newGroup, Roster roster) {
    final Set<RosterEntry> unfiledEntries = roster.getUnfiledEntries();
    final org.jivesoftware.smack.roster.RosterGroup group = roster.createGroup(newGroup);
    try {
        for (RosterEntry entry : unfiledEntries) {
            group.addEntry(entry);
        }
    } catch (SmackException.NoResponseException e) {
        Application.getInstance().onError(R.string.CONNECTION_FAILED);
    } catch (SmackException.NotConnectedException e) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
    } catch (XMPPException.XMPPErrorException e) {
        Application.getInstance().onError(R.string.XMPP_EXCEPTION);
    } catch (InterruptedException e) {
        LogManager.exception(LOG_TAG, e);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPException(org.jivesoftware.smack.XMPPException)

Example 45 with RosterEntry

use of org.jivesoftware.smack.roster.RosterEntry in project Smack by igniterealtime.

the class RosterExchangeManager method send.

/**
 * 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 if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void send(RosterGroup rosterGroup, Jid targetUserID) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = weakRefConnection.get();
    // Create a new message to send the roster
    MessageBuilder msg = connection.getStanzaFactory().buildMessageStanza().to(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);
    // Send the message that contains the roster
    connection.sendStanza(msg.build());
}
Also used : RosterExchange(org.jivesoftware.smackx.xroster.packet.RosterExchange) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Aggregations

RosterEntry (org.jivesoftware.smack.roster.RosterEntry)45 Roster (org.jivesoftware.smack.roster.Roster)35 RosterGroup (org.jivesoftware.smack.roster.RosterGroup)17 SmackException (org.jivesoftware.smack.SmackException)14 Presence (org.jivesoftware.smack.packet.Presence)13 XMPPException (org.jivesoftware.smack.XMPPException)12 IOException (java.io.IOException)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)4 RosterPacket (org.jivesoftware.smack.roster.packet.RosterPacket)3 AccountItem (com.xabber.android.data.account.AccountItem)2 ConnectionItem (com.xabber.android.data.connection.ConnectionItem)2 java.awt (java.awt)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 KeyEvent (java.awt.event.KeyEvent)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 javax.swing (javax.swing)2 Icon (javax.swing.Icon)2