use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class LocalMUCRoom method changeOccupantRole.
/**
* Updates the presence of the given user with the new role information. Do nothing if the given
* jid is not present in the room.
*
* @param jid the full jid of the user to update his/her role.
* @param newRole the new role for the JID.
* @return the updated presence of the user or null if none.
* @throws NotAllowedException If trying to change the moderator role to an owner or an admin.
*/
private Presence changeOccupantRole(JID jid, MUCRole.Role newRole) throws NotAllowedException {
// Try looking the role in the bare JID list
MUCRole role = occupantsByFullJID.get(jid);
// }
if (role != null) {
if (role.isLocal()) {
// Update the presence with the new role
role.setRole(newRole);
// Notify the other cluster nodes to update the occupant
CacheFactory.doClusterTask(new UpdateOccupant(this, role));
// Prepare a new presence to be sent to all the room occupants
return role.getPresence().createCopy();
} else {
// Ask the cluster node hosting the occupant to make the changes. Note that if the change
// is not allowed a NotAllowedException will be thrown
Element element = (Element) CacheFactory.doSynchronousClusterTask(new UpdateOccupantRequest(this, role.getNickname(), null, newRole), role.getNodeID().toByteArray());
if (element != null) {
// Prepare a new presence to be sent to all the room occupants
return new Presence(element, true);
} else {
throw new NotAllowedException();
}
}
}
return null;
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RemoteMUCRole method readExternal.
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
serviceDomain = ExternalizableUtil.getInstance().readSafeUTF(in);
presence = new Presence((Element) ExternalizableUtil.getInstance().readSerializable(in), true);
role = Role.values()[ExternalizableUtil.getInstance().readInt(in)];
affiliation = Affiliation.values()[ExternalizableUtil.getInstance().readInt(in)];
nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
voiceOnly = ExternalizableUtil.getInstance().readBoolean(in);
roleAddress = (JID) ExternalizableUtil.getInstance().readSerializable(in);
userAddress = (JID) ExternalizableUtil.getInstance().readSerializable(in);
nodeID = NodeID.getInstance(ExternalizableUtil.getInstance().readByteArray(in));
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class MultiplexerPacketDeliverer method handleUnprocessedPacket.
private void handleUnprocessedPacket(Packet packet) {
if (packet instanceof Message) {
messageStrategy.storeOffline((Message) packet);
} else if (packet instanceof Presence) {
// presence packets are dropped silently
//dropPacket(packet);
} else if (packet instanceof IQ) {
IQ iq = (IQ) packet;
// Check if we need to unwrap the packet
Element child = iq.getChildElement();
if (child != null && "session".equals(child.getName()) && "http://jabber.org/protocol/connectionmanager".equals(child.getNamespacePrefix())) {
Element send = child.element("send");
if (send != null) {
// Unwrap packet
Element wrappedElement = (Element) send.elements().get(0);
if ("message".equals(wrappedElement.getName())) {
handleUnprocessedPacket(new Message(wrappedElement));
}
}
} else {
// IQ packets are logged but dropped
Log.warn(LocaleUtils.getLocalizedString("admin.error.routing") + "\n" + packet.toString());
}
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class WorkgroupPresence method sendPresence.
/**
* Sends the presence of the workgroup to the specified JID address.
*
* @param address the XMPP address that will receive the presence of the workgroup.
*/
public void sendPresence(JID address) {
Presence presence = new Presence();
presence.setTo(address);
presence.setFrom(workgroup.getJID());
Presence.Type type;
if (workgroup.isAvailable()) {
type = null;
// Add the a child element that will contain information about the workgroup
Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
// Add the last modification date of the workgroup
child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
} else {
type = Presence.Type.unavailable;
// Add the a child element that will contain information about the workgroup
Element child = presence.addChildElement("workgroup", "http://jivesoftware.com/protocol/workgroup");
// Add the last modification date of the workgroup
child.addElement("lastModified").setText(UTC_FORMAT.format(workgroup.getModificationDate()));
}
presence.setType(type);
workgroup.send(presence);
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class NonPersistantRosterProcessor method process.
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
Presence myPacket = (Presence) packet;
if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable) && !myPacket.getElement().getStringValue().equals("Connecting")) {
String username = getUsernameFromJid(to);
Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain + "and user " + username + " Packet: " + packet.toString());
try {
Roster roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
String itemName = item.getJid().toString();
if (itemName.contains(subdomain)) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list.");
roster.deleteRosterItem(item.getJid(), false);
}
}
} catch (Exception e) {
Log.debug("Execption occured when cleaning up the Roster.", e);
e.printStackTrace();
}
}
}
Aggregations