• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef THIRD_PARTY_LIBJINGLE_FILES_WEBRTC_LIBJINGLE_XMPP_PRESENCESTATUS_H_
12 #define THIRD_PARTY_LIBJINGLE_FILES_WEBRTC_LIBJINGLE_XMPP_PRESENCESTATUS_H_
13 
14 #include "webrtc/libjingle/xmpp/constants.h"
15 #include "webrtc/libjingle/xmpp/jid.h"
16 
17 namespace buzz {
18 
19 class PresenceStatus {
20 public:
21   PresenceStatus();
~PresenceStatus()22   ~PresenceStatus() {}
23 
24   // These are arranged in "priority order", i.e., if we see
25   // two statuses at the same priority but with different Shows,
26   // we will show the one with the highest show in the following
27   // order.
28   enum Show {
29     SHOW_NONE     = 0,
30     SHOW_OFFLINE  = 1,
31     SHOW_XA       = 2,
32     SHOW_AWAY     = 3,
33     SHOW_DND      = 4,
34     SHOW_ONLINE   = 5,
35     SHOW_CHAT     = 6,
36   };
37 
jid()38   const Jid& jid() const { return jid_; }
priority()39   int priority() const { return pri_; }
show()40   Show show() const { return show_; }
status()41   const std::string& status() const { return status_; }
nick()42   const std::string& nick() const { return nick_; }
available()43   bool available() const { return available_ ; }
error_code()44   int error_code() const { return e_code_; }
error_string()45   const std::string& error_string() const { return e_str_; }
know_capabilities()46   bool know_capabilities() const { return know_capabilities_; }
voice_capability()47   bool voice_capability() const { return voice_capability_; }
pmuc_capability()48   bool pmuc_capability() const { return pmuc_capability_; }
video_capability()49   bool video_capability() const { return video_capability_; }
camera_capability()50   bool camera_capability() const { return camera_capability_; }
caps_node()51   const std::string& caps_node() const { return caps_node_; }
version()52   const std::string& version() const { return version_; }
feedback_probation()53   bool feedback_probation() const { return feedback_probation_; }
sent_time()54   const std::string& sent_time() const { return sent_time_; }
55 
set_jid(const Jid & jid)56   void set_jid(const Jid& jid) { jid_ = jid; }
set_priority(int pri)57   void set_priority(int pri) { pri_ = pri; }
set_show(Show show)58   void set_show(Show show) { show_ = show; }
set_status(const std::string & status)59   void set_status(const std::string& status) { status_ = status; }
set_nick(const std::string & nick)60   void set_nick(const std::string& nick) { nick_ = nick; }
set_available(bool a)61   void set_available(bool a) { available_ = a; }
set_error(int e_code,const std::string e_str)62   void set_error(int e_code, const std::string e_str)
63       { e_code_ = e_code; e_str_ = e_str; }
set_know_capabilities(bool f)64   void set_know_capabilities(bool f) { know_capabilities_ = f; }
set_voice_capability(bool f)65   void set_voice_capability(bool f) { voice_capability_ = f; }
set_pmuc_capability(bool f)66   void set_pmuc_capability(bool f) { pmuc_capability_ = f; }
set_video_capability(bool f)67   void set_video_capability(bool f) { video_capability_ = f; }
set_camera_capability(bool f)68   void set_camera_capability(bool f) { camera_capability_ = f; }
set_caps_node(const std::string & f)69   void set_caps_node(const std::string& f) { caps_node_ = f; }
set_version(const std::string & v)70   void set_version(const std::string& v) { version_ = v; }
set_feedback_probation(bool f)71   void set_feedback_probation(bool f) { feedback_probation_ = f; }
set_sent_time(const std::string & time)72   void set_sent_time(const std::string& time) { sent_time_ = time; }
73 
74   void UpdateWith(const PresenceStatus& new_value);
75 
HasQuietStatus()76   bool HasQuietStatus() const {
77     if (status_.empty())
78       return false;
79     return !(QuietStatus().empty());
80   }
81 
82   // Knowledge of other clients' silly automatic status strings -
83   // Don't show these.
QuietStatus()84   std::string QuietStatus() const {
85     if (jid_.resource().find("Psi") != std::string::npos) {
86       if (status_ == "Online" ||
87           status_.find("Auto Status") != std::string::npos)
88         return STR_EMPTY;
89     }
90     if (jid_.resource().find("Gaim") != std::string::npos) {
91       if (status_ == "Sorry, I ran out for a bit!")
92         return STR_EMPTY;
93     }
94     return TrimStatus(status_);
95   }
96 
ExplicitStatus()97   std::string ExplicitStatus() const {
98     std::string result = QuietStatus();
99     if (result.empty()) {
100       result = ShowStatus();
101     }
102     return result;
103   }
104 
ShowStatus()105   std::string ShowStatus() const {
106     std::string result;
107     if (!available()) {
108       result = "Offline";
109     }
110     else {
111       switch (show()) {
112         case SHOW_AWAY:
113         case SHOW_XA:
114           result = "Idle";
115           break;
116         case SHOW_DND:
117           result = "Busy";
118           break;
119         case SHOW_CHAT:
120           result = "Chatty";
121           break;
122         default:
123           result = "Available";
124           break;
125       }
126     }
127     return result;
128   }
129 
TrimStatus(const std::string & st)130   static std::string TrimStatus(const std::string& st) {
131     std::string s(st);
132     int j = 0;
133     bool collapsing = true;
134     for (unsigned int i = 0; i < s.length(); i+= 1) {
135       if (s[i] <= ' ' && s[i] >= 0) {
136         if (collapsing) {
137           continue;
138         }
139         else {
140           s[j] = ' ';
141           j += 1;
142           collapsing = true;
143         }
144       }
145       else {
146         s[j] = s[i];
147         j += 1;
148         collapsing = false;
149       }
150     }
151     if (collapsing && j > 0) {
152       j -= 1;
153     }
154     s.erase(j, s.length());
155     return s;
156   }
157 
158 private:
159   Jid jid_;
160   int pri_;
161   Show show_;
162   std::string status_;
163   std::string nick_;
164   bool available_;
165   int e_code_;
166   std::string e_str_;
167   bool feedback_probation_;
168 
169   // capabilities (valid only if know_capabilities_
170   bool know_capabilities_;
171   bool voice_capability_;
172   bool pmuc_capability_;
173   bool video_capability_;
174   bool camera_capability_;
175   std::string caps_node_;
176   std::string version_;
177 
178   std::string sent_time_; // from the jabber:x:delay element
179 };
180 
181 class MucPresenceStatus : public PresenceStatus {
182 };
183 
184 } // namespace buzz
185 
186 
187 #endif // THIRD_PARTY_LIBJINGLE_FILES_WEBRTC_LIBJINGLE_XMPP_PRESENCESTATUS_H_
188 
189