diff options
Diffstat (limited to 'src')
4 files changed, 27 insertions, 14 deletions
diff --git a/src/com/isode/stroke/presence/DirectedPresenceSender.java b/src/com/isode/stroke/presence/DirectedPresenceSender.java index 5af85ef..1938bec 100644 --- a/src/com/isode/stroke/presence/DirectedPresenceSender.java +++ b/src/com/isode/stroke/presence/DirectedPresenceSender.java @@ -47,9 +47,9 @@ public class DirectedPresenceSender implements PresenceSender { public void addDirectedPresenceReceiver(JID jid, SendPresence sendPresence) { directedPresenceReceivers_.add(jid); - if (sendPresence == SendPresence.AndSendPresence && sender_.isAvailable()) { + if (SendPresence.AndSendPresence.equals(sendPresence) && sender_.isAvailable()) { if (lastSentUndirectedPresence_ != null && - lastSentUndirectedPresence_.getType() == Presence.Type.Available) { + Presence.Type.Available.equals(lastSentUndirectedPresence_.getType())) { Presence presenceCopy = new Presence(lastSentUndirectedPresence_); presenceCopy.setTo(jid); sender_.sendPresence(presenceCopy); @@ -64,7 +64,7 @@ public class DirectedPresenceSender implements PresenceSender { */ public void removeDirectedPresenceReceiver(JID jid, SendPresence sendPresence) { directedPresenceReceivers_.remove(jid); - if (sendPresence == SendPresence.AndSendPresence && sender_.isAvailable()) { + if (SendPresence.AndSendPresence.equals(sendPresence) && sender_.isAvailable()) { Presence presence = new Presence(); presence.setType(Presence.Type.Unavailable); presence.setTo(jid); diff --git a/src/com/isode/stroke/presence/PayloadAddingPresenceSender.java b/src/com/isode/stroke/presence/PayloadAddingPresenceSender.java index ed6106b..c634555 100644 --- a/src/com/isode/stroke/presence/PayloadAddingPresenceSender.java +++ b/src/com/isode/stroke/presence/PayloadAddingPresenceSender.java @@ -7,6 +7,11 @@ package com.isode.stroke.presence; import com.isode.stroke.elements.Payload; import com.isode.stroke.elements.Presence; +/** + * This presence sender adds payloads to outgoing presences. + * + * This class isn't meant to be used with directed presence. + */ public class PayloadAddingPresenceSender implements PresenceSender { private Presence lastSentPresence; private final PresenceSender sender; @@ -25,7 +30,7 @@ public class PayloadAddingPresenceSender implements PresenceSender { lastSentPresence = null; } if (payload != null) { - Presence sentPresence = presence; + Presence sentPresence = new Presence(presence); sentPresence.updatePayload(payload); sender.sendPresence(sentPresence); } else { diff --git a/src/com/isode/stroke/presence/PresenceOracle.java b/src/com/isode/stroke/presence/PresenceOracle.java index 8d63f59..e3e68cb 100644 --- a/src/com/isode/stroke/presence/PresenceOracle.java +++ b/src/com/isode/stroke/presence/PresenceOracle.java @@ -56,7 +56,7 @@ public class PresenceOracle { void handleIncomingPresence(Presence presence) { JID bareJID = presence.getFrom().toBare(); - if (presence.getType() == Presence.Type.Subscribe) { + if (Presence.Type.Subscribe.equals(presence.getType())) { } else { Presence passedPresence = presence; @@ -69,14 +69,14 @@ public class PresenceOracle { } Map<JID,Presence> jidMap = entries_.get(bareJID); if (jidMap == null) jidMap = new HashMap<JID,Presence>(); - if (passedPresence.getFrom().isBare() && presence.getType() == Presence.Type.Unavailable) { + if (passedPresence.getFrom().isBare() && Presence.Type.Unavailable.equals(presence.getType())) { /* Have a bare-JID only presence of offline */ jidMap.clear(); - } else if (passedPresence.getType() == Presence.Type.Available) { + } else if (Presence.Type.Available.equals(passedPresence.getType())) { /* Don't have a bare-JID only offline presence once there are available presences */ jidMap.remove(bareJID); } - if (passedPresence.getType() == Presence.Type.Unavailable && jidMap.size() > 1) { + if (Presence.Type.Unavailable.equals(passedPresence.getType()) && jidMap.size() > 1) { jidMap.remove(passedPresence.getFrom()); } else { jidMap.put(passedPresence.getFrom(), passedPresence); @@ -88,13 +88,13 @@ public class PresenceOracle { public Presence getLastPresence(final JID jid) { Map<JID,Presence> presenceMap = entries_.get(jid.toBare()); - if (presenceMap == null) return new Presence(); + if (presenceMap == null) return null; Presence i = presenceMap.get(jid); if (i != null) { return i; } else { - return new Presence(); + return null; } } @@ -110,7 +110,7 @@ public class PresenceOracle { public Presence getHighestPriorityPresence(final JID bareJID) { Map<JID,Presence> presenceMap = entries_.get(bareJID); - if (presenceMap == null) return new Presence(); + if (presenceMap == null) return null; Presence highest = null; for (Presence current : presenceMap.values()) { diff --git a/src/com/isode/stroke/presence/SubscriptionManager.java b/src/com/isode/stroke/presence/SubscriptionManager.java index 91075fc..24cfd0a 100644 --- a/src/com/isode/stroke/presence/SubscriptionManager.java +++ b/src/com/isode/stroke/presence/SubscriptionManager.java @@ -15,7 +15,15 @@ import com.isode.stroke.signals.Slot1; public class SubscriptionManager { private StanzaChannel stanzaChannel; private SignalConnection onPresenceReceivedConnection; - + + /** + * This signal is emitted when a presence subscription request is + * received. + * + * The third parameter of this signal is the original presence stanza + * received. This is useful when the subscriber adds extensions to + * the request. + */ public final Signal3<JID, String, Presence> onPresenceSubscriptionRequest = new Signal3<JID, String, Presence>(); public final Signal2<JID, String> onPresenceSubscriptionRevoked = new Signal2<JID, String>(); @@ -58,10 +66,10 @@ public class SubscriptionManager { void handleIncomingPresence(Presence presence) { JID bareJID = presence.getFrom().toBare(); - if (presence.getType() == Presence.Type.Subscribe) { + if (Presence.Type.Subscribe.equals(presence.getType())) { onPresenceSubscriptionRequest.emit(bareJID, presence.getStatus(), presence); } - else if (presence.getType() == Presence.Type.Unsubscribe) { + else if (Presence.Type.Unsubscribe.equals(presence.getType())) { onPresenceSubscriptionRevoked.emit(bareJID, presence.getStatus()); } } |