Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: third_party/libjingle_xmpp/xmpp/presencestatus.h

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

Powered by Google App Engine
This is Rietveld 408576698