Unverified Commit 4f1f75e9 authored by Dave Cridland's avatar Dave Cridland Committed by GitHub

Merge pull request #753 from Gugli/roster-restrictions-interceptor

Allow code reuse from plugins
parents 6286c4ac fbc41a5b
......@@ -477,20 +477,24 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
* <p>Indicate a state change.</p>
* <p>Use nulls to indicate fields that should not be changed.</p>
*/
private static class Change {
public static class Change {
public Change(RosterItem.RecvType recv, RosterItem.SubType sub, RosterItem.AskType ask) {
newRecv = recv;
newSub = sub;
newAsk = ask;
}
public RosterItem.RecvType newRecv;
public RosterItem.SubType newSub;
public RosterItem.AskType newAsk;
public RosterItem.RecvType getNewRecv() { return newRecv; }
public RosterItem.SubType getNewSub() { return newSub; }
public RosterItem.AskType getNewAsk() { return newAsk; }
private RosterItem.RecvType newRecv;
private RosterItem.SubType newSub;
private RosterItem.AskType newAsk;
}
/**
* Determine and call the update method based on the item's subscription state.
* Determine the changes to apply to the item, according to its subscription state.
* The method also turns the action and sending status into an integer code
* for easier processing (switch statements).
* <p/>
......@@ -503,19 +507,32 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
* @param item The item to be updated
* @param action The new state change request
* @param isSending True if the roster owner of the item is sending the new state change request
* @return Change changes to apply to the item
*/
private static void updateState(RosterItem item, Presence.Type action, boolean isSending) {
Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(item.getSubStatus());
public static Change getStateChange(RosterItem.SubType itemSubType, Presence.Type action, boolean isSending) {
Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(itemSubType);
Map<Presence.Type, Change> changeTable = srTable.get(isSending ? "send" : "recv");
Change change = changeTable.get(action);
if (change.newAsk != null && change.newAsk != item.getAskStatus()) {
item.setAskStatus(change.newAsk);
return changeTable.get(action);
}
/**
* Determine and call the update method based on the item's subscription state.
* <p/>
*
* @param item The item to be updated
* @param action The new state change request
* @param isSending True if the roster owner of the item is sending the new state change request
*/
private static void updateState(RosterItem item, Presence.Type action, boolean isSending) {
Change change = getStateChange(item.getSubStatus(), action, isSending);
if (change.getNewAsk() != null && change.getNewAsk() != item.getAskStatus()) {
item.setAskStatus(change.getNewAsk());
}
if (change.newSub != null && change.newSub != item.getSubStatus()) {
item.setSubStatus(change.newSub);
if (change.getNewSub() != null && change.getNewSub() != item.getSubStatus()) {
item.setSubStatus(change.getNewSub());
}
if (change.newRecv != null && change.newRecv != item.getRecvStatus()) {
item.setRecvStatus(change.newRecv);
if (change.getNewRecv() != null && change.getNewRecv() != item.getRecvStatus()) {
item.setRecvStatus(change.getNewRecv());
}
}
......
......@@ -283,7 +283,7 @@ public class RosterItem implements Cacheable, Externalizable {
new LinkedList<>(item.getGroups()));
}
private static RosterItem.AskType getAskStatus(org.xmpp.packet.Roster.Item item) {
public static RosterItem.AskType getAskStatus(org.xmpp.packet.Roster.Item item) {
if (item.getAsk() == org.xmpp.packet.Roster.Ask.subscribe) {
return RosterItem.ASK_SUBSCRIBE;
}
......@@ -295,7 +295,7 @@ public class RosterItem implements Cacheable, Externalizable {
}
}
private static RosterItem.SubType getSubType(org.xmpp.packet.Roster.Item item) {
public static RosterItem.SubType getSubType(org.xmpp.packet.Roster.Item item) {
if (item.getSubscription() == org.xmpp.packet.Roster.Subscription.to) {
return RosterItem.SUB_TO;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment