mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-02 00:42:07 +01:00
Add a success callback for auto-join on reconnect.
When auto-join on reconnection is success, invoke a callback. Conform to the proper copyright format.
This commit is contained in:
parent
0cd3318b12
commit
f1fb03d08c
2 changed files with 52 additions and 0 deletions
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2019 Vincent Lau
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.muc;
|
||||||
|
|
||||||
|
import org.jxmpp.jid.parts.Resourcepart;
|
||||||
|
|
||||||
|
public interface AutoJoinSuccessCallback {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked after the automatic rejoin rooms on reconnect success.
|
||||||
|
*
|
||||||
|
* @param muc the joined MultiUserChat.
|
||||||
|
* @param nickname nickname used by participant to join the room.
|
||||||
|
*/
|
||||||
|
void autoJoinSuccess(MultiUserChat muc, Resourcepart nickname);
|
||||||
|
|
||||||
|
}
|
|
@ -152,6 +152,8 @@ public final class MultiUserChatManager extends Manager {
|
||||||
|
|
||||||
private AutoJoinFailedCallback autoJoinFailedCallback;
|
private AutoJoinFailedCallback autoJoinFailedCallback;
|
||||||
|
|
||||||
|
private AutoJoinSuccessCallback autoJoinSuccessCallback;
|
||||||
|
|
||||||
private final ServiceDiscoveryManager serviceDiscoveryManager;
|
private final ServiceDiscoveryManager serviceDiscoveryManager;
|
||||||
|
|
||||||
private MultiUserChatManager(XMPPConnection connection) {
|
private MultiUserChatManager(XMPPConnection connection) {
|
||||||
|
@ -200,6 +202,7 @@ public final class MultiUserChatManager extends Manager {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final AutoJoinFailedCallback failedCallback = autoJoinFailedCallback;
|
final AutoJoinFailedCallback failedCallback = autoJoinFailedCallback;
|
||||||
|
final AutoJoinSuccessCallback successCallback = autoJoinSuccessCallback;
|
||||||
for (EntityBareJid mucJid : mucs) {
|
for (EntityBareJid mucJid : mucs) {
|
||||||
MultiUserChat muc = getMultiUserChat(mucJid);
|
MultiUserChat muc = getMultiUserChat(mucJid);
|
||||||
|
|
||||||
|
@ -221,6 +224,9 @@ public final class MultiUserChatManager extends Manager {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
muc.join(nickname);
|
muc.join(nickname);
|
||||||
|
if (successCallback != null) {
|
||||||
|
successCallback.autoJoinSuccess(muc, nickname);
|
||||||
|
}
|
||||||
} catch (NotAMucServiceException | NoResponseException | XMPPErrorException
|
} catch (NotAMucServiceException | NoResponseException | XMPPErrorException
|
||||||
| NotConnectedException | InterruptedException e) {
|
| NotConnectedException | InterruptedException e) {
|
||||||
if (failedCallback != null) {
|
if (failedCallback != null) {
|
||||||
|
@ -481,6 +487,21 @@ public final class MultiUserChatManager extends Manager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a callback invoked by this manager when automatic join on reconnect success.
|
||||||
|
* If successCallback is not <code>null</code>, automatic rejoin will also
|
||||||
|
* be enabled.
|
||||||
|
*
|
||||||
|
* @param successCallback the callback
|
||||||
|
*/
|
||||||
|
public void setAutoJoinSuccessCallback(AutoJoinSuccessCallback successCallback) {
|
||||||
|
autoJoinSuccessCallback = successCallback;
|
||||||
|
if (successCallback != null) {
|
||||||
|
setAutoJoinOnReconnect(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void addJoinedRoom(EntityBareJid room) {
|
void addJoinedRoom(EntityBareJid room) {
|
||||||
joinedRooms.add(room);
|
joinedRooms.add(room);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue