diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-03-11 09:38:40 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-03-14 14:59:53 (GMT) |
commit | c77facbc3036590cfa347f38859f9f536f082d6b (patch) | |
tree | 6ea804994bac2bc8fe76736b61075deeb02b6932 | |
parent | ecec6f30d6d91ea17b8ed9f6a31dc4702e759585 (diff) | |
download | stroke-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
-rw-r--r-- | src/com/isode/stroke/client/Client.java | 4 | ||||
-rw-r--r-- | src/com/isode/stroke/presence/PresenceOracle.java | 58 | ||||
-rw-r--r-- | test/com/isode/stroke/presence/PresenceOracleTest.java | 11 |
3 files changed, 54 insertions, 19 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()); diff --git a/test/com/isode/stroke/presence/PresenceOracleTest.java b/test/com/isode/stroke/presence/PresenceOracleTest.java index 03aea04..ac82045 100644 --- a/test/com/isode/stroke/presence/PresenceOracleTest.java +++ b/test/com/isode/stroke/presence/PresenceOracleTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -16,8 +16,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import org.junit.Test; import org.junit.Before; + import com.isode.stroke.elements.Presence; import com.isode.stroke.elements.Payload; import com.isode.stroke.client.DummyStanzaChannel; @@ -27,10 +29,13 @@ import com.isode.stroke.presence.PayloadAddingPresenceSender; import com.isode.stroke.presence.PresenceOracle; import com.isode.stroke.presence.SubscriptionManager; import com.isode.stroke.jid.JID; +import com.isode.stroke.roster.XMPPRoster; +import com.isode.stroke.roster.XMPPRosterImpl; import com.isode.stroke.signals.SignalConnection; import com.isode.stroke.signals.Slot2; import com.isode.stroke.signals.Slot3; import com.isode.stroke.signals.Slot1; + import java.util.Collection; import java.util.Vector; @@ -49,6 +54,7 @@ public class PresenceOracleTest { private PresenceOracle oracle_; private SubscriptionManager subscriptionManager_; private DummyStanzaChannel stanzaChannel_; + private XMPPRoster xmppRoster_; private Collection<Presence> changes = new Vector<Presence>(); private Collection<SubscriptionRequestInfo> subscriptionRequests = new Vector<SubscriptionRequestInfo>(); private JID user1; @@ -89,7 +95,8 @@ public class PresenceOracleTest { @Before public void setUp() { stanzaChannel_ = new DummyStanzaChannel(); - oracle_ = new PresenceOracle(stanzaChannel_); + xmppRoster_ = new XMPPRosterImpl(); + oracle_ = new PresenceOracle(stanzaChannel_,xmppRoster_); oracle_.onPresenceChange.connect(new Slot1<Presence>() { @Override public void call(Presence p) { |