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