public void setPresence(Presence newPresence) { // Try to remove the element whose namespace is "http://jabber.org/protocol/muc" since we // don't need to include that element in future presence broadcasts Element element = newPresence.getElement().element(QName.get("x", "http://jabber.org/protocol/muc")); if (element != null) { newPresence.getElement().remove(element); } this.presence = newPresence; this.presence.setFrom(getRoleAddress()); if (extendedInformation != null) { extendedInformation.setParent(null); presence.getElement().add(extendedInformation); } }
/** * Create a new role. * * @param chatserver the server hosting the role. * @param chatroom the room the role is valid in. * @param nickname the nickname of the user in the role. * @param role the role of the user in the room. * @param affiliation the affiliation of the user in the room. * @param chatuser the user on the chat server. * @param presence the presence sent by the user to join the room. * @param packetRouter the packet router for sending messages from this role. */ public LocalMUCRole( MultiUserChatService chatserver, LocalMUCRoom chatroom, String nickname, MUCRole.Role role, MUCRole.Affiliation affiliation, LocalMUCUser chatuser, Presence presence, PacketRouter packetRouter) { this.room = chatroom; this.nick = nickname; this.user = chatuser; this.server = chatserver; this.router = packetRouter; this.role = role; this.affiliation = affiliation; // Cache the user's session (will only work for local users) this.session = XMPPServer.getInstance().getSessionManager().getSession(presence.getFrom()); extendedInformation = DocumentHelper.createElement(QName.get("x", "http://jabber.org/protocol/muc#user")); calculateExtendedInformation(); rJID = new JID(room.getName(), server.getServiceDomain(), nick); setPresence(presence); // Check if new occupant wants to be a deaf occupant Element element = presence.getElement().element(QName.get("x", "http://jivesoftware.org/protocol/muc")); if (element != null) { voiceOnly = element.element("deaf-occupant") != null; } // Add the new role to the list of roles user.addRole(room.getName(), this); }
@Override public void writeExternal(ObjectOutput out) throws IOException { super.writeExternal(out); ExternalizableUtil.getInstance().writeSerializable(out, (DefaultElement) presence.getElement()); ExternalizableUtil.getInstance().writeSafeUTF(out, nickname); ExternalizableUtil.getInstance().writeInt(out, role); ExternalizableUtil.getInstance().writeInt(out, affiliation); }
private void processPresence(Element doc) { log.debug("processPresence()..."); Presence packet; try { packet = new Presence(doc, false); } catch (IllegalArgumentException e) { log.debug("Rejecting packet. JID malformed", e); Presence reply = new Presence(); reply.setID(doc.attributeValue("id")); reply.setTo(session.getAddress()); reply.getElement().addAttribute("from", doc.attributeValue("to")); reply.setError(PacketError.Condition.jid_malformed); session.process(reply); return; } if (session.getStatus() == Session.STATUS_CLOSED && packet.isAvailable()) { log.warn("Ignoring available presence packet of closed session: " + packet); return; } packet.setFrom(session.getAddress()); router.route(packet); session.incrementClientPacketCount(); if (session.getStatus() == Session.STATUS_AUTHENTICATED && packet.isAvailable()) { String userName = session.getAddress().getNode(); System.out.println("Query username : -> " + userName); if (null != userName && !"".equals(userName)) { NotificationMO mo = new NotificationMO(); mo.setUsername(userName); mo.setStatus(NotificationMO.STATUS_NOT_SEND); List<NotificationMO> list = notificationService.queryNotification(mo); if (!list.isEmpty()) { for (NotificationMO notificationMO : list) { notificationManager.sendOfflineNotification(notificationMO); } } else { log.info(" no offline notification, username = "******"userName is null !!!!!!"); } } }