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 ...@@ -477,20 +477,24 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
* <p>Indicate a state change.</p> * <p>Indicate a state change.</p>
* <p>Use nulls to indicate fields that should not be changed.</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) { public Change(RosterItem.RecvType recv, RosterItem.SubType sub, RosterItem.AskType ask) {
newRecv = recv; newRecv = recv;
newSub = sub; newSub = sub;
newAsk = ask; newAsk = ask;
} }
public RosterItem.RecvType newRecv; public RosterItem.RecvType getNewRecv() { return newRecv; }
public RosterItem.SubType newSub; public RosterItem.SubType getNewSub() { return newSub; }
public RosterItem.AskType newAsk; 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 * The method also turns the action and sending status into an integer code
* for easier processing (switch statements). * for easier processing (switch statements).
* <p/> * <p/>
...@@ -503,19 +507,32 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand ...@@ -503,19 +507,32 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
* @param item The item to be updated * @param item The item to be updated
* @param action The new state change request * @param action The new state change request
* @param isSending True if the roster owner of the item is sending 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) { public static Change getStateChange(RosterItem.SubType itemSubType, Presence.Type action, boolean isSending) {
Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(item.getSubStatus()); Map<String, Map<Presence.Type, Change>> srTable = stateTable.get(itemSubType);
Map<Presence.Type, Change> changeTable = srTable.get(isSending ? "send" : "recv"); Map<Presence.Type, Change> changeTable = srTable.get(isSending ? "send" : "recv");
Change change = changeTable.get(action); return changeTable.get(action);
if (change.newAsk != null && change.newAsk != item.getAskStatus()) { }
item.setAskStatus(change.newAsk);
/**
* 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()) { if (change.getNewSub() != null && change.getNewSub() != item.getSubStatus()) {
item.setSubStatus(change.newSub); item.setSubStatus(change.getNewSub());
} }
if (change.newRecv != null && change.newRecv != item.getRecvStatus()) { if (change.getNewRecv() != null && change.getNewRecv() != item.getRecvStatus()) {
item.setRecvStatus(change.newRecv); item.setRecvStatus(change.getNewRecv());
} }
} }
......
...@@ -283,7 +283,7 @@ public class RosterItem implements Cacheable, Externalizable { ...@@ -283,7 +283,7 @@ public class RosterItem implements Cacheable, Externalizable {
new LinkedList<>(item.getGroups())); 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) { if (item.getAsk() == org.xmpp.packet.Roster.Ask.subscribe) {
return RosterItem.ASK_SUBSCRIBE; return RosterItem.ASK_SUBSCRIBE;
} }
...@@ -295,7 +295,7 @@ public class RosterItem implements Cacheable, Externalizable { ...@@ -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) { if (item.getSubscription() == org.xmpp.packet.Roster.Subscription.to) {
return RosterItem.SUB_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