summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-03-11 09:38:40 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-03-14 14:59:53 (GMT)
commitc77facbc3036590cfa347f38859f9f536f082d6b (patch)
tree6ea804994bac2bc8fe76736b61075deeb02b6932 /src
parentecec6f30d6d91ea17b8ed9f6a31dc4702e759585 (diff)
downloadstroke-c77facbc3036590cfa347f38859f9f536f082d6b.zip
stroke-c77facbc3036590cfa347f38859f9f536f082d6b.tar.bz2
Add roster to PresenceOracle.
As per patch 'Mark removed contacts as unavailable in Swift' (9e6ee0f262e7dc663f4c706b16a346a268f425aa) added an XMPPRoster to the member variables and constructor arguments for PresenceOracle. Test-information: Unit tests pass. Change-Id: I062d256c088a968e061d864fbd1386f850b614a7
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/client/Client.java4
-rw-r--r--src/com/isode/stroke/presence/PresenceOracle.java58
2 files changed, 45 insertions, 17 deletions
diff --git a/src/com/isode/stroke/client/Client.java b/src/com/isode/stroke/client/Client.java
index 07ac885..88022e3 100644
--- a/src/com/isode/stroke/client/Client.java
+++ b/src/com/isode/stroke/client/Client.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015, Isode Limited, London, England.
+ * Copyright (c) 2010-2016, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.client;
@@ -101,7 +101,7 @@ public class Client extends CoreClient {
subscriptionManager = new SubscriptionManager(getStanzaChannel());
- presenceOracle = new PresenceOracle(getStanzaChannel());
+ presenceOracle = new PresenceOracle(getStanzaChannel(),roster);
presenceOracle.onPresenceChange.connect(onPresenceChange);
stanzaChannelPresenceSender = new StanzaChannelPresenceSender(getStanzaChannel());
diff --git a/src/com/isode/stroke/presence/PresenceOracle.java b/src/com/isode/stroke/presence/PresenceOracle.java
index e3e68cb..7ac5b9d 100644
--- a/src/com/isode/stroke/presence/PresenceOracle.java
+++ b/src/com/isode/stroke/presence/PresenceOracle.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015, Isode Limited, London, England.
+ * Copyright (c) 2010-2016, Isode Limited, London, England.
* All rights reserved.
*/
package com.isode.stroke.presence;
@@ -13,6 +13,7 @@ import com.isode.stroke.client.StanzaChannel;
import com.isode.stroke.elements.Presence;
import com.isode.stroke.elements.StatusShow;
import com.isode.stroke.jid.JID;
+import com.isode.stroke.roster.XMPPRoster;
import com.isode.stroke.signals.Signal1;
import com.isode.stroke.signals.SignalConnection;
import com.isode.stroke.signals.Slot1;
@@ -22,29 +23,41 @@ public class PresenceOracle {
private final StanzaChannel stanzaChannel_;
private final SignalConnection onPresenceReceivedSignal;
private final SignalConnection onAvailableChangedSignal;
+ private final XMPPRoster xmppRoster_;
public final Signal1<Presence> onPresenceChange = new Signal1<Presence>();
+ private final SignalConnection onJIDRemovedConnection;
- public PresenceOracle(StanzaChannel stanzaChannel) {
- stanzaChannel_ = stanzaChannel;
- onPresenceReceivedSignal = stanzaChannel_.onPresenceReceived.connect(new Slot1<Presence>() {
- @Override
- public void call(Presence p1) {
- handleIncomingPresence(p1);
- }
- });
- onAvailableChangedSignal = stanzaChannel_.onAvailableChanged.connect(new Slot1<Boolean>() {
- @Override
- public void call(Boolean p1) {
- handleStanzaChannelAvailableChanged(p1);
- }
- });
+ public PresenceOracle(StanzaChannel stanzaChannel, XMPPRoster xmppRoster) {
+ stanzaChannel_ = stanzaChannel;
+ xmppRoster_ = xmppRoster;
+ onPresenceReceivedSignal = stanzaChannel_.onPresenceReceived.connect(new Slot1<Presence>() {
+ @Override
+ public void call(Presence p1) {
+ handleIncomingPresence(p1);
+ }
+ });
+ onAvailableChangedSignal = stanzaChannel_.onAvailableChanged.connect(new Slot1<Boolean>() {
+ @Override
+ public void call(Boolean p1) {
+ handleStanzaChannelAvailableChanged(p1);
+ }
+ });
+ onJIDRemovedConnection = xmppRoster_.onJIDRemoved.connect(new Slot1<JID>() {
+
+ @Override
+ public void call(JID removedJID) {
+ handleJIDRemoved(removedJID);
+ }
+
+ });
}
void delete() {
onPresenceReceivedSignal.disconnect();
onAvailableChangedSignal.disconnect();
+ onJIDRemovedConnection.disconnect();
}
void handleStanzaChannelAvailableChanged(boolean available) {
@@ -85,6 +98,21 @@ public class PresenceOracle {
onPresenceChange.emit(passedPresence);
}
}
+
+ private void handleJIDRemoved(JID removedJID) {
+ // 3921bis says that we don't follow up with an unavailable, so simulate this ourselves
+ Presence unavailablePresence = new Presence();
+ unavailablePresence.setType(Presence.Type.Unavailable);
+ unavailablePresence.setFrom(removedJID);
+
+ if (entries_.containsKey(removedJID.toBare())) {
+ Map<JID,Presence> presenceMap = entries_.get(removedJID.toBare());
+ presenceMap.clear();
+ presenceMap.put(removedJID, unavailablePresence);
+ }
+
+ onPresenceChange.emit(unavailablePresence);
+ }
public Presence getLastPresence(final JID jid) {
Map<JID,Presence> presenceMap = entries_.get(jid.toBare());