mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Merge branch '4.2'
This commit is contained in:
commit
81002c4fbd
63 changed files with 391 additions and 266 deletions
|
@ -251,9 +251,10 @@ public final class Roster extends Manager {
|
|||
connection.addSyncStanzaListener(presencePacketListener, PRESENCE_PACKET_FILTER);
|
||||
|
||||
connection.addAsyncStanzaListener(new StanzaListener() {
|
||||
@SuppressWarnings("fallthrough")
|
||||
@Override
|
||||
public void processStanza(Stanza stanza) throws NotConnectedException,
|
||||
InterruptedException {
|
||||
InterruptedException, NotLoggedInException {
|
||||
Presence presence = (Presence) stanza;
|
||||
Jid from = presence.getFrom();
|
||||
SubscribeAnswer subscribeAnswer = null;
|
||||
|
@ -279,13 +280,26 @@ public final class Roster extends Manager {
|
|||
break;
|
||||
}
|
||||
|
||||
if (subscribeAnswer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Presence response;
|
||||
if (subscribeAnswer == SubscribeAnswer.Approve) {
|
||||
switch (subscribeAnswer) {
|
||||
case ApproveAndAlsoRequestIfRequired:
|
||||
BareJid bareFrom = from.asBareJid();
|
||||
RosterUtil.askForSubscriptionIfRequired(Roster.this, bareFrom);
|
||||
// The fall through is intended.
|
||||
case Approve:
|
||||
response = new Presence(Presence.Type.subscribed);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
case Deny:
|
||||
response = new Presence(Presence.Type.unsubscribed);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
response.setTo(presence.getFrom());
|
||||
connection.sendStanza(response);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.locks.Condition;
|
|||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.FeatureNotSupportedException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
@ -86,6 +87,33 @@ public class RosterUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-approve the subscription if it is required and possible.
|
||||
*
|
||||
* @param roster The roster which should be used for the pre-approval.
|
||||
* @param jid The XMPP address which should be pre-approved.
|
||||
* @throws NotLoggedInException
|
||||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
* @since 4.2.2
|
||||
*/
|
||||
public static void preApproveSubscriptionIfRequiredAndPossible(Roster roster, BareJid jid)
|
||||
throws NotLoggedInException, NotConnectedException, InterruptedException {
|
||||
if (!roster.isSubscriptionPreApprovalSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RosterEntry entry = roster.getEntry(jid);
|
||||
if (entry == null || (!entry.canSeeMyPresence() && !entry.isApproved())) {
|
||||
try {
|
||||
roster.preApprove(jid);
|
||||
} catch (FeatureNotSupportedException e) {
|
||||
// Should never happen since we checked for the feature above.
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void askForSubscriptionIfRequired(Roster roster, BareJid jid)
|
||||
throws NotLoggedInException, NotConnectedException, InterruptedException {
|
||||
RosterEntry entry = roster.getEntry(jid);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015 Florian Schmaus
|
||||
* Copyright 2015-2017 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -23,13 +23,29 @@ import org.jxmpp.jid.Jid;
|
|||
|
||||
|
||||
/**
|
||||
* Handle incoming requests to subscribe to our presence.
|
||||
* Handle incoming requests to subscribe to our presence. The
|
||||
* {@link #processSubscribe(Jid, Presence)} method may return a subscribe
|
||||
* answer. If no subscribe answer is returned, the next listener will be
|
||||
* notified and asked. If no listener returns an answer, then nothing happens.
|
||||
*
|
||||
*/
|
||||
public interface SubscribeListener {
|
||||
|
||||
public enum SubscribeAnswer {
|
||||
/**
|
||||
* Approve the subscription request.
|
||||
*/
|
||||
Approve,
|
||||
|
||||
/**
|
||||
* Approve the subscription request and also request subscription from the other party if not already subscribed.
|
||||
* @since 4.2.2
|
||||
*/
|
||||
ApproveAndAlsoRequestIfRequired,
|
||||
|
||||
/**
|
||||
* Deny the subscription request.
|
||||
*/
|
||||
Deny,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue