summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/Roster')
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.cpp32
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.h6
2 files changed, 30 insertions, 8 deletions
diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp
index 0ad023a..71c5f8e 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.cpp
+++ b/Swift/Controllers/Roster/ContactRosterItem.cpp
@@ -11,6 +11,7 @@
#include <Swiften/Base/DateTime.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/Idle.h>
+#include <Swiften/Elements/Presence.h>
#include <Swift/Controllers/Intl.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
@@ -34,7 +35,7 @@ StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const {
switch (presence_ ? presence_->getShow() : StatusShow::None) {
case StatusShow::Online: return StatusShow::Online;
case StatusShow::Away: return StatusShow::Away;
- case StatusShow::XA: return StatusShow::Away;
+ case StatusShow::XA: return StatusShow::Away;
case StatusShow::FFC: return StatusShow::Online;
case StatusShow::DND: return StatusShow::DND;
case StatusShow::None: return StatusShow::None;
@@ -48,22 +49,41 @@ std::string ContactRosterItem::getStatusText() const {
}
std::string ContactRosterItem::getIdleText() const {
- Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref();
- if (!idle || idle->getSince().is_not_a_date_time()) {
+ boost::posix_time::ptime idleTime = getIdle();
+ if (idleTime.is_not_a_date_time()) {
return "";
} else {
- return dateTimeToLocalString(idle->getSince());
+ return dateTimeToLocalString(idleTime);
+ }
+}
+
+boost::posix_time::ptime ContactRosterItem::getIdle() const {
+ Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref();
+ if (idle) {
+ return idle->getSince();
+ }
+ else {
+ return boost::posix_time::not_a_date_time;
}
}
std::string ContactRosterItem::getOfflineSinceText() const {
+ boost::posix_time::ptime offlineSince = getOfflineSince();
+ if (!offlineSince.is_not_a_date_time()) {
+ return dateTimeToLocalString(offlineSince);
+ }
+ return "";
+}
+
+boost::posix_time::ptime ContactRosterItem::getOfflineSince() const {
+ boost::posix_time::ptime offlineSince = boost::posix_time::not_a_date_time;
if (presence_ && presence_->getType() == Presence::Unavailable) {
boost::optional<boost::posix_time::ptime> delay = presence_->getTimestamp();
if (delay) {
- return dateTimeToLocalString(*delay);
+ offlineSince = delay.get();
}
}
- return "";
+ return offlineSince;
}
void ContactRosterItem::setAvatarPath(const boost::filesystem::path& path) {
diff --git a/Swift/Controllers/Roster/ContactRosterItem.h b/Swift/Controllers/Roster/ContactRosterItem.h
index 2ffec09..37c3840 100644
--- a/Swift/Controllers/Roster/ContactRosterItem.h
+++ b/Swift/Controllers/Roster/ContactRosterItem.h
@@ -17,7 +17,6 @@
#include <boost/signals2.hpp>
#include <Swiften/Elements/MUCOccupant.h>
-#include <Swiften/Elements/Presence.h>
#include <Swiften/Elements/StatusShow.h>
#include <Swiften/Elements/VCard.h>
#include <Swiften/JID/JID.h>
@@ -27,6 +26,8 @@
namespace Swift {
class GroupRosterItem;
+class Presence;
+
class ContactRosterItem : public RosterItem {
public:
enum Feature {
@@ -49,7 +50,9 @@ class ContactRosterItem : public RosterItem {
StatusShow::Type getSimplifiedStatusShow() const;
std::string getStatusText() const;
std::string getIdleText() const;
+ boost::posix_time::ptime getIdle() const;
std::string getOfflineSinceText() const;
+ boost::posix_time::ptime getOfflineSince() const;
void setAvatarPath(const boost::filesystem::path& path);
const boost::filesystem::path& getAvatarPath() const;
const JID& getJID() const;
@@ -82,7 +85,6 @@ class ContactRosterItem : public RosterItem {
private:
JID jid_;
JID displayJID_;
- boost::posix_time::ptime lastAvailableTime_;
boost::filesystem::path avatarPath_;
std::shared_ptr<Presence> presence_;
std::vector<std::string> groups_;