summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-09-14 15:08:39 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-10-16 14:58:03 (GMT)
commit9e6ee0f262e7dc663f4c706b16a346a268f425aa (patch)
tree5926fd9cc9dec1233f95239b259a7730f99a5a72 /Swiften/Presence/UnitTest/PresenceOracleTest.cpp
parent8da6e35afab55d7232d47575faea2bde7cd44ece (diff)
downloadswift-9e6ee0f262e7dc663f4c706b16a346a268f425aa.zip
swift-9e6ee0f262e7dc663f4c706b16a346a268f425aa.tar.bz2
Mark removed contacts as unavailable in Swift
When removing a contact, a XMPP client will not receive an explicit unavailable presence stanza for the contact from the server. Because of that Swift used to show removed contacts still with their old presence in the Chats tab or the chat view. With this patch, the PresenceOracle will flush all known presence of a contact as soon as the JID is removed from the roster. An unavailable presence will stored under the removed bare JID and is emitted via the PresenceOracle::onPresenceChange signal. Test-Information: Added a unit test verifying this behavior. Tested the behavior with two scenarios: a) Account A and B adding each other and accepting the subscription request. Starting a chat between A and B. After removing B in A's account, B used to be shown as available in the chat view and the Chats tab. With this patch B is shown as unavailable. b) Account A and B adding each other and accepting the subscription request. A removing B, and B removing A. After A adds B again, B used to be shown with the old presence even before B accepted the subscription request. This behavior is also fixed with this patch, not showing B as online until B accepted the subscription request. Change-Id: Iba97d3bedd0ac962ea00b25a0d2ed6106ed55a55
Diffstat (limited to 'Swiften/Presence/UnitTest/PresenceOracleTest.cpp')
-rw-r--r--Swiften/Presence/UnitTest/PresenceOracleTest.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
index 41857e1..85dcca9 100644
--- a/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
+++ b/Swiften/Presence/UnitTest/PresenceOracleTest.cpp
@@ -1,19 +1,22 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
6 6
7#include <cppunit/extensions/HelperMacros.h>
8#include <cppunit/extensions/TestFactoryRegistry.h>
9#include <boost/bind.hpp> 7#include <boost/bind.hpp>
10#include <boost/shared_ptr.hpp> 8#include <boost/shared_ptr.hpp>
11 9
12#include <Swiften/Presence/PresenceOracle.h> 10#include <cppunit/extensions/HelperMacros.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12
13#include <Swiften/Client/DummyStanzaChannel.h> 13#include <Swiften/Client/DummyStanzaChannel.h>
14#include <Swiften/Presence/PresenceOracle.h>
14#include <Swiften/Presence/SubscriptionManager.h> 15#include <Swiften/Presence/SubscriptionManager.h>
16#include <Swiften/Roster/XMPPRoster.h>
17#include <Swiften/Roster/XMPPRosterImpl.h>
15 18
16using namespace Swift; 19using namespace Swift;
17 20
18class PresenceOracleTest : public CppUnit::TestFixture { 21class PresenceOracleTest : public CppUnit::TestFixture {
19 CPPUNIT_TEST_SUITE(PresenceOracleTest); 22 CPPUNIT_TEST_SUITE(PresenceOracleTest);
@@ -28,11 +31,13 @@ class PresenceOracleTest : public CppUnit::TestFixture {
28 CPPUNIT_TEST_SUITE_END(); 31 CPPUNIT_TEST_SUITE_END();
29 32
30 public: 33 public:
31 void setUp() { 34 void setUp() {
32 stanzaChannel_ = new DummyStanzaChannel(); 35 stanzaChannel_ = new DummyStanzaChannel();
33 oracle_ = new PresenceOracle(stanzaChannel_); 36 xmppRoster_ = new XMPPRosterImpl();
37
38 oracle_ = new PresenceOracle(stanzaChannel_, xmppRoster_);
34 oracle_->onPresenceChange.connect(boost::bind(&PresenceOracleTest::handlePresenceChange, this, _1)); 39 oracle_->onPresenceChange.connect(boost::bind(&PresenceOracleTest::handlePresenceChange, this, _1));
35 subscriptionManager_ = new SubscriptionManager(stanzaChannel_); 40 subscriptionManager_ = new SubscriptionManager(stanzaChannel_);
36 subscriptionManager_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2)); 41 subscriptionManager_->onPresenceSubscriptionRequest.connect(boost::bind(&PresenceOracleTest::handlePresenceSubscriptionRequest, this, _1, _2));
37 user1 = JID("user1@foo.com/Foo"); 42 user1 = JID("user1@foo.com/Foo");
38 user1alt = JID("user1@foo.com/Bar"); 43 user1alt = JID("user1@foo.com/Bar");
@@ -40,10 +45,11 @@ class PresenceOracleTest : public CppUnit::TestFixture {
40 } 45 }
41 46
42 void tearDown() { 47 void tearDown() {
43 delete subscriptionManager_; 48 delete subscriptionManager_;
44 delete oracle_; 49 delete oracle_;
50 delete xmppRoster_;
45 delete stanzaChannel_; 51 delete stanzaChannel_;
46 } 52 }
47 53
48 void testHighestPresenceSingle() { 54 void testHighestPresenceSingle() {
49 JID bareJID("alice@wonderland.lit"); 55 JID bareJID("alice@wonderland.lit");
@@ -184,10 +190,11 @@ class PresenceOracleTest : public CppUnit::TestFixture {
184 std::string reason; 190 std::string reason;
185 }; 191 };
186 PresenceOracle* oracle_; 192 PresenceOracle* oracle_;
187 SubscriptionManager* subscriptionManager_; 193 SubscriptionManager* subscriptionManager_;
188 DummyStanzaChannel* stanzaChannel_; 194 DummyStanzaChannel* stanzaChannel_;
195 XMPPRoster* xmppRoster_;
189 std::vector<Presence::ref> changes; 196 std::vector<Presence::ref> changes;
190 std::vector<SubscriptionRequestInfo> subscriptionRequests; 197 std::vector<SubscriptionRequestInfo> subscriptionRequests;
191 JID user1; 198 JID user1;
192 JID user1alt; 199 JID user1alt;
193 JID user2; 200 JID user2;