summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-07-25 06:48:08 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-08-17 11:10:49 (GMT)
commit2533374644704040ca67aba4e1240a9d6ea450c8 (patch)
treef8b707a2b1544f934c0bc626eab51fb737a63541 /src/com
parent0a1f7199e26523dd2693f44a5841c5434cc9000d (diff)
downloadstroke-2533374644704040ca67aba4e1240a9d6ea450c8.zip
stroke-2533374644704040ca67aba4e1240a9d6ea450c8.tar.bz2
Updates Presence in accordance with Swiften.
Updates DirectedPresenceSender, PayloadAddingPresenceSender, PresenceOracle and SubscriptionManager. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for: DirectedPresenceSenderTest, PayloadAddingPresenceSenderTest and PresenceOracle. All tests pass. Change-Id: I9ad899965f5ac32c6f21805b530c234e391be6ba
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/presence/DirectedPresenceSender.java6
-rw-r--r--src/com/isode/stroke/presence/PayloadAddingPresenceSender.java7
-rw-r--r--src/com/isode/stroke/presence/PresenceOracle.java14
-rw-r--r--src/com/isode/stroke/presence/SubscriptionManager.java14
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());
}
}