summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-10-27 16:20:09 (GMT)
committerTobias Markmann <tm@ayena.de>2015-10-30 12:34:52 (GMT)
commit0f5ef716a50c8d9761cafda12aacf818cdfd6353 (patch)
tree4ed80dedc2fa8b04036eb7567282094ea8fe07f1 /Swift/Controllers/Roster/ContactRosterItem.cpp
parent4320235bef1b601856b295a8d6411d1898048802 (diff)
downloadswift-0f5ef716a50c8d9761cafda12aacf818cdfd6353.zip
swift-0f5ef716a50c8d9761cafda12aacf818cdfd6353.tar.bz2
Change bare JID presence lookup code to ignore priorities
Before presence handling code was handled by both, the ContactRosterItem in Swift and the PresenceOracle in Swiften. The ContactRosterItem also considered the presence priority for deciding what presence to show for a bare JID. With this code all full or bare JID presence requests are finally handled by the PresenceOracle. For bare JIDs it is looked up to a presence of one of the available resources of that JID regardless of the priorities. Test-Information: Adjusted tests according to above description and documentation in PresenceOracle. Change-Id: I972a4574f476cdf4d4b5593a035eb1c25ef2f8ba
Diffstat (limited to 'Swift/Controllers/Roster/ContactRosterItem.cpp')
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.cpp52
1 files changed, 12 insertions, 40 deletions
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp
index fd6d1cd..ae05aee 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.cpp
+++ b/Swift/Controllers/Roster/ContactRosterItem.cpp
@@ -1,18 +1,19 @@
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 <Swift/Controllers/Roster/ContactRosterItem.h> 7#include <Swift/Controllers/Roster/ContactRosterItem.h>
8 8
9#include <boost/date_time/posix_time/posix_time.hpp> 9#include <boost/date_time/posix_time/posix_time.hpp>
10 10
11#include <Swiften/Base/foreach.h>
12#include <Swiften/Base/DateTime.h> 11#include <Swiften/Base/DateTime.h>
12#include <Swiften/Base/foreach.h>
13#include <Swiften/Elements/Idle.h> 13#include <Swiften/Elements/Idle.h>
14
14#include <Swift/Controllers/Intl.h> 15#include <Swift/Controllers/Intl.h>
15#include <Swift/Controllers/Roster/GroupRosterItem.h> 16#include <Swift/Controllers/Roster/GroupRosterItem.h>
16 17
17namespace Swift { 18namespace Swift {
18 19
@@ -24,15 +25,15 @@ ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, cons
24 25
25ContactRosterItem::~ContactRosterItem() { 26ContactRosterItem::~ContactRosterItem() {
26} 27}
27 28
28StatusShow::Type ContactRosterItem::getStatusShow() const { 29StatusShow::Type ContactRosterItem::getStatusShow() const {
29 return shownPresence_ ? shownPresence_->getShow() : StatusShow::None; 30 return presence_ ? presence_->getShow() : StatusShow::None;
30} 31}
31 32
32StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const { 33StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
33 switch (shownPresence_ ? shownPresence_->getShow() : StatusShow::None) { 34 switch (presence_ ? presence_->getShow() : StatusShow::None) {
34 case StatusShow::Online: return StatusShow::Online; 35 case StatusShow::Online: return StatusShow::Online;
35 case StatusShow::Away: return StatusShow::Away; 36 case StatusShow::Away: return StatusShow::Away;
36 case StatusShow::XA: return StatusShow::Away; 37 case StatusShow::XA: return StatusShow::Away;
37 case StatusShow::FFC: return StatusShow::Online; 38 case StatusShow::FFC: return StatusShow::Online;
38 case StatusShow::DND: return StatusShow::DND; 39 case StatusShow::DND: return StatusShow::DND;
@@ -41,26 +42,26 @@ StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
41 assert(false); 42 assert(false);
42 return StatusShow::None; 43 return StatusShow::None;
43} 44}
44 45
45std::string ContactRosterItem::getStatusText() const { 46std::string ContactRosterItem::getStatusText() const {
46 return shownPresence_ ? shownPresence_->getStatus() : ""; 47 return presence_ ? presence_->getStatus() : "";
47} 48}
48 49
49std::string ContactRosterItem::getIdleText() const { 50std::string ContactRosterItem::getIdleText() const {
50 Idle::ref idle = shownPresence_ ? shownPresence_->getPayload<Idle>() : Idle::ref(); 51 Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref();
51 if (!idle || idle->getSince().is_not_a_date_time()) { 52 if (!idle || idle->getSince().is_not_a_date_time()) {
52 return ""; 53 return "";
53 } else { 54 } else {
54 return dateTimeToLocalString(idle->getSince()); 55 return dateTimeToLocalString(idle->getSince());
55 } 56 }
56} 57}
57 58
58std::string ContactRosterItem::getOfflineSinceText() const { 59std::string ContactRosterItem::getOfflineSinceText() const {
59 if (offlinePresence_) { 60 if (presence_ && presence_->getType() == Presence::Unavailable) {
60 boost::optional<boost::posix_time::ptime> delay = offlinePresence_->getTimestamp(); 61 boost::optional<boost::posix_time::ptime> delay = presence_->getTimestamp();
61 if (offlinePresence_->getType() == Presence::Unavailable && delay) { 62 if (delay) {
62 return dateTimeToLocalString(*delay); 63 return dateTimeToLocalString(*delay);
63 } 64 }
64 } 65 }
65 return ""; 66 return "";
66} 67}
@@ -86,46 +87,17 @@ const JID& ContactRosterItem::getDisplayJID() const {
86} 87}
87 88
88 89
89typedef std::pair<std::string, boost::shared_ptr<Presence> > StringPresencePair; 90typedef std::pair<std::string, boost::shared_ptr<Presence> > StringPresencePair;
90 91
91void ContactRosterItem::calculateShownPresence() {
92 shownPresence_ = offlinePresence_;
93 foreach (StringPresencePair presencePair, presences_) {
94 boost::shared_ptr<Presence> presence = presencePair.second;
95 if (!shownPresence_ || presence->getPriority() > shownPresence_->getPriority() || presence->getShow() < shownPresence_->getShow()) {
96 shownPresence_ = presence;
97 }
98 }
99}
100
101void ContactRosterItem::clearPresence() { 92void ContactRosterItem::clearPresence() {
102 presences_.clear(); 93 presence_.reset();
103 calculateShownPresence();
104 onDataChanged(); 94 onDataChanged();
105} 95}
106 96
107void ContactRosterItem::applyPresence(const std::string& resource, boost::shared_ptr<Presence> presence) { 97void ContactRosterItem::applyPresence(const std::string& resource, boost::shared_ptr<Presence> presence) {
108 if (offlinePresence_) { 98 presence_ = presence;
109 offlinePresence_ = boost::shared_ptr<Presence>();
110 }
111 if (presence->getType() == Presence::Unavailable) {
112 if (resource.empty()) {
113 /* Unavailable from the bare JID means all resources are offline.*/
114 presences_.clear();
115 } else {
116 if (presences_.find(resource) != presences_.end()) {
117 presences_.erase(resource);
118 }
119 }
120 if (presences_.empty()) {
121 offlinePresence_ = presence;
122 }
123 } else {
124 presences_[resource] = presence;
125 }
126 calculateShownPresence();
127 onDataChanged(); 99 onDataChanged();
128} 100}
129 101
130const std::vector<std::string>& ContactRosterItem::getGroups() const { 102const std::vector<std::string>& ContactRosterItem::getGroups() const {
131 return groups_; 103 return groups_;