org.jivesoftware.smackx.muc.packet.MUCUser Java Examples
The following examples show how to use
org.jivesoftware.smackx.muc.packet.MUCUser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Occupant.java From Smack with Apache License 2.0 | 6 votes |
Occupant(Presence presence) { MUCUser mucUser = (MUCUser) presence.getExtensionElement("x", "http://jabber.org/protocol/muc#user"); MUCItem item = mucUser.getItem(); this.jid = item.getJid(); this.affiliation = item.getAffiliation(); this.role = item.getRole(); // Get the nickname from the FROM attribute of the presence EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible(); if (from == null) { LOGGER.warning("Occupant presence without resource: " + presence.getFrom()); this.nick = null; } else { this.nick = from.getResourcepart(); } }
Example #2
Source File: MultiUserChat.java From Smack with Apache License 2.0 | 6 votes |
/** * Like {@link #create(Resourcepart)}, but will return a {@link MucCreateConfigFormHandle} if the room creation was acknowledged by * the service (with an 201 status code). It's up to the caller to decide, based on the return * value, if he needs to continue sending the room configuration. If {@code null} is returned, the room * already existed and the user is able to join right away, without sending a form. * * @param mucEnterConfiguration the configuration used to enter the MUC. * @return A {@link MucCreateConfigFormHandle} if the room was created while joining, or {@code null} if the room was just joined. * @throws XMPPErrorException if the room couldn't be created for some reason (e.g. 405 error if * the user is not allowed to create the room) * @throws NoResponseException if there was no response from the server. * @throws InterruptedException if the calling thread was interrupted. * @throws MucAlreadyJoinedException if the MUC is already joined * @throws NotConnectedException if the XMPP connection is not connected. * @throws NotAMucServiceException if the entity is not a MUC serivce. */ public synchronized MucCreateConfigFormHandle createOrJoin(MucEnterConfiguration mucEnterConfiguration) throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException { if (isJoined()) { throw new MucAlreadyJoinedException(); } Presence presence = enter(mucEnterConfiguration); // Look for confirmation of room creation from the server MUCUser mucUser = MUCUser.from(presence); if (mucUser != null && mucUser.getStatus().contains(Status.ROOM_CREATED_201)) { // Room was created and the user has joined the room return new MucCreateConfigFormHandle(); } return null; }
Example #3
Source File: MultiUserChatIntegrationTest.java From Smack with Apache License 2.0 | 6 votes |
@SmackIntegrationTest public void mucJoinLeaveTest() throws XmppStringprepException, NotAMucServiceException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException { EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-join-leave-" + randomString), mucService.getDomain()); MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress); muc.join(Resourcepart.from("nick-one")); Presence reflectedLeavePresence = muc.leave(); MUCUser mucUser = MUCUser.from(reflectedLeavePresence); assertNotNull(mucUser); assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110)); }
Example #4
Source File: MUCUserProvider.java From Smack with Apache License 2.0 | 6 votes |
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException { String reason = null; EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to"); EntityJid from = ParserUtils.getEntityJidAttribute(parser, "from"); outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { if (parser.getName().equals("reason")) { reason = parser.nextText(); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals("invite")) { break outerloop; } } } return new MUCUser.Invite(reason, from, to); }
Example #5
Source File: MUCUserProvider.java From Smack with Apache License 2.0 | 6 votes |
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws XmlPullParserException, IOException { String reason = null; EntityBareJid to = ParserUtils.getBareJidAttribute(parser, "to"); EntityBareJid from = ParserUtils.getBareJidAttribute(parser, "from"); outerloop: while (true) { XmlPullParser.Event eventType = parser.next(); if (eventType == XmlPullParser.Event.START_ELEMENT) { if (parser.getName().equals("reason")) { reason = parser.nextText(); } } else if (eventType == XmlPullParser.Event.END_ELEMENT) { if (parser.getName().equals("decline")) { break outerloop; } } } return new MUCUser.Decline(reason, from, to); }
Example #6
Source File: ChatRoomImpl.java From Spark with Apache License 2.0 | 5 votes |
@Override public void sendMessage(String text) { final Message message = new Message(); if (threadID == null) { threadID = StringUtils.randomString(6); } message.setThread(threadID); if ( privateChat ) { // XEP-0045: 7.5 Sending a Private Message message.addExtension( new MUCUser() ); } // Set the body of the message using typedMessage and remove control // characters text = text.replaceAll("[\\u0001-\\u0008\\u000B-\\u001F]", ""); message.setBody(text); // IF there is no body, just return and do nothing if (!ModelUtil.hasLength(text)) { return; } // Fire Message Filters SparkManager.getChatManager().filterOutgoingMessage(this, message); // Fire Global Filters SparkManager.getChatManager().fireGlobalMessageSentListeners(this, message); sendMessage(message); }
Example #7
Source File: PresenceManager.java From Spark with Apache License 2.0 | 5 votes |
public static String getJidFromMUCPresence(Presence presence) { Collection<ExtensionElement> extensions = presence.getExtensions(); for (ExtensionElement extension : extensions) { if (extension instanceof MUCUser) { final MUCUser mucUser = (MUCUser) extension; Jid fullJid = mucUser.getItem().getJid(); if ( fullJid == null) { return null; } return fullJid.asBareJid().toString(); } } return null; }
Example #8
Source File: MultiUserChat.java From Smack with Apache License 2.0 | 5 votes |
/** * Fires invitation rejection listeners. * * @param invitee the user being invited. * @param reason the reason for the rejection */ private void fireInvitationRejectionListeners(Message message, MUCUser.Decline rejection) { EntityBareJid invitee = rejection.getFrom(); String reason = rejection.getReason(); InvitationRejectionListener[] listeners; synchronized (invitationRejectionListeners) { listeners = new InvitationRejectionListener[invitationRejectionListeners.size()]; invitationRejectionListeners.toArray(listeners); } for (InvitationRejectionListener listener : listeners) { listener.invitationDeclined(invitee, reason, message, rejection); } }
Example #9
Source File: MUCUserStatusCodeFilter.java From Smack with Apache License 2.0 | 5 votes |
@Override public boolean accept(Stanza stanza) { MUCUser mucUser = MUCUser.from(stanza); if (mucUser == null) { return false; } return mucUser.getStatus().contains(status); }
Example #10
Source File: GroupChatParticipantList.java From Spark with Apache License 2.0 | 4 votes |
protected void addParticipant(final EntityFullJid participantJID, Presence presence) { // Remove reference to invitees for (CharSequence displayName : invitees.keySet()) { EntityFullJid jid = SparkManager.getUserManager().getJIDFromDisplayName( displayName); Occupant occ = chat.getOccupant(jid); if (occ != null) { String actualJID = occ.getJid().toString(); if (actualJID.equals(jid)) { removeUser(displayName); } } } Resourcepart nickname = participantJID.getResourcepart(); MUCAffiliation affiliation = null; MUCRole role = null; final MUCUser extension = (MUCUser) presence.getExtension( MUCUser.NAMESPACE ); if ( extension != null && extension.getItem() != null ) { affiliation = extension.getItem().getAffiliation(); role = extension.getItem().getRole(); } if ( affiliation == null ) { affiliation = MUCAffiliation.none; } if ( role == null ) { role = MUCRole.none; } usersToRoles.put(participantJID, role); usersToAffiliation.put(participantJID, affiliation); Icon icon; if (_localPreferences.isShowingRoleIcons()) { icon = getIconForRole(role, affiliation); } else { icon = PresenceManager.getIconFromPresence(presence); if (icon == null) { icon = SparkRes.getImageIcon(SparkRes.GREEN_BALL); } } if (!exists(nickname)) { addUser(icon, nickname); } else { int index = getIndex(nickname); if (index != -1) { final JLabel userLabel = new JLabel(nickname.toString(), icon, JLabel.HORIZONTAL); model.setElementAt(userLabel, index); } } }
Example #11
Source File: AgentSession.java From Smack with Apache License 2.0 | 4 votes |
private void handlePacket(Stanza packet) { if (packet instanceof Presence) { Presence presence = (Presence) packet; // The workgroup can send us a number of different presence packets. We // check for different packet extensions to see what type of presence // packet it is. Resourcepart queueName = presence.getFrom().getResourceOrNull(); WorkgroupQueue queue = queues.get(queueName); // If there isn't already an entry for the queue, create a new one. if (queue == null) { queue = new WorkgroupQueue(queueName); queues.put(queueName, queue); } // QueueOverview packet extensions contain basic information about a queue. QueueOverview queueOverview = (QueueOverview) presence.getExtensionElement(QueueOverview.ELEMENT_NAME, QueueOverview.NAMESPACE); if (queueOverview != null) { if (queueOverview.getStatus() == null) { queue.setStatus(WorkgroupQueue.Status.CLOSED); } else { queue.setStatus(queueOverview.getStatus()); } queue.setAverageWaitTime(queueOverview.getAverageWaitTime()); queue.setOldestEntry(queueOverview.getOldestEntry()); // Fire event. fireQueueUsersEvent(queue, queueOverview.getStatus(), queueOverview.getAverageWaitTime(), queueOverview.getOldestEntry(), null); return; } // QueueDetails packet extensions contain information about the users in // a queue. QueueDetails queueDetails = (QueueDetails) packet.getExtensionElement(QueueDetails.ELEMENT_NAME, QueueDetails.NAMESPACE); if (queueDetails != null) { queue.setUsers(queueDetails.getUsers()); // Fire event. fireQueueUsersEvent(queue, null, -1, null, queueDetails.getUsers()); return; } // Notify agent packets gives an overview of agent activity in a queue. StandardExtensionElement notifyAgents = (StandardExtensionElement) presence.getExtensionElement("notify-agents", "http://jabber.org/protocol/workgroup"); if (notifyAgents != null) { int currentChats = Integer.parseInt(notifyAgents.getFirstElement("current-chats", "http://jabber.org/protocol/workgroup").getText()); int maxChats = Integer.parseInt(notifyAgents.getFirstElement("max-chats", "http://jabber.org/protocol/workgroup").getText()); queue.setCurrentChats(currentChats); queue.setMaxChats(maxChats); // Fire event. // TODO: might need another event for current chats and max chats of queue return; } } else if (packet instanceof Message) { Message message = (Message) packet; // Check if a room invitation was sent and if the sender is the workgroup MUCUser mucUser = MUCUser.from(message); MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null; if (invite != null && workgroupJID.equals(invite.getFrom())) { String sessionID = null; Map<String, List<String>> metaData = null; SessionID sessionIDExt = (SessionID) message.getExtensionElement(SessionID.ELEMENT_NAME, SessionID.NAMESPACE); if (sessionIDExt != null) { sessionID = sessionIDExt.getSessionID(); } MetaData metaDataExt = (MetaData) message.getExtensionElement(MetaData.ELEMENT_NAME, MetaData.NAMESPACE); if (metaDataExt != null) { metaData = metaDataExt.getMetaData(); } this.fireInvitationEvent(message.getFrom(), sessionID, message.getBody(), message.getFrom(), metaData); } } }
Example #12
Source File: GroupChatParticipantList.java From Spark with Apache License 2.0 | 4 votes |
public void setChatRoom(final ChatRoom chatRoom) { this.groupChatRoom = (GroupChatRoom) chatRoom; chat = groupChatRoom.getMultiUserChat(); chat.addInvitationRejectionListener( ( jid1, reason, message, rejection ) -> { String nickname = userManager.getUserNicknameFromJID( jid1.toString() ); 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(StanzaError.Condition.conflict .toString())) { return; } } final EntityFullJid userid = p.getFrom().asEntityFullJidOrThrow(); Resourcepart displayName = userid.getResourcepart(); 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 (mucUserEx != null && mucUserEx.getStatus().contains( MUCUser.Status.create( 110 ) ) ) // 110 = Inform user that presence refers to itself { 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 | InterruptedException e) { Log.debug("Unable to retrieve room information for " + chat.getRoom()); } }
Example #13
Source File: GroupChatRoom.java From Spark with Apache License 2.0 | 4 votes |
/** * Handle all presence packets being sent to this Group Chat Room. * * @param stanza the presence packet. */ private void handlePresencePacket( Stanza stanza ) { final Presence presence = (Presence) stanza; if ( presence.getError() != null ) { return; } final EntityFullJid from = presence.getFrom().asEntityFullJidIfPossible(); if (from == null) { return; } final Resourcepart nickname = from.getResourcepart(); final MUCUser mucUser = stanza.getExtension( "x", "http://jabber.org/protocol/muc#user" ); final Set<MUCUser.Status> status = new HashSet<>(); if ( mucUser != null ) { status.addAll( mucUser.getStatus() ); final Destroy destroy = mucUser.getDestroy(); if ( destroy != null ) { UIManager.put( "OptionPane.okButtonText", Res.getString( "ok" ) ); JOptionPane.showMessageDialog( this, Res.getString( "message.room.destroyed", destroy.getReason() ), Res.getString( "title.room.destroyed" ), JOptionPane.INFORMATION_MESSAGE ); leaveChatRoom(); return; } } if ( presence.getType() == Presence.Type.unavailable && !status.contains( MUCUser.Status.NEW_NICKNAME_303 ) ) { if ( currentUserList.contains( from ) ) { if ( pref.isShowJoinLeaveMessagesEnabled() ) { getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.left.room", nickname ), ChatManager.NOTIFICATION_COLOR ); scrollToBottom(); } currentUserList.remove( from ); } } else { if ( !currentUserList.contains( from ) ) { currentUserList.add( from ); getChatInputEditor().setEnabled( true ); if ( pref.isShowJoinLeaveMessagesEnabled() ) { getTranscriptWindow().insertNotificationMessage( Res.getString( "message.user.joined.room", nickname ), ChatManager.NOTIFICATION_COLOR ); scrollToBottom(); } } } }
Example #14
Source File: MUCUserStatusCodeFilter.java From Smack with Apache License 2.0 | 4 votes |
public MUCUserStatusCodeFilter(int statusCode) { this(MUCUser.Status.create(statusCode)); }
Example #15
Source File: MUCUserStatusCodeFilter.java From Smack with Apache License 2.0 | 4 votes |
public MUCUserStatusCodeFilter(MUCUser.Status status) { this.status = status; }
Example #16
Source File: MUCUserProvider.java From Smack with Apache License 2.0 | 4 votes |
/** * Parses a MUCUser stanza (extension sub-packet). * * @param parser the XML parser, positioned at the starting element of the extension. * @return a PacketExtension. * @throws IOException if an I/O error occurred. * @throws XmlPullParserException if an error in the XML parser occurred. */ @Override public MUCUser parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { MUCUser mucUser = new MUCUser(); outerloop: while (true) { switch (parser.next()) { case START_ELEMENT: switch (parser.getName()) { case "invite": mucUser.setInvite(parseInvite(parser)); break; case "item": mucUser.setItem(MUCParserUtils.parseItem(parser)); break; case "password": mucUser.setPassword(parser.nextText()); break; case "status": String statusString = parser.getAttributeValue("", "code"); mucUser.addStatusCode(MUCUser.Status.create(statusString)); break; case "decline": mucUser.setDecline(parseDecline(parser)); break; case "destroy": mucUser.setDestroy(MUCParserUtils.parseDestroy(parser)); break; } break; case END_ELEMENT: if (parser.getDepth() == initialDepth) { break outerloop; } break; default: // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement. break; } } return mucUser; }
Example #17
Source File: Workgroup.java From Smack with Apache License 2.0 | 4 votes |
private void handlePacket(Stanza packet) { if (packet instanceof Message) { Message msg = (Message) packet; // Check to see if the user left the queue. ExtensionElement pe = msg.getExtensionElement("depart-queue", "http://jabber.org/protocol/workgroup"); ExtensionElement queueStatus = msg.getExtensionElement("queue-status", "http://jabber.org/protocol/workgroup"); if (pe != null) { fireQueueDepartedEvent(); } else if (queueStatus != null) { QueueUpdate queueUpdate = (QueueUpdate) queueStatus; if (queueUpdate.getPosition() != -1) { fireQueuePositionEvent(queueUpdate.getPosition()); } if (queueUpdate.getRemaingTime() != -1) { fireQueueTimeEvent(queueUpdate.getRemaingTime()); } } else { // Check if a room invitation was sent and if the sender is the workgroup MUCUser mucUser = MUCUser.from(msg); MUCUser.Invite invite = mucUser != null ? mucUser.getInvite() : null; if (invite != null && workgroupJID.equals(invite.getFrom())) { String sessionID = null; Map<String, List<String>> metaData = null; pe = msg.getExtensionElement(SessionID.ELEMENT_NAME, SessionID.NAMESPACE); if (pe != null) { sessionID = ((SessionID) pe).getSessionID(); } pe = msg.getExtensionElement(MetaData.ELEMENT_NAME, MetaData.NAMESPACE); if (pe != null) { metaData = ((MetaData) pe).getMetaData(); } WorkgroupInvitation inv = new WorkgroupInvitation(connection.getUser(), msg.getFrom(), workgroupJID, sessionID, msg.getBody(), msg.getFrom(), metaData); fireInvitationEvent(inv); } } } }
Example #18
Source File: Workgroup.java From Smack with Apache License 2.0 | 4 votes |
/** * Creates a new workgroup instance using the specified workgroup JID * (eg [email protected]) and XMPP connection. The connection must have * undergone a successful login before being used to construct an instance of * this class. * * @param workgroupJID the JID of the workgroup. * @param connection an XMPP connection which must have already undergone a * successful login. */ public Workgroup(EntityBareJid workgroupJID, XMPPConnection connection) { // Login must have been done before passing in connection. if (!connection.isAuthenticated()) { throw new IllegalStateException("Must login to server before creating workgroup."); } this.workgroupJID = workgroupJID; this.connection = connection; inQueue = false; invitationListeners = new CopyOnWriteArraySet<>(); queueListeners = new CopyOnWriteArraySet<>(); // Register as a queue listener for internal usage by this instance. addQueueListener(new QueueListener() { @Override public void joinedQueue() { inQueue = true; } @Override public void departedQueue() { inQueue = false; queuePosition = -1; queueRemainingTime = -1; } @Override public void queuePositionUpdated(int currentPosition) { queuePosition = currentPosition; } @Override public void queueWaitTimeUpdated(int secondsRemaining) { queueRemainingTime = secondsRemaining; } }); /** * Internal handling of an invitation.Recieving an invitation removes the user from the queue. */ MultiUserChatManager.getInstanceFor(connection).addInvitationListener( new org.jivesoftware.smackx.muc.InvitationListener() { @Override public void invitationReceived(XMPPConnection conn, org.jivesoftware.smackx.muc.MultiUserChat room, EntityJid inviter, String reason, String password, Message message, MUCUser.Invite invitation) { inQueue = false; queuePosition = -1; queueRemainingTime = -1; } }); // Register a packet listener for all the messages sent to this client. StanzaFilter typeFilter = new StanzaTypeFilter(Message.class); connection.addAsyncStanzaListener(new StanzaListener() { @Override public void processStanza(Stanza packet) { handlePacket(packet); } }, typeFilter); }
Example #19
Source File: InvitationRejectionListener.java From Smack with Apache License 2.0 | 2 votes |
/** * Called when the invitee declines the invitation. * * @param invitee the invitee that declined the invitation. (e.g. [email protected]). * @param reason the reason why the invitee declined the invitation. * @param message the message used to decline the invitation. * @param rejection the raw decline found in the message. */ void invitationDeclined(EntityBareJid invitee, String reason, Message message, MUCUser.Decline rejection);
Example #20
Source File: InvitationListener.java From Smack with Apache License 2.0 | 2 votes |
/** * Called when the an invitation to join a MUC room is received.<p> * * If the room is password-protected, the invitee will receive a password to use to join * the room. If the room is members-only, the the invitee may be added to the member list. * * @param conn the XMPPConnection that received the invitation. * @param room the room that invitation refers to. * @param inviter the inviter that sent the invitation. (e.g. [email protected]). * @param reason the reason why the inviter sent the invitation. * @param password the password to use when joining the room. * @param message the message used by the inviter to send the invitation. * @param invitation the raw invitation received with the message. */ void invitationReceived(XMPPConnection conn, MultiUserChat room, EntityJid inviter, String reason, String password, Message message, MUCUser.Invite invitation);
Example #21
Source File: UserStatusListener.java From Smack with Apache License 2.0 | 2 votes |
/** * Called when a user is involuntarily removed from the room. * * @param mucUser the optional muc#user extension element * @param presence the carrier presence * @since 4.4.0 */ default void removed(MUCUser mucUser, Presence presence) { }