use of org.jivesoftware.smackx.muc.packet.MUCItem in project xabber-android by redsolution.
the class RoomChat method createOccupant.
/**
* Warning: this method should be placed with packet provider.
*
* @return New occupant based on presence information.
*/
private Occupant createOccupant(String resource, Presence presence) {
Occupant occupant = new Occupant(resource);
String jid = null;
Affiliation affiliation = Affiliation.none;
Role role = Role.none;
StatusMode statusMode = StatusMode.unavailable;
String statusText = null;
MUCUser mucUser = MUC.getMUCUserExtension(presence);
if (mucUser != null) {
MUCItem item = mucUser.getItem();
if (item != null) {
jid = item.getJid();
try {
affiliation = Affiliation.fromString(item.getAffiliation().toString());
} catch (NoSuchElementException e) {
}
try {
role = Role.fromString(item.getRole().toString());
} catch (NoSuchElementException e) {
}
statusMode = StatusMode.createStatusMode(presence);
statusText = presence.getStatus();
}
}
if (statusText == null) {
statusText = "";
}
occupant.setJid(jid);
occupant.setAffiliation(affiliation);
occupant.setRole(role);
occupant.setStatusMode(statusMode);
occupant.setStatusText(statusText);
return occupant;
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Spark by igniterealtime.
the class GroupChatParticipantList method setChatRoom.
public void setChatRoom(final ChatRoom chatRoom) {
this.groupChatRoom = (GroupChatRoom) chatRoom;
chat = groupChatRoom.getMultiUserChat();
chat.addInvitationRejectionListener((jid1, message) -> {
String nickname = userManager.getUserNicknameFromJID(jid1);
userHasLeft(nickname);
chatRoom.getTranscriptWindow().insertNotificationMessage(nickname + " has rejected the invitation.", ChatManager.NOTIFICATION_COLOR);
});
listener = p -> SwingUtilities.invokeLater(() -> {
if (p.getError() != null) {
if (p.getError().getCondition().equals(XMPPError.Condition.conflict.toString())) {
return;
}
}
final String userid = p.getFrom();
String displayName = XmppStringUtils.parseResource(userid);
userMap.put(displayName, userid);
if (p.getType() == Presence.Type.available) {
addParticipant(userid, p);
agentInfoPanel.setVisible(true);
groupChatRoom.validate();
} else {
removeUser(displayName);
}
// When joining a room, check if the current user is an owner/admin. If so, the UI should allow the current
// user to change settings of this MUC.
final MUCUser mucUserEx = p.getExtension(MUCUser.ELEMENT, MUCUser.NAMESPACE);
if (// 110 = Inform user that presence refers to itself
mucUserEx != null && mucUserEx.getStatus().contains(MUCUser.Status.create(110))) {
final MUCItem item = mucUserEx.getItem();
if (item != null) {
if (item.getAffiliation() == MUCAffiliation.admin || item.getAffiliation() == MUCAffiliation.owner) {
groupChatRoom.notifySettingsAccessRight();
}
}
}
});
chat.addParticipantListener(listener);
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
try {
roomInformation = disco.discoverInfo(chat.getRoom());
} catch (XMPPException | SmackException e) {
Log.debug("Unable to retrieve room information for " + chat.getRoom());
}
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MultiUserChat method getOccupants.
/**
* Returns a list of <code>Occupant</code> that have the specified room role.
*
* @param role the role of the occupant in the room.
* @return a list of <code>Occupant</code> that have the specified room role.
* @throws XMPPErrorException if an error occurred while performing the request to the server or you
* don't have enough privileges to get this information.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
private List<Occupant> getOccupants(MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.get);
// Set the specified role. This may request the list of moderators/participants.
MUCItem item = new MUCItem(role);
iq.addItem(item);
MUCAdmin answer = (MUCAdmin) connection.sendIqRequestAndWaitForResponse(iq);
// Get the list of participants from the server's answer
List<Occupant> participants = new ArrayList<Occupant>();
for (MUCItem mucadminItem : answer.getItems()) {
participants.add(new Occupant(mucadminItem));
}
return participants;
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project Smack by igniterealtime.
the class MultiUserChat method changeRole.
private void changeRole(Collection<Resourcepart> nicknames, MUCRole role) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCAdmin iq = new MUCAdmin();
iq.setTo(room);
iq.setType(IQ.Type.set);
for (Resourcepart nickname : nicknames) {
// Set the new role.
MUCItem item = new MUCItem(role, nickname);
iq.addItem(item);
}
connection.sendIqRequestAndWaitForResponse(iq);
}
use of org.jivesoftware.smackx.muc.packet.MUCItem in project xabber-android by redsolution.
the class RoomChat method createOccupant.
/**
* Warning: this method should be placed with packet provider.
*
* @return New occupant based on presence information.
*/
private Occupant createOccupant(Resourcepart resource, Presence presence) {
Occupant occupant = new Occupant(resource);
org.jxmpp.jid.Jid jid = null;
MUCAffiliation affiliation = MUCAffiliation.none;
MUCRole role = MUCRole.none;
StatusMode statusMode = StatusMode.unavailable;
String statusText = null;
MUCUser mucUser = MUCUser.from(presence);
if (mucUser != null) {
MUCItem item = mucUser.getItem();
if (item != null) {
jid = item.getJid();
try {
affiliation = item.getAffiliation();
} catch (NoSuchElementException e) {
}
try {
role = item.getRole();
} catch (NoSuchElementException e) {
}
statusMode = StatusMode.createStatusMode(presence);
statusText = presence.getStatus();
}
}
if (statusText == null) {
statusText = "";
}
occupant.setJid(jid);
occupant.setAffiliation(affiliation);
occupant.setRole(role);
occupant.setStatusMode(statusMode);
occupant.setStatusText(statusText);
return occupant;
}
Aggregations