use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MamManager method ensureMamQueryResultMatchesThisManager.
private void ensureMamQueryResultMatchesThisManager(MamQueryResult mamQueryResult) {
EntityFullJid localAddress = connection().getUser();
EntityBareJid localBareAddress = null;
if (localAddress != null) {
localBareAddress = localAddress.asEntityBareJid();
}
boolean isLocalUserArchive = archiveAddress == null || archiveAddress.equals(localBareAddress);
Jid finIqFrom = mamQueryResult.mamFin.getFrom();
if (finIqFrom != null) {
if (finIqFrom.equals(archiveAddress) || (isLocalUserArchive && finIqFrom.equals(localBareAddress))) {
return;
}
throw new IllegalArgumentException("The given MamQueryResult is from the MAM archive '" + finIqFrom + "' whereas this MamManager is responsible for '" + archiveAddress + '\'');
} else if (!isLocalUserArchive) {
throw new IllegalArgumentException("The given MamQueryResult is from the local entity (user) MAM archive, whereas this MamManager is responsible for '" + archiveAddress + '\'');
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class IntTestUtil method deleteViaServiceAdministration.
public static void deleteViaServiceAdministration(XMPPTCPConnection connection, Configuration config) {
EntityBareJid accountToDelete = connection.getUser().asEntityBareJid();
final int maxAttempts = 3;
int attempts;
for (attempts = 0; attempts < maxAttempts; attempts++) {
connection.disconnect();
try {
connection.connect().login(config.adminAccountUsername, config.adminAccountPassword);
} catch (XMPPException | SmackException | IOException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
}
ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
try {
adminManager.deleteUser(accountToDelete);
} catch (NoResponseException | XMPPErrorException | NotConnectedException | InterruptedException e) {
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
continue;
}
}
if (attempts > maxAttempts) {
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatManager method getJoinedRooms.
/**
* Returns a List of the rooms where the requested user has joined. The Iterator will contain Strings where each
* String represents a room (e.g. room@muc.jabber.org).
*
* @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com.
* @return a List of the rooms where the requested user has joined.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<EntityBareJid> getJoinedRooms(EntityJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// Send the disco packet to the user
DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE);
List<DiscoverItems.Item> items = result.getItems();
List<EntityBareJid> answer = new ArrayList<>(items.size());
// Collect the entityID for each returned item
for (DiscoverItems.Item item : items) {
EntityBareJid muc = item.getEntityID().asEntityBareJidIfPossible();
if (muc == null) {
LOGGER.warning("Not a bare JID: " + item.getEntityID());
continue;
}
answer.add(muc);
}
return answer;
}
use of org.jxmpp.jid.EntityBareJid in project Zom-Android by zom.
the class XmppConnection method loadVCard.
private boolean loadVCard(ContentResolver resolver, String jid) {
try {
debug(TAG, "loading vcard for: " + jid);
EntityBareJid bareJid = JidCreate.entityBareFrom(jid);
VCardManager vCardManager = VCardManager.getInstanceFor(mConnection);
VCard vCard = vCardManager.loadVCard(bareJid);
Contact contact = mContactListManager.getContact(bareJid.toString());
if (!TextUtils.isEmpty(vCard.getNickName())) {
if (!vCard.getNickName().equals(contact.getName())) {
contact.setName(vCard.getNickName());
mContactListManager.doSetContactName(contact.getAddress().getBareAddress(), contact.getName());
}
}
// check for a forwarding address
if (vCard.getJabberId() != null && (!vCard.getJabberId().equals(bareJid.toString()))) {
contact.setForwardingAddress(vCard.getJabberId());
} else {
contact.setForwardingAddress(null);
}
// If VCard is loaded, then save the avatar to the personal folder.
String avatarHash = vCard.getAvatarHash();
if (avatarHash != null) {
byte[] avatarBytes = vCard.getAvatar();
if (avatarBytes != null) {
debug(TAG, "found avatar image in vcard for: " + bareJid.toString());
debug(TAG, "start avatar length: " + avatarBytes.length);
int rowsUpdated = DatabaseUtils.updateAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, avatarBytes, bareJid.toString());
if (rowsUpdated <= 0)
DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString());
return true;
}
}
} catch (Exception e) {
debug(TAG, "err loading vcard: " + e.toString());
if (e.getMessage() != null) {
String streamErr = e.getMessage();
if (streamErr != null && (streamErr.contains("404") || streamErr.contains("503"))) {
return false;
}
}
}
return false;
}
use of org.jxmpp.jid.EntityBareJid in project xabber-android by redsolution.
the class ContactAddFragment method addContact.
@Override
public void addContact() {
final AccountJid account = (AccountJid) accountView.getSelectedItem();
if (account == null || getAccount() == null) {
Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
return;
}
String contactString = userView.getText().toString();
contactString = contactString.trim();
if (contactString.contains(" ")) {
userView.setError(getString(R.string.INCORRECT_USER_NAME));
return;
}
if (TextUtils.isEmpty(contactString)) {
userView.setError(getString(R.string.EMPTY_USER_NAME));
return;
}
final UserJid user;
try {
EntityBareJid entityFullJid = JidCreate.entityBareFrom(contactString);
user = UserJid.from(entityFullJid);
} catch (XmppStringprepException | UserJid.UserJidCreateException e) {
e.printStackTrace();
userView.setError(getString(R.string.INCORRECT_USER_NAME));
return;
}
if (listenerActivity != null)
listenerActivity.showProgress(true);
final String name = nameView.getText().toString();
final ArrayList<String> groups = getSelected();
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
try {
RosterManager.getInstance().createContact(account, user, name, groups);
PresenceManager.getInstance().requestSubscription(account, user);
} catch (SmackException.NotLoggedInException | SmackException.NotConnectedException e) {
Application.getInstance().onError(R.string.NOT_CONNECTED);
stopAddContactProcess(false);
} catch (XMPPException.XMPPErrorException e) {
Application.getInstance().onError(R.string.XMPP_EXCEPTION);
stopAddContactProcess(false);
} catch (SmackException.NoResponseException e) {
Application.getInstance().onError(R.string.CONNECTION_FAILED);
stopAddContactProcess(false);
} catch (NetworkException e) {
Application.getInstance().onError(e);
stopAddContactProcess(false);
} catch (InterruptedException e) {
LogManager.exception(this, e);
stopAddContactProcess(false);
}
stopAddContactProcess(true);
}
});
}
Aggregations