diff options
Diffstat (limited to 'Swift/Controllers/Roster/ContactRosterItem.cpp')
| -rw-r--r-- | Swift/Controllers/Roster/ContactRosterItem.cpp | 52 |
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 | ||
| 17 | namespace Swift { | 18 | namespace Swift { |
| 18 | 19 | ||
| @@ -24,15 +25,15 @@ ContactRosterItem::ContactRosterItem(const JID& jid, const JID& displayJID, cons | |||
| 24 | 25 | ||
| 25 | ContactRosterItem::~ContactRosterItem() { | 26 | ContactRosterItem::~ContactRosterItem() { |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | StatusShow::Type ContactRosterItem::getStatusShow() const { | 29 | StatusShow::Type ContactRosterItem::getStatusShow() const { |
| 29 | return shownPresence_ ? shownPresence_->getShow() : StatusShow::None; | 30 | return presence_ ? presence_->getShow() : StatusShow::None; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const { | 33 | StatusShow::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 | ||
| 45 | std::string ContactRosterItem::getStatusText() const { | 46 | std::string ContactRosterItem::getStatusText() const { |
| 46 | return shownPresence_ ? shownPresence_->getStatus() : ""; | 47 | return presence_ ? presence_->getStatus() : ""; |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | std::string ContactRosterItem::getIdleText() const { | 50 | std::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 | ||
| 58 | std::string ContactRosterItem::getOfflineSinceText() const { | 59 | std::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 | ||
| 89 | typedef std::pair<std::string, boost::shared_ptr<Presence> > StringPresencePair; | 90 | typedef std::pair<std::string, boost::shared_ptr<Presence> > StringPresencePair; |
| 90 | 91 | ||
| 91 | void 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 | |||
| 101 | void ContactRosterItem::clearPresence() { | 92 | void ContactRosterItem::clearPresence() { |
| 102 | presences_.clear(); | 93 | presence_.reset(); |
| 103 | calculateShownPresence(); | ||
| 104 | onDataChanged(); | 94 | onDataChanged(); |
| 105 | } | 95 | } |
| 106 | 96 | ||
| 107 | void ContactRosterItem::applyPresence(const std::string& resource, boost::shared_ptr<Presence> presence) { | 97 | void 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 | ||
| 130 | const std::vector<std::string>& ContactRosterItem::getGroups() const { | 102 | const std::vector<std::string>& ContactRosterItem::getGroups() const { |
| 131 | return groups_; | 103 | return groups_; |
Swift