mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Merge pull request #299 from magnetsystems/autojoin-callback-on-reconnect
Autojoin callback on reconnect
This commit is contained in:
commit
60db42e2f4
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);
|
||||||
|
|
||||||
|
}
|
|
@ -153,6 +153,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) {
|
||||||
|
@ -201,6 +203,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);
|
||||||
|
|
||||||
|
@ -222,6 +225,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) {
|
||||||
|
@ -482,6 +488,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