use of org.jxmpp.jid.parts.Resourcepart in project Smack by igniterealtime.
the class MUCParserUtils method parseItem.
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
int initialDepth = parser.getDepth();
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
Jid jid = ParserUtils.getJidAttribute(parser);
Jid actor = null;
Resourcepart actorNick = null;
String reason = null;
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String name = parser.getName();
switch(name) {
case "actor":
actor = ParserUtils.getJidAttribute(parser);
// TODO change to
// actorNick = Resourcepart.from(parser.getAttributeValue("", "nick"));
// once a newer version of JXMPP is used that supports from(null).
String actorNickString = parser.getAttributeValue("", "nick");
if (actorNickString != null) {
actorNick = Resourcepart.from(actorNickString);
}
break;
case "reason":
reason = parser.nextText();
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick);
}
use of org.jxmpp.jid.parts.Resourcepart in project Smack by igniterealtime.
the class Roster method getAllPresences.
/**
* Returns a List of Presence objects for all of a user's current presences if no presence information is available,
* such as when you are not subscribed to the user's presence updates.
*
* @param bareJid an XMPP ID, e.g. jdoe@example.com.
* @return a List of Presence objects for all the user's current presences, or an unavailable presence if no
* presence information is available.
*/
public List<Presence> getAllPresences(BareJid bareJid) {
Map<Resourcepart, Presence> userPresences = getPresencesInternal(bareJid);
List<Presence> res;
if (userPresences == null) {
// Create an unavailable presence if none was found
Presence unavailable = synthesizeUnvailablePresence(bareJid);
res = new ArrayList<>(Arrays.asList(unavailable));
} else {
res = new ArrayList<>(userPresences.values().size());
for (Presence presence : userPresences.values()) {
res.add(presence);
}
}
return res;
}
use of org.jxmpp.jid.parts.Resourcepart in project Smack by igniterealtime.
the class Roster method getPresenceResource.
/**
* Returns the presence info for a particular user's resource, or unavailable presence
* if the user is offline or if no presence information is available, such as
* when you are not subscribed to the user's presence updates.
*
* @param userWithResource a fully qualified XMPP ID including a resource (user@domain/resource).
* @return the user's current presence, or unavailable presence if the user is offline
* or if no presence information is available.
*/
public Presence getPresenceResource(FullJid userWithResource) {
BareJid key = userWithResource.asBareJid();
Resourcepart resource = userWithResource.getResourcepart();
Map<Resourcepart, Presence> userPresences = getPresencesInternal(key);
if (userPresences == null) {
Presence presence = synthesizeUnvailablePresence(userWithResource);
return presence;
} else {
Presence presence = userPresences.get(resource);
if (presence == null) {
presence = synthesizeUnvailablePresence(userWithResource);
return presence;
} else {
return presence;
}
}
}
use of org.jxmpp.jid.parts.Resourcepart in project Smack by igniterealtime.
the class Roster method getPresence.
/**
* Returns the presence info for a particular user. If the user is offline, or
* if no presence data is available (such as when you are not subscribed to the
* user's presence updates), unavailable presence will be returned.
*
* If the user has several presences (one for each resource), then the presence with
* highest priority will be returned. If multiple presences have the same priority,
* the one with the "most available" presence mode will be returned. In order,
* that's {@link org.jivesoftware.smack.packet.Presence.Mode#chat free to chat},
* {@link org.jivesoftware.smack.packet.Presence.Mode#available available},
* {@link org.jivesoftware.smack.packet.Presence.Mode#away away},
* {@link org.jivesoftware.smack.packet.Presence.Mode#xa extended away}, and
* {@link org.jivesoftware.smack.packet.Presence.Mode#dnd do not disturb}.
*
* <p>
* Note that presence information is received asynchronously. So, just after logging
* in to the server, presence values for users in the roster may be unavailable
* even if they are actually online. In other words, the value returned by this
* method should only be treated as a snapshot in time, and may not accurately reflect
* other user's presence instant by instant. If you need to track presence over time,
* such as when showing a visual representation of the roster, consider using a
* {@link RosterListener}.
* </p>
*
* @param jid the XMPP address of the user (eg "jsmith@example.com"). The
* address must be a bare JID e.g. "domain/resource" or
* "user@domain".
* @return the user's current presence, or unavailable presence if the user is offline
* or if no presence information is available..
*/
public Presence getPresence(BareJid jid) {
Map<Resourcepart, Presence> userPresences = getPresencesInternal(jid);
if (userPresences == null) {
Presence presence = synthesizeUnvailablePresence(jid);
return presence;
} else {
// Find the resource with the highest priority
// Might be changed to use the resource with the highest availability instead.
Presence presence = null;
// This is used in case no available presence is found
Presence unavailable = null;
for (Presence p : userPresences.values()) {
if (!p.isAvailable()) {
unavailable = p;
continue;
}
// Chose presence with highest priority first.
if (presence == null || p.getPriority() > presence.getPriority()) {
presence = p;
} else // If equal priority, choose "most available" by the mode value.
if (p.getPriority() == presence.getPriority()) {
Presence.Mode pMode = p.getMode();
// Default to presence mode of available.
if (pMode == null) {
pMode = Presence.Mode.available;
}
Presence.Mode presenceMode = presence.getMode();
// Default to presence mode of available.
if (presenceMode == null) {
presenceMode = Presence.Mode.available;
}
if (pMode.compareTo(presenceMode) < 0) {
presence = p;
}
}
}
if (presence == null) {
if (unavailable != null) {
return unavailable;
} else {
presence = synthesizeUnvailablePresence(jid);
return presence;
}
} else {
return presence;
}
}
}
use of org.jxmpp.jid.parts.Resourcepart in project Smack by igniterealtime.
the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForRemovingModerator.
/**
* Asserts that a user who undergoes a role change receives that change as a presence update
*
* <p>From XEP-0045 § 5.1.3:</p>
* <blockquote>
* ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change
* to all occupants...
* </blockquote>
*
* <p>From XEP-0045 § 9.7:</p>
* <blockquote>
* The service MUST then send updated presence from this individual to all occupants, indicating the removal of
* moderator status...
* </blockquote>
*
* @throws Exception when errors occur
*/
@SmackIntegrationTest
public void mucRoleTestForRemovingModerator() throws Exception {
EntityBareJid mucAddress = getRandomRoom("smack-inttest");
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() {
@Override
public void moderatorRevoked() {
resultSyncPoint.signal("done");
}
});
createMuc(mucAsSeenByOne, "one-" + randomString);
try {
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByOne.grantModerator(nicknameTwo);
mucAsSeenByOne.revokeModerator(nicknameTwo);
resultSyncPoint.waitForResult(timeout);
} finally {
tryDestroy(mucAsSeenByOne);
}
}
Aggregations