mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-15 03:52:05 +01:00
Support more subscription modes.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1959 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
e65006c770
commit
e68209dd3d
1 changed files with 67 additions and 6 deletions
|
@ -62,6 +62,12 @@ import java.util.*;
|
||||||
* Represents a user's roster, which is the collection of users a person receives
|
* Represents a user's roster, which is the collection of users a person receives
|
||||||
* presence updates for. Roster items are categorized into groups for easier management.<p>
|
* presence updates for. Roster items are categorized into groups for easier management.<p>
|
||||||
*
|
*
|
||||||
|
* Others users may attempt to subscribe to this user using a subscription request. Three
|
||||||
|
* modes are supported for handling these requests: <ul>
|
||||||
|
* <li> SUBSCRIPTION_ACCEPT_ALL -- accept all subscription requests.
|
||||||
|
* <li> SUBCRIPTION_REJECT_ALL -- reject all subscription requests.
|
||||||
|
* <li> SUBSCRIPTION_MANUAL -- manually process all subscription requests. </ul>
|
||||||
|
*
|
||||||
* All presence subscription requests are automatically approved to this client
|
* All presence subscription requests are automatically approved to this client
|
||||||
* are automatically approved. This logic will be updated in the future to allow for
|
* are automatically approved. This logic will be updated in the future to allow for
|
||||||
* pluggable behavior.
|
* pluggable behavior.
|
||||||
|
@ -71,6 +77,25 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class Roster {
|
public class Roster {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically accept all subscription requests. This is the default mode
|
||||||
|
* and is suitable for simple client. More complex client will likely wish to
|
||||||
|
* handle subscription requests manually.
|
||||||
|
*/
|
||||||
|
public static final int SUBCRIPTION_ACCEPT_ALL = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically reject all subscription requests.
|
||||||
|
*/
|
||||||
|
public static final int SUBCRIPTION_REJECT_ALL = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscription requests are ignored, which means they must be manually
|
||||||
|
* processed by registering a listener for presence packets and then looking
|
||||||
|
* for any presence requests that have the type Presence.Type.SUBSCRIBE.
|
||||||
|
*/
|
||||||
|
public static final int SUBSCRIPTION_MANUAL = 2;
|
||||||
|
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
private Map groups;
|
private Map groups;
|
||||||
private List unfiledEntries;
|
private List unfiledEntries;
|
||||||
|
@ -80,6 +105,8 @@ public class Roster {
|
||||||
// has been recieved and processed.
|
// has been recieved and processed.
|
||||||
boolean rosterInitialized = false;
|
boolean rosterInitialized = false;
|
||||||
|
|
||||||
|
private int subscriptionMode = SUBCRIPTION_ACCEPT_ALL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new roster.
|
* Creates a new roster.
|
||||||
*
|
*
|
||||||
|
@ -99,6 +126,32 @@ public class Roster {
|
||||||
connection.addPacketListener(new PresencePacketListener(), presenceFilter);
|
connection.addPacketListener(new PresencePacketListener(), presenceFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the subscription processing mode, which dictates what action
|
||||||
|
* Smack will take when subscription requests from other users are made.
|
||||||
|
*
|
||||||
|
* @return the subscription mode.
|
||||||
|
*/
|
||||||
|
public int getSubscriptionMode() {
|
||||||
|
return subscriptionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the subscription processing mode, which dictates what action
|
||||||
|
* Smack will take when subscription requests from other users are made.
|
||||||
|
*
|
||||||
|
* @param subscriptionMode the subscription mode.
|
||||||
|
*/
|
||||||
|
public void setSubscriptionMode(int subscriptionMode) {
|
||||||
|
if (subscriptionMode != SUBCRIPTION_ACCEPT_ALL &&
|
||||||
|
subscriptionMode != SUBCRIPTION_REJECT_ALL &&
|
||||||
|
subscriptionMode != SUBSCRIPTION_MANUAL)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid mode.");
|
||||||
|
}
|
||||||
|
this.subscriptionMode = subscriptionMode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the entire roster from the server. This is an asynchronous operation,
|
* Reloads the entire roster from the server. This is an asynchronous operation,
|
||||||
* which means the method will return immediately, and the roster will be
|
* which means the method will return immediately, and the roster will be
|
||||||
|
@ -285,10 +338,19 @@ public class Roster {
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (presence.getType() == Presence.Type.SUBSCRIBE) {
|
else if (presence.getType() == Presence.Type.SUBSCRIBE) {
|
||||||
// Accept all subscription requests.
|
if (subscriptionMode == SUBCRIPTION_ACCEPT_ALL) {
|
||||||
Presence response = new Presence(Presence.Type.SUBSCRIBED);
|
// Accept all subscription requests.
|
||||||
response.setTo(presence.getFrom());
|
Presence response = new Presence(Presence.Type.SUBSCRIBED);
|
||||||
connection.sendPacket(response);
|
response.setTo(presence.getFrom());
|
||||||
|
connection.sendPacket(response);
|
||||||
|
}
|
||||||
|
else if (subscriptionMode == SUBCRIPTION_REJECT_ALL) {
|
||||||
|
// Reject all subscription requests.
|
||||||
|
Presence response = new Presence(Presence.Type.UNSUBSCRIBED);
|
||||||
|
response.setTo(presence.getFrom());
|
||||||
|
connection.sendPacket(response);
|
||||||
|
}
|
||||||
|
// Otherwise, in manual mode so ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -303,8 +365,7 @@ public class Roster {
|
||||||
for (Iterator i=rosterPacket.getRosterItems(); i.hasNext(); ) {
|
for (Iterator i=rosterPacket.getRosterItems(); i.hasNext(); ) {
|
||||||
RosterPacket.Item item = (RosterPacket.Item)i.next();
|
RosterPacket.Item item = (RosterPacket.Item)i.next();
|
||||||
if (item.getItemType() == RosterPacket.ItemType.TO ||
|
if (item.getItemType() == RosterPacket.ItemType.TO ||
|
||||||
item.getItemType() == RosterPacket.ItemType.BOTH ||
|
item.getItemType() == RosterPacket.ItemType.BOTH)
|
||||||
item.getItemType() == RosterPacket.ItemType.PENDING)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue