mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Add SubscribeAnswer.ApproveAndAlsoRequestIfRequired
This commit is contained in:
parent
9a34e9e870
commit
65b4f506dc
7 changed files with 50 additions and 13 deletions
|
@ -249,9 +249,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;
|
||||
|
@ -277,13 +278,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);
|
||||
}
|
||||
|
|
|
@ -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