001/** 002 * 003 * Copyright © 2014-2024 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.muc; 018 019import java.lang.ref.WeakReference; 020import java.util.ArrayList; 021import java.util.Collections; 022import java.util.HashMap; 023import java.util.HashSet; 024import java.util.List; 025import java.util.Map; 026import java.util.Set; 027import java.util.WeakHashMap; 028import java.util.concurrent.CopyOnWriteArrayList; 029import java.util.concurrent.CopyOnWriteArraySet; 030import java.util.logging.Level; 031import java.util.logging.Logger; 032 033import org.jivesoftware.smack.ConnectionCreationListener; 034import org.jivesoftware.smack.ConnectionListener; 035import org.jivesoftware.smack.Manager; 036import org.jivesoftware.smack.SmackException.NoResponseException; 037import org.jivesoftware.smack.SmackException.NotConnectedException; 038import org.jivesoftware.smack.StanzaListener; 039import org.jivesoftware.smack.XMPPConnection; 040import org.jivesoftware.smack.XMPPConnectionRegistry; 041import org.jivesoftware.smack.XMPPException.XMPPErrorException; 042import org.jivesoftware.smack.filter.AndFilter; 043import org.jivesoftware.smack.filter.ExtensionElementFilter; 044import org.jivesoftware.smack.filter.MessageTypeFilter; 045import org.jivesoftware.smack.filter.NotFilter; 046import org.jivesoftware.smack.filter.StanzaExtensionFilter; 047import org.jivesoftware.smack.filter.StanzaFilter; 048import org.jivesoftware.smack.filter.StanzaTypeFilter; 049import org.jivesoftware.smack.packet.Message; 050import org.jivesoftware.smack.packet.MessageBuilder; 051import org.jivesoftware.smack.packet.Stanza; 052import org.jivesoftware.smack.util.Async; 053import org.jivesoftware.smack.util.CleaningWeakReferenceMap; 054 055import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider; 056import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; 057import org.jivesoftware.smackx.disco.packet.DiscoverInfo; 058import org.jivesoftware.smackx.disco.packet.DiscoverItems; 059import org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException; 060import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException; 061import org.jivesoftware.smackx.muc.packet.GroupChatInvitation; 062import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; 063import org.jivesoftware.smackx.muc.packet.MUCUser; 064 065import org.jxmpp.jid.DomainBareJid; 066import org.jxmpp.jid.EntityBareJid; 067import org.jxmpp.jid.EntityFullJid; 068import org.jxmpp.jid.EntityJid; 069import org.jxmpp.jid.Jid; 070import org.jxmpp.jid.parts.Resourcepart; 071import org.jxmpp.util.cache.ExpirationCache; 072 073/** 074 * A manager for Multi-User Chat rooms. 075 * <p> 076 * Use {@link #getMultiUserChat(EntityBareJid)} to retrieve an object representing a Multi-User Chat room. 077 * </p> 078 * <p> 079 * <b>Automatic rejoin:</b> The manager supports automatic rejoin of MultiUserChat rooms once the connection got 080 * re-established. This mechanism is disabled by default. To enable it, use {@link #setAutoJoinOnReconnect(boolean)}. 081 * You can set a {@link AutoJoinFailedCallback} via {@link #setAutoJoinFailedCallback(AutoJoinFailedCallback)} to get 082 * notified if this mechanism failed for some reason. Note that as soon as rejoining for a single room failed, no 083 * further attempts will be made for the other rooms. 084 * </p> 085 * 086 * Note: 087 * For inviting other users to a group chat or listening for such invitations, take a look at the 088 * {@link DirectMucInvitationManager} which provides an implementation of XEP-0249: Direct MUC Invitations. 089 * 090 * @see <a href="http://xmpp.org/extensions/xep-0045.html">XEP-0045: Multi-User Chat</a> 091 */ 092public final class MultiUserChatManager extends Manager { 093 private static final String DISCO_NODE = MUCInitialPresence.NAMESPACE + "#rooms"; 094 095 private static final Logger LOGGER = Logger.getLogger(MultiUserChatManager.class.getName()); 096 097 static { 098 XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() { 099 @Override 100 public void connectionCreated(final XMPPConnection connection) { 101 // Set on every established connection that this client supports the Multi-User 102 // Chat protocol. This information will be used when another client tries to 103 // discover whether this client supports MUC or not. 104 ServiceDiscoveryManager.getInstanceFor(connection).addFeature(MUCInitialPresence.NAMESPACE); 105 106 // Set the NodeInformationProvider that will provide information about the 107 // joined rooms whenever a disco request is received 108 final WeakReference<XMPPConnection> weakRefConnection = new WeakReference<XMPPConnection>(connection); 109 ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(DISCO_NODE, 110 new AbstractNodeInformationProvider() { 111 @SuppressWarnings({"JavaUtilDate", "MixedMutabilityReturnType"}) 112 @Override 113 public List<DiscoverItems.Item> getNodeItems() { 114 XMPPConnection connection = weakRefConnection.get(); 115 if (connection == null) 116 return Collections.emptyList(); 117 Set<EntityBareJid> joinedRooms = MultiUserChatManager.getInstanceFor(connection).getJoinedRooms(); 118 List<DiscoverItems.Item> answer = new ArrayList<DiscoverItems.Item>(); 119 for (EntityBareJid room : joinedRooms) { 120 answer.add(new DiscoverItems.Item(room)); 121 } 122 return answer; 123 } 124 }); 125 } 126 }); 127 } 128 129 private static final Map<XMPPConnection, MultiUserChatManager> INSTANCES = new WeakHashMap<XMPPConnection, MultiUserChatManager>(); 130 131 /** 132 * Get a instance of a multi user chat manager for the given connection. 133 * 134 * @param connection TODO javadoc me please 135 * @return a multi user chat manager. 136 */ 137 public static synchronized MultiUserChatManager getInstanceFor(XMPPConnection connection) { 138 MultiUserChatManager multiUserChatManager = INSTANCES.get(connection); 139 if (multiUserChatManager == null) { 140 multiUserChatManager = new MultiUserChatManager(connection); 141 INSTANCES.put(connection, multiUserChatManager); 142 } 143 return multiUserChatManager; 144 } 145 146 private static final StanzaFilter INVITATION_FILTER = new AndFilter(StanzaTypeFilter.MESSAGE, new StanzaExtensionFilter(new MUCUser()), 147 new NotFilter(MessageTypeFilter.ERROR)); 148 149 private static final StanzaFilter DIRECT_INVITATION_FILTER = 150 new AndFilter(StanzaTypeFilter.MESSAGE, 151 new ExtensionElementFilter<GroupChatInvitation>(GroupChatInvitation.class), 152 NotFilter.of(MUCUser.class), 153 new NotFilter(MessageTypeFilter.ERROR)); 154 155 private static final ExpirationCache<DomainBareJid, DiscoverInfo> KNOWN_MUC_SERVICES = new ExpirationCache<>( 156 100, 1000 * 60 * 60 * 24); 157 158 private static final Set<MucMessageInterceptor> DEFAULT_MESSAGE_INTERCEPTORS = new HashSet<>(); 159 160 private final Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>(); 161 162 /** 163 * The XMPP addresses of currently joined rooms. 164 */ 165 private final Set<EntityBareJid> joinedRooms = new CopyOnWriteArraySet<>(); 166 167 /** 168 * A Map of MUC JIDs to {@link MultiUserChat} instances. We use weak references for the values in order to allow 169 * those instances to get garbage collected. Note that MultiUserChat instances can not get garbage collected while 170 * the user is joined, because then the MUC will have PacketListeners added to the XMPPConnection. 171 */ 172 private final Map<EntityBareJid, WeakReference<MultiUserChat>> multiUserChats = new CleaningWeakReferenceMap<>(); 173 174 private boolean autoJoinOnReconnect; 175 176 private AutoJoinFailedCallback autoJoinFailedCallback; 177 178 private AutoJoinSuccessCallback autoJoinSuccessCallback; 179 180 private final ServiceDiscoveryManager serviceDiscoveryManager; 181 182 private MultiUserChatManager(XMPPConnection connection) { 183 super(connection); 184 serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); 185 // Listens for all messages that include a MUCUser extension and fire the invitation 186 // listeners if the message includes an invitation. 187 StanzaListener invitationPacketListener = new StanzaListener() { 188 @Override 189 public void processStanza(Stanza packet) { 190 final Message message = (Message) packet; 191 // Get the MUCUser extension 192 final MUCUser mucUser = MUCUser.from(message); 193 // Check if the MUCUser extension includes an invitation 194 if (mucUser.getInvite() != null) { 195 EntityBareJid mucJid = message.getFrom().asEntityBareJidIfPossible(); 196 if (mucJid == null) { 197 LOGGER.warning("Invite to non bare JID: '" + message.toXML() + "'"); 198 return; 199 } 200 // Fire event for invitation listeners 201 final MultiUserChat muc = getMultiUserChat(mucJid); 202 final XMPPConnection connection = connection(); 203 final MUCUser.Invite invite = mucUser.getInvite(); 204 final EntityJid from = invite.getFrom(); 205 final String reason = invite.getReason(); 206 final String password = mucUser.getPassword(); 207 for (final InvitationListener listener : invitationsListeners) { 208 listener.invitationReceived(connection, muc, from, reason, password, message, invite); 209 } 210 } 211 } 212 }; 213 connection.addAsyncStanzaListener(invitationPacketListener, INVITATION_FILTER); 214 215 // Listens for all messages that include an XEP-0249 GroupChatInvitation extension and fire the invitation 216 // listeners 217 StanzaListener directInvitationStanzaListener = new StanzaListener() { 218 @Override 219 public void processStanza(Stanza stanza) { 220 final Message message = (Message) stanza; 221 GroupChatInvitation invite = 222 stanza.getExtension(GroupChatInvitation.class); 223 224 // Fire event for invitation listeners 225 final MultiUserChat muc = getMultiUserChat(invite.getRoomAddress()); 226 final XMPPConnection connection = connection(); 227 final EntityJid from = message.getFrom().asEntityJidIfPossible(); 228 if (from == null) { 229 LOGGER.warning("Group Chat Invitation from non entity JID in '" + message + "'"); 230 return; 231 } 232 final String reason = invite.getReason(); 233 final String password = invite.getPassword(); 234 final MUCUser.Invite mucInvite = new MUCUser.Invite(reason, from, connection.getUser().asEntityBareJid()); 235 for (final InvitationListener listener : invitationsListeners) { 236 listener.invitationReceived(connection, muc, from, reason, password, message, mucInvite); 237 } 238 } 239 }; 240 connection.addAsyncStanzaListener(directInvitationStanzaListener, DIRECT_INVITATION_FILTER); 241 242 connection.addConnectionListener(new ConnectionListener() { 243 @Override 244 public void authenticated(XMPPConnection connection, boolean resumed) { 245 if (resumed) return; 246 if (!autoJoinOnReconnect) return; 247 248 final Set<EntityBareJid> mucs = getJoinedRooms(); 249 if (mucs.isEmpty()) return; 250 251 Async.go(new Runnable() { 252 @Override 253 public void run() { 254 final AutoJoinFailedCallback failedCallback = autoJoinFailedCallback; 255 final AutoJoinSuccessCallback successCallback = autoJoinSuccessCallback; 256 for (EntityBareJid mucJid : mucs) { 257 MultiUserChat muc = getMultiUserChat(mucJid); 258 259 if (!muc.isJoined()) return; 260 261 Resourcepart nickname = muc.getNickname(); 262 if (nickname == null) return; 263 264 try { 265 muc.leave(); 266 } catch (NotConnectedException | InterruptedException | MucNotJoinedException 267 | NoResponseException | XMPPErrorException e) { 268 if (failedCallback != null) { 269 failedCallback.autoJoinFailed(muc, e); 270 } else { 271 LOGGER.log(Level.WARNING, "Could not leave room", e); 272 } 273 return; 274 } 275 try { 276 muc.join(nickname); 277 if (successCallback != null) { 278 successCallback.autoJoinSuccess(muc, nickname); 279 } 280 } catch (NotAMucServiceException | NoResponseException | XMPPErrorException 281 | NotConnectedException | InterruptedException e) { 282 if (failedCallback != null) { 283 failedCallback.autoJoinFailed(muc, e); 284 } else { 285 LOGGER.log(Level.WARNING, "Could not leave room", e); 286 } 287 return; 288 } 289 } 290 } 291 292 }); 293 } 294 }); 295 } 296 297 /** 298 * Creates a multi user chat. Note: no information is sent to or received from the server until you attempt to 299 * {@link MultiUserChat#join(org.jxmpp.jid.parts.Resourcepart) join} the chat room. On some server implementations, the room will not be 300 * created until the first person joins it. 301 * <p> 302 * Most XMPP servers use a sub-domain for the chat service (e.g.chat.example.com for the XMPP server example.com). 303 * You must ensure that the room address you're trying to connect to includes the proper chat sub-domain. 304 * </p> 305 * 306 * @param jid the name of the room in the form "roomName@service", where "service" is the hostname at which the 307 * multi-user chat service is running. Make sure to provide a valid JID. 308 * @return MultiUserChat instance of the room with the given jid. 309 */ 310 public synchronized MultiUserChat getMultiUserChat(EntityBareJid jid) { 311 WeakReference<MultiUserChat> weakRefMultiUserChat = multiUserChats.get(jid); 312 if (weakRefMultiUserChat == null) { 313 return createNewMucAndAddToMap(jid); 314 } 315 MultiUserChat multiUserChat = weakRefMultiUserChat.get(); 316 if (multiUserChat == null) { 317 return createNewMucAndAddToMap(jid); 318 } 319 return multiUserChat; 320 } 321 322 public static boolean addDefaultMessageInterceptor(MucMessageInterceptor messageInterceptor) { 323 synchronized (DEFAULT_MESSAGE_INTERCEPTORS) { 324 return DEFAULT_MESSAGE_INTERCEPTORS.add(messageInterceptor); 325 } 326 } 327 328 public static boolean removeDefaultMessageInterceptor(MucMessageInterceptor messageInterceptor) { 329 synchronized (DEFAULT_MESSAGE_INTERCEPTORS) { 330 return DEFAULT_MESSAGE_INTERCEPTORS.remove(messageInterceptor); 331 } 332 } 333 334 private MultiUserChat createNewMucAndAddToMap(EntityBareJid jid) { 335 MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this); 336 multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat)); 337 return multiUserChat; 338 } 339 340 /** 341 * Returns true if the specified user supports the Multi-User Chat protocol. 342 * 343 * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com. 344 * @return a boolean indicating whether the specified user supports the MUC protocol. 345 * @throws XMPPErrorException if there was an XMPP error returned. 346 * @throws NoResponseException if there was no response from the remote entity. 347 * @throws NotConnectedException if the XMPP connection is not connected. 348 * @throws InterruptedException if the calling thread was interrupted. 349 */ 350 public boolean isServiceEnabled(Jid user) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { 351 return serviceDiscoveryManager.supportsFeature(user, MUCInitialPresence.NAMESPACE); 352 } 353 354 /** 355 * Returns a Set of the rooms where the user has joined. The Iterator will contain Strings where each String 356 * represents a room (e.g. room@muc.jabber.org). 357 * 358 * Note: In order to get a list of bookmarked (but not necessarily joined) conferences, use 359 * {@link org.jivesoftware.smackx.bookmarks.BookmarkManager#getBookmarkedConferences()}. 360 * 361 * @return a List of the rooms where the user has joined using a given connection. 362 */ 363 public Set<EntityBareJid> getJoinedRooms() { 364 return Collections.unmodifiableSet(joinedRooms); 365 } 366 367 /** 368 * Returns a List of the rooms where the requested user has joined. The Iterator will contain Strings where each 369 * String represents a room (e.g. room@muc.jabber.org). 370 * 371 * @param user the user to check. A fully qualified xmpp ID, e.g. jdoe@example.com. 372 * @return a List of the rooms where the requested user has joined. 373 * @throws XMPPErrorException if there was an XMPP error returned. 374 * @throws NoResponseException if there was no response from the remote entity. 375 * @throws NotConnectedException if the XMPP connection is not connected. 376 * @throws InterruptedException if the calling thread was interrupted. 377 */ 378 public List<EntityBareJid> getJoinedRooms(EntityFullJid user) throws NoResponseException, XMPPErrorException, 379 NotConnectedException, InterruptedException { 380 // Send the disco packet to the user 381 DiscoverItems result = serviceDiscoveryManager.discoverItems(user, DISCO_NODE); 382 List<DiscoverItems.Item> items = result.getItems(); 383 List<EntityBareJid> answer = new ArrayList<>(items.size()); 384 // Collect the entityID for each returned item 385 for (DiscoverItems.Item item : items) { 386 EntityBareJid muc = item.getEntityID().asEntityBareJidIfPossible(); 387 if (muc == null) { 388 LOGGER.warning("Not a bare JID: " + item.getEntityID()); 389 continue; 390 } 391 answer.add(muc); 392 } 393 return answer; 394 } 395 396 /** 397 * Returns the discovered information of a given room without actually having to join the room. The server will 398 * provide information only for rooms that are public. 399 * 400 * @param room the name of the room in the form "roomName@service" of which we want to discover its information. 401 * @return the discovered information of a given room without actually having to join the room. 402 * @throws XMPPErrorException if there was an XMPP error returned. 403 * @throws NoResponseException if there was no response from the remote entity. 404 * @throws NotConnectedException if the XMPP connection is not connected. 405 * @throws InterruptedException if the calling thread was interrupted. 406 */ 407 public RoomInfo getRoomInfo(EntityBareJid room) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { 408 DiscoverInfo info = serviceDiscoveryManager.discoverInfo(room); 409 return new RoomInfo(info); 410 } 411 412 /** 413 * Returns a collection with the XMPP addresses of the Multi-User Chat services. 414 * 415 * @return a collection with the XMPP addresses of the Multi-User Chat services. 416 * @throws XMPPErrorException if there was an XMPP error returned. 417 * @throws NoResponseException if there was no response from the remote entity. 418 * @throws NotConnectedException if the XMPP connection is not connected. 419 * @throws InterruptedException if the calling thread was interrupted. 420 */ 421 public List<DomainBareJid> getMucServiceDomains() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { 422 return serviceDiscoveryManager.findServices(MUCInitialPresence.NAMESPACE, false, false); 423 } 424 425 /** 426 * Check if the provided domain bare JID provides a MUC service. 427 * 428 * @param domainBareJid the domain bare JID to check. 429 * @return <code>true</code> if the provided JID provides a MUC service, <code>false</code> otherwise. 430 * @throws NoResponseException if there was no response from the remote entity. 431 * @throws XMPPErrorException if there was an XMPP error returned. 432 * @throws NotConnectedException if the XMPP connection is not connected. 433 * @throws InterruptedException if the calling thread was interrupted. 434 * @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> 435 * @since 4.2 436 */ 437 public boolean providesMucService(DomainBareJid domainBareJid) throws NoResponseException, 438 XMPPErrorException, NotConnectedException, InterruptedException { 439 return getMucServiceDiscoInfo(domainBareJid) != null; 440 } 441 442 DiscoverInfo getMucServiceDiscoInfo(DomainBareJid mucServiceAddress) 443 throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { 444 DiscoverInfo discoInfo = KNOWN_MUC_SERVICES.get(mucServiceAddress); 445 if (discoInfo != null) { 446 return discoInfo; 447 } 448 449 discoInfo = serviceDiscoveryManager.discoverInfo(mucServiceAddress); 450 if (!discoInfo.containsFeature(MUCInitialPresence.NAMESPACE)) { 451 return null; 452 } 453 454 KNOWN_MUC_SERVICES.put(mucServiceAddress, discoInfo); 455 return discoInfo; 456 } 457 458 /** 459 * Returns a Map of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name. 460 * Once discovered the rooms hosted by a chat service it is possible to discover more detailed room information or 461 * join the room. 462 * 463 * @param serviceName the service that is hosting the rooms to discover. 464 * @return a map from the room's address to its HostedRoom information. 465 * @throws XMPPErrorException if there was an XMPP error returned. 466 * @throws NoResponseException if there was no response from the remote entity. 467 * @throws NotConnectedException if the XMPP connection is not connected. 468 * @throws InterruptedException if the calling thread was interrupted. 469 * @throws NotAMucServiceException if the entity is not a MUC service. 470 * @since 4.3.1 471 */ 472 public Map<EntityBareJid, HostedRoom> getRoomsHostedBy(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, 473 NotConnectedException, InterruptedException, NotAMucServiceException { 474 if (!providesMucService(serviceName)) { 475 throw new NotAMucServiceException(serviceName); 476 } 477 DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(serviceName); 478 List<DiscoverItems.Item> items = discoverItems.getItems(); 479 480 Map<EntityBareJid, HostedRoom> answer = new HashMap<>(items.size()); 481 for (DiscoverItems.Item item : items) { 482 HostedRoom hostedRoom = new HostedRoom(item); 483 HostedRoom previousRoom = answer.put(hostedRoom.getJid(), hostedRoom); 484 assert previousRoom == null; 485 } 486 487 return answer; 488 } 489 490 /** 491 * Informs the sender of an invitation that the invitee declines the invitation. The rejection will be sent to the 492 * room which in turn will forward the rejection to the inviter. 493 * 494 * @param room the room that sent the original invitation. 495 * @param inviter the inviter of the declined invitation. 496 * @param reason the reason why the invitee is declining the invitation. 497 * @throws NotConnectedException if the XMPP connection is not connected. 498 * @throws InterruptedException if the calling thread was interrupted. 499 */ 500 public void decline(EntityBareJid room, EntityBareJid inviter, String reason) throws NotConnectedException, InterruptedException { 501 XMPPConnection connection = connection(); 502 503 MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza().to(room); 504 505 // Create the MUCUser packet that will include the rejection 506 MUCUser mucUser = new MUCUser(); 507 MUCUser.Decline decline = new MUCUser.Decline(reason, inviter); 508 mucUser.setDecline(decline); 509 // Add the MUCUser packet that includes the rejection 510 messageBuilder.addExtension(mucUser); 511 512 connection.sendStanza(messageBuilder.build()); 513 } 514 515 /** 516 * Adds a listener to invitation notifications. The listener will be fired anytime an invitation is received. 517 * 518 * @param listener an invitation listener. 519 */ 520 public void addInvitationListener(InvitationListener listener) { 521 invitationsListeners.add(listener); 522 } 523 524 /** 525 * Removes a listener to invitation notifications. The listener will be fired anytime an invitation is received. 526 * 527 * @param listener an invitation listener. 528 */ 529 public void removeInvitationListener(InvitationListener listener) { 530 invitationsListeners.remove(listener); 531 } 532 533 /** 534 * If automatic join on reconnect is enabled, then the manager will try to auto join MUC rooms after the connection 535 * got re-established. 536 * 537 * @param autoJoin <code>true</code> to enable, <code>false</code> to disable. 538 */ 539 public void setAutoJoinOnReconnect(boolean autoJoin) { 540 autoJoinOnReconnect = autoJoin; 541 } 542 543 /** 544 * Set a callback invoked by this manager when automatic join on reconnect failed. If failedCallback is not 545 * <code>null</code>, then automatic rejoin get also enabled. 546 * 547 * @param failedCallback the callback. 548 */ 549 public void setAutoJoinFailedCallback(AutoJoinFailedCallback failedCallback) { 550 autoJoinFailedCallback = failedCallback; 551 if (failedCallback != null) { 552 setAutoJoinOnReconnect(true); 553 } 554 } 555 556 /** 557 * Set a callback invoked by this manager when automatic join on reconnect success. 558 * If successCallback is not <code>null</code>, automatic rejoin will also 559 * be enabled. 560 * 561 * @param successCallback the callback 562 */ 563 public void setAutoJoinSuccessCallback(AutoJoinSuccessCallback successCallback) { 564 autoJoinSuccessCallback = successCallback; 565 if (successCallback != null) { 566 setAutoJoinOnReconnect(true); 567 } 568 } 569 570 571 void addJoinedRoom(EntityBareJid room) { 572 joinedRooms.add(room); 573 } 574 575 void removeJoinedRoom(EntityBareJid room) { 576 joinedRooms.remove(room); 577 } 578 579 static CopyOnWriteArrayList<MucMessageInterceptor> getMessageInterceptors() { 580 synchronized (DEFAULT_MESSAGE_INTERCEPTORS) { 581 return new CopyOnWriteArrayList<>(DEFAULT_MESSAGE_INTERCEPTORS); 582 } 583 } 584}