private MultiUserChat createNewMucAndAddToMap(EntityBareJid jid) { MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this); multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat)); return multiUserChat; }
/** * Returns a collection with the XMPP addresses of the Multi-User Chat services. * * @return a collection with the XMPP addresses of the Multi-User Chat services. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public List<DomainBareJid> getMucServiceDomains() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection()); return sdm.findServices(MUCInitialPresence.NAMESPACE, false, false); }
/** * Returns true if the specified user supports the Multi-User Chat protocol. * * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com. * @return a boolean indicating whether the specified user supports the MUC protocol. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public boolean isServiceEnabled(Jid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(user, MUCInitialPresence.NAMESPACE); }
/** * Check if the provided domain bare JID provides a MUC service. * * @param domainBareJid the domain bare JID to check. * @return <code>true</code> if the provided JID provides a MUC service, <code>false</code> otherwise. * @throws NoResponseException * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException * @see <a href="http://xmpp.org/extensions/xep-0045.html#disco-service-features">XEP-45 ยง 6.2 Discovering the Features Supported by a MUC Service</a> * @since 4.2 */ public boolean providesMucService(DomainBareJid domainBareJid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(domainBareJid, MUCInitialPresence.NAMESPACE); }
/** * Returns the discovered information of a given room without actually having to join the room. The server will * provide information only for rooms that are public. * * @param room the name of the room in the form "roomName@service" of which we want to discover its information. * @return the discovered information of a given room without actually having to join the room. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public RoomInfo getRoomInfo(EntityBareJid room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection()).discoverInfo(room); return new RoomInfo(info); }
/** * Returns a List of the rooms where the requested user has joined. The Iterator will contain Strings where each * String represents a room (e.g. room@muc.jabber.org). * * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com. * @return a List of the rooms where the requested user has joined. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException */ public List<EntityBareJid> getJoinedRooms(EntityJid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { // Send the disco packet to the user DiscoverItems result = ServiceDiscoveryManager.getInstanceFor(connection()).discoverItems(user, DISCO_NODE); List<DiscoverItems.Item> items = result.getItems(); List<EntityBareJid> answer = new ArrayList<>(items.size()); // Collect the entityID for each returned item for (DiscoverItems.Item item : items) { EntityBareJid muc = item.getEntityID().asEntityBareJidIfPossible(); if (muc == null) { LOGGER.warning("Not a bare JID: " + item.getEntityID()); continue; } answer.add(muc); } return answer; }
/** * Returns a Map of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name. * Once discovered the rooms hosted by a chat service it is possible to discover more detailed room information or * join the room. * * @param serviceName the service that is hosting the rooms to discover. * @return a map from the room's address to its HostedRoom information. * @throws XMPPErrorException * @throws NoResponseException * @throws NotConnectedException * @throws InterruptedException * @throws NotAMucServiceException * @since 4.3.1 */ public Map<EntityBareJid, HostedRoom> getRoomsHostedBy(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAMucServiceException { if (!providesMucService(serviceName)) { throw new NotAMucServiceException(serviceName); } ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection()); DiscoverItems discoverItems = discoManager.discoverItems(serviceName); List<DiscoverItems.Item> items = discoverItems.getItems(); Map<EntityBareJid, HostedRoom> answer = new HashMap<>(items.size()); for (DiscoverItems.Item item : items) { HostedRoom hostedRoom = new HostedRoom(item); HostedRoom previousRoom = answer.put(hostedRoom.getJid(), hostedRoom); assert previousRoom == null; } return answer; }
/** * Informs the sender of an invitation that the invitee declines the invitation. The rejection will be sent to the * room which in turn will forward the rejection to the inviter. * * @param room the room that sent the original invitation. * @param inviter the inviter of the declined invitation. * @param reason the reason why the invitee is declining the invitation. * @throws NotConnectedException * @throws InterruptedException */ public void decline(EntityBareJid room, EntityBareJid inviter, String reason) throws NotConnectedException, InterruptedException { Message message = new Message(room); // Create the MUCUser packet that will include the rejection MUCUser mucUser = new MUCUser(); MUCUser.Decline decline = new MUCUser.Decline(reason, inviter); mucUser.setDecline(decline); // Add the MUCUser packet that includes the rejection message.addExtension(mucUser); connection().sendStanza(message); }