Search in sources :

Example 1 with EntityBareJid

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 + '\'');
    }
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 2 with EntityBareJid

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);
    }
}
Also used : ServiceAdministrationManager(org.jivesoftware.smackx.admin.ServiceAdministrationManager) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 3 with EntityBareJid

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;
}
Also used : ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 4 with EntityBareJid

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;
}
Also used : VCardManager(org.jivesoftware.smackx.vcardtemp.VCardManager) EntityBareJid(org.jxmpp.jid.EntityBareJid) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) OmemoFingerprint(org.jivesoftware.smackx.omemo.OmemoFingerprint) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException) Contact(org.awesomeapp.messenger.model.Contact)

Example 5 with EntityBareJid

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);
        }
    });
}
Also used : SmackException(org.jivesoftware.smack.SmackException) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) AccountJid(com.xabber.android.data.entity.AccountJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

EntityBareJid (org.jxmpp.jid.EntityBareJid)56 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)30 XMPPException (org.jivesoftware.smack.XMPPException)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)21 SmackException (org.jivesoftware.smack.SmackException)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)16 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)15 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 Presence (org.jivesoftware.smack.packet.Presence)6 Jid (org.jxmpp.jid.Jid)6 Message (org.jivesoftware.smack.packet.Message)5 ArrayList (java.util.ArrayList)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)4 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)4 UserJid (com.xabber.android.data.entity.UserJid)3 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2