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);
}
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);
}
}
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);
}
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);
}
}
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());
}
Aggregations