Search in sources :

Example 31 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class IntTestUtil method registerAccountViaAdmin.

//    public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection) throws XmppStringprepException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
//        return registerAccountViaAdmin(connection, StringUtils.insecureRandomString(12),
//                        StringUtils.insecureRandomString(12));
//    }
public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection, String username, String password, String adminAccountUsername, String adminAccountPassword) throws InterruptedException, XMPPException, SmackException, IOException {
    connection.login(adminAccountUsername, adminAccountPassword);
    ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
    EntityBareJid userJid = JidCreate.entityBareFrom(Localpart.from(username), connection.getServiceName());
    adminManager.addUser(userJid, password);
    connection.disconnect();
    connection.connect();
    return new UsernameAndPassword(username, password);
}
Also used : ServiceAdministrationManager(org.jivesoftware.smackx.admin.ServiceAdministrationManager) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 32 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project xabber-android by redsolution.

the class PresenceManager method getOccupant.

/**
 * if contact is private MUC chat
 */
@Nullable
private Occupant getOccupant(AccountJid account, UserJid user) {
    EntityBareJid userEntityBareJid = user.getJid().asEntityBareJidIfPossible();
    if (userEntityBareJid == null) {
        return null;
    }
    Resourcepart resourcepart = user.getJid().getResourceOrNull();
    if (resourcepart == null) {
        return null;
    }
    if (MUCManager.getInstance().hasRoom(account, userEntityBareJid)) {
        final Collection<Occupant> occupants = MUCManager.getInstance().getOccupants(account, userEntityBareJid);
        for (Occupant occupant : occupants) {
            if (occupant.getNickname().equals(resourcepart)) {
                return occupant;
            }
        }
    }
    return null;
}
Also used : Occupant(com.xabber.android.data.extension.muc.Occupant) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Nullable(androidx.annotation.Nullable)

Example 33 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project xabber-android by redsolution.

the class RosterManager method getDisplayAuthorName.

public static String getDisplayAuthorName(MessageItem messageItem) {
    UserJid jid = null;
    try {
        jid = UserJid.from(messageItem.getOriginalFrom());
    } catch (UserJid.UserJidCreateException e) {
        e.printStackTrace();
    }
    String author = null;
    if (jid != null) {
        EntityBareJid room = messageItem.getUser().getBareJid().asEntityBareJidIfPossible();
        RoomChat roomChat = null;
        if (room != null)
            roomChat = MUCManager.getInstance().getRoomChat(messageItem.getAccount(), room);
        if (roomChat != null) {
            if (!messageItem.isIncoming())
                author = MUCManager.getInstance().getNickname(messageItem.getAccount(), room).toString();
            else
                author = jid.getJid().getResourceOrEmpty().toString();
        } else {
            if (!messageItem.getAccount().getFullJid().asBareJid().equals(jid.getBareJid()))
                author = RosterManager.getInstance().getNameOrBareJid(messageItem.getAccount(), jid);
            else
                author = AccountManager.getInstance().getNickName(messageItem.getAccount());
        }
    }
    return author;
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) RoomChat(com.xabber.android.data.extension.muc.RoomChat)

Example 34 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project xabber-android by redsolution.

the class VCardManager method getVCard.

@SuppressWarnings("WeakerAccess")
void getVCard(final AccountJid account, final Jid srcUser) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        onVCardFailed(account, srcUser);
        return;
    }
    final CustomVCardManager vCardManager = CustomVCardManager.getInstanceFor(accountItem.getConnection());
    if (!accountItem.getConnection().isAuthenticated()) {
        onVCardFailed(account, srcUser);
        return;
    }
    Collection<UserJid> blockedContacts = BlockingManager.getInstance().getBlockedContacts(account);
    for (UserJid blockedContact : blockedContacts) {
        if (blockedContact.getBareJid().equals(srcUser.asBareJid())) {
            return;
        }
    }
    final EntityBareJid entityBareJid = srcUser.asEntityBareJidIfPossible();
    if (entityBareJid != null) {
        vCardRequests.add(srcUser);
        try {
            vCardManager.sendVCardRequest(srcUser);
        } catch (SmackException.NotConnectedException e) {
            LogManager.exception(this, e);
            LogManager.w(this, "Error getting vCard: " + e.getMessage());
        } catch (ClassCastException e) {
            LogManager.exception(this, e);
            // http://stackoverflow.com/questions/31498721/error-loading-vcard-information-using-smack-emptyresultiq-cannot-be-cast-to-or
            LogManager.w(this, "ClassCastException: " + e.getMessage());
        // vCard = new VCard();
        } catch (InterruptedException e) {
            LogManager.exception(this, e);
        }
        vCardRequests.remove(srcUser);
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) SmackException(org.jivesoftware.smack.SmackException) UserJid(com.xabber.android.data.entity.UserJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 35 with EntityBareJid

use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.

the class MultiUserChatEntityIntegrationTest method mucTestForDiscoveringRooms.

/**
 * Asserts that a MUC Service lists its public rooms.
 *
 * <p>From XEP-0045 ยง 6.3:</p>
 * <blockquote>
 * The service discovery items ("disco#items") protocol enables an entity to query a service for a list of
 * associated items, which in the case of a chat service would consist of the specific chat rooms hosted by the
 * service. The service SHOULD return a full list of the public rooms it hosts (i.e., not return any rooms that
 * are hidden).
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestForDiscoveringRooms() throws Exception {
    EntityBareJid mucAddressPublic = getRandomRoom("smack-inttest-publicroom");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddressPublic);
    EntityBareJid mucAddressHidden = getRandomRoom("smack-inttest-hiddenroom");
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddressHidden);
    createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));
    Map<EntityBareJid, HostedRoom> rooms;
    try {
        createHiddenMuc(mucAsSeenByTwo, Resourcepart.from("two-" + randomString));
        rooms = mucManagerThree.getRoomsHostedBy(mucService);
    } finally {
        tryDestroy(mucAsSeenByOne);
        tryDestroy(mucAsSeenByTwo);
    }
    assertTrue(rooms.containsKey(mucAddressPublic));
    assertFalse(rooms.containsKey(mucAddressHidden));
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

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