about summary refs log tree commit diff stats
path: root/src/notification.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/notification.cpp')
-rw-r--r--src/notification.cpp269
1 files changed, 140 insertions, 129 deletions
diff --git a/src/notification.cpp b/src/notification.cpp index 0397ce5..3269a90 100644 --- a/src/notification.cpp +++ b/src/notification.cpp
@@ -2,8 +2,8 @@
2#include <cassert> 2#include <cassert>
3#include <new> 3#include <new>
4#include <json.hpp> 4#include <json.hpp>
5 5#include "codes.h"
6using nlohmann::json; 6#include "client.h"
7 7
8namespace twitter { 8namespace twitter {
9 9
@@ -12,26 +12,32 @@ namespace twitter {
12 return _type; 12 return _type;
13 } 13 }
14 14
15 notification::notification() : _type(type::invalid) 15 notification::notification(const client& tclient, std::string data)
16 { 16 {
17 const user& current_user = tclient.getUser();
17 18
18 } 19 nlohmann::json json;
19
20 notification::notification(std::string data, const user& current_user)
21 {
22 try {
23 auto _data = json::parse(data);
24 20
25 if (_data.find("in_reply_to_status_id") != _data.end()) 21 try
22 {
23 json = nlohmann::json::parse(data);
24 } catch (const std::invalid_argument& error)
25 {
26 std::throw_with_nested(invalid_response(data));
27 }
28
29 try
30 {
31 if (!json["in_reply_to_status_id"].is_null())
26 { 32 {
27 _type = type::tweet; 33 _type = type::tweet;
28 34
29 new(&_tweet) tweet(data); 35 new(&_tweet) tweet(tclient, data);
30 } else if (_data.find("event") != _data.end()) 36 } else if (!json["event"].is_null())
31 { 37 {
32 std::string event = _data.at("event"); 38 std::string event = json["event"];
33 user source(_data.at("source").dump()); 39 user source(tclient, json["source"].dump());
34 user target(_data.at("target").dump()); 40 user target(tclient, json["target"].dump());
35 41
36 if (event == "user_update") 42 if (event == "user_update")
37 { 43 {
@@ -50,7 +56,7 @@ namespace twitter {
50 new(&_user) user(target); 56 new(&_user) user(target);
51 } else if (event == "favorite") 57 } else if (event == "favorite")
52 { 58 {
53 new(&_user_and_tweet._tweet) tweet(_data.at("target_object").dump()); 59 new(&_user_and_tweet._tweet) tweet(tclient, json["target_object"].dump());
54 60
55 if (current_user == source) 61 if (current_user == source)
56 { 62 {
@@ -64,7 +70,7 @@ namespace twitter {
64 } 70 }
65 } else if (event == "unfavorite") 71 } else if (event == "unfavorite")
66 { 72 {
67 new(&_user_and_tweet._tweet) tweet(_data.at("target_object").dump()); 73 new(&_user_and_tweet._tweet) tweet(tclient, json["target_object"].dump());
68 74
69 if (current_user == source) 75 if (current_user == source)
70 { 76 {
@@ -97,20 +103,20 @@ namespace twitter {
97 { 103 {
98 _type = type::list_created; 104 _type = type::list_created;
99 105
100 new(&_list) list(_data.at("target_object").dump()); 106 new(&_list) list(json["target_object"].dump());
101 } else if (event == "list_destroyed") 107 } else if (event == "list_destroyed")
102 { 108 {
103 _type = type::list_destroyed; 109 _type = type::list_destroyed;
104 110
105 new(&_list) list(_data.at("target_object").dump()); 111 new(&_list) list(json["target_object"].dump());
106 } else if (event == "list_updated") 112 } else if (event == "list_updated")
107 { 113 {
108 _type = type::list_updated; 114 _type = type::list_updated;
109 115
110 new(&_list) list(_data.at("target_object").dump()); 116 new(&_list) list(json["target_object"].dump());
111 } else if (event == "list_member_added") 117 } else if (event == "list_member_added")
112 { 118 {
113 new(&_user_and_list._list) list(_data.at("target_object").dump()); 119 new(&_user_and_list._list) list(json["target_object"].dump());
114 120
115 if (current_user == source) 121 if (current_user == source)
116 { 122 {
@@ -124,7 +130,7 @@ namespace twitter {
124 } 130 }
125 } else if (event == "list_member_removed") 131 } else if (event == "list_member_removed")
126 { 132 {
127 new(&_user_and_list._list) list(_data.at("target_object").dump()); 133 new(&_user_and_list._list) list(json["target_object"].dump());
128 134
129 if (current_user == source) 135 if (current_user == source)
130 { 136 {
@@ -138,7 +144,7 @@ namespace twitter {
138 } 144 }
139 } else if (event == "list_member_subscribe") 145 } else if (event == "list_member_subscribe")
140 { 146 {
141 new(&_user_and_list._list) list(_data.at("target_object").dump()); 147 new(&_user_and_list._list) list(json["target_object"].dump());
142 148
143 if (current_user == source) 149 if (current_user == source)
144 { 150 {
@@ -152,7 +158,7 @@ namespace twitter {
152 } 158 }
153 } else if (event == "list_member_unsubscribe") 159 } else if (event == "list_member_unsubscribe")
154 { 160 {
155 new(&_user_and_list._list) list(_data.at("target_object").dump()); 161 new(&_user_and_list._list) list(json["target_object"].dump());
156 162
157 if (current_user == source) 163 if (current_user == source)
158 { 164 {
@@ -169,66 +175,67 @@ namespace twitter {
169 _type = type::quoted; 175 _type = type::quoted;
170 176
171 new(&_user_and_tweet._user) user(source); 177 new(&_user_and_tweet._user) user(source);
172 new(&_user_and_tweet._tweet) tweet(_data.at("target_object").dump()); 178 new(&_user_and_tweet._tweet) tweet(tclient, json["target_object"].dump());
173 } 179 }
174 } else if (_data.find("warning") != _data.end()) 180 } else if (!json["warning"].is_null())
175 { 181 {
176 new(&_warning) std::string(_data.at("warning").at("message").get<std::string>()); 182 new(&_warning) std::string(json["warning"]["message"].get<std::string>());
177 183
178 if (_data.at("warning").at("code") == "FALLING_BEHIND") 184 auto warning_code = json["warning"]["code"].get<std::string>();
185 if (warning_code == "FALLING_BEHIND")
179 { 186 {
180 _type = type::stall; 187 _type = type::stall;
181 } else if (_data.at("warning").at("code") == "FOLLOWS_OVER_LIMIT") 188 } else if (warning_code == "FOLLOWS_OVER_LIMIT")
182 { 189 {
183 _type = type::follow_limit; 190 _type = type::follow_limit;
184 } else { 191 } else {
185 _type = type::unknown_warning; 192 _type = type::unknown_warning;
186 } 193 }
187 } else if (_data.find("delete") != _data.end()) 194 } else if (!json["delete"].is_null())
188 { 195 {
189 _type = type::deletion; 196 _type = type::deletion;
190 197
191 _user_id_and_tweet_id._tweet_id = _data.at("delete").at("status").at("id"); 198 _user_id_and_tweet_id._tweet_id = json["delete"]["status"]["id"].get<tweet_id>();
192 _user_id_and_tweet_id._user_id = _data.at("delete").at("status").at("user_id"); 199 _user_id_and_tweet_id._user_id = json["delete"]["status"]["user_id"].get<user_id>();
193 } else if (_data.find("scrub_geo") != _data.end()) 200 } else if (!json["scrub_geo"].is_null())
194 { 201 {
195 _type = type::scrub_location; 202 _type = type::scrub_location;
196 203
197 _user_id_and_tweet_id._tweet_id = _data.at("scrub_geo").at("up_to_status_id"); 204 _user_id_and_tweet_id._tweet_id = json["scrub_geo"]["up_to_status_id"].get<tweet_id>();
198 _user_id_and_tweet_id._user_id = _data.at("scrub_geo").at("user_id"); 205 _user_id_and_tweet_id._user_id = json["scrub_geo"]["user_id"].get<user_id>();
199 } else if (_data.find("limit") != _data.end()) 206 } else if (!json["limit"].is_null())
200 { 207 {
201 _type = type::limit; 208 _type = type::limit;
202 209
203 _limit = _data.at("limit").at("track"); 210 _limit = json["limit"]["track"].get<int>();
204 } else if (_data.find("status_withheld") != _data.end()) 211 } else if (!json["status_withheld"].is_null())
205 { 212 {
206 _type = type::withhold_status; 213 _type = type::withhold_status;
207 214
208 _withhold_status._user_id = _data.at("status_withheld").at("user_id"); 215 _withhold_status._user_id = json["status_withheld"]["user_id"].get<user_id>();
209 _withhold_status._tweet_id = _data.at("status_withheld").at("id"); 216 _withhold_status._tweet_id = json["status_withheld"]["id"].get<tweet_id>();
210 217
211 new(&_withhold_status._countries) std::vector<std::string>(); 218 new(&_withhold_status._countries) std::vector<std::string>();
212 for (auto s : _data.at("status_withheld").at("withheld_in_countries")) 219 for (auto s : json["status_withheld"]["withheld_in_countries"])
213 { 220 {
214 _withhold_status._countries.push_back(s); 221 _withhold_status._countries.push_back(s);
215 } 222 }
216 } else if (_data.find("user_withheld") != _data.end()) 223 } else if (!json["user_withheld"].is_null())
217 { 224 {
218 _type = type::withhold_user; 225 _type = type::withhold_user;
219 226
220 _withhold_user._user_id = _data.at("user_withheld").at("id"); 227 _withhold_user._user_id = json["user_withheld"]["id"].get<user_id>();
221 228
222 new(&_withhold_user._countries) std::vector<std::string>(); 229 new(&_withhold_user._countries) std::vector<std::string>();
223 for (auto s : _data.at("user_withheld").at("withheld_in_countries")) 230 for (auto s : json["user_withheld"]["withheld_in_countries"])
224 { 231 {
225 _withhold_user._countries.push_back(s); 232 _withhold_user._countries.push_back(s);
226 } 233 }
227 } else if (_data.find("disconnect") != _data.end()) 234 } else if (!json["disconnect"].is_null())
228 { 235 {
229 _type = type::disconnect; 236 _type = type::disconnect;
230 237
231 switch (_data.at("disconnect").at("code").get<int>()) 238 switch (json["disconnect"]["code"].get<int>())
232 { 239 {
233 case 1: _disconnect = disconnect_code::shutdown; break; 240 case 1: _disconnect = disconnect_code::shutdown; break;
234 case 2: _disconnect = disconnect_code::duplicate; break; 241 case 2: _disconnect = disconnect_code::duplicate; break;
@@ -242,26 +249,26 @@ namespace twitter {
242 case 12: _disconnect = disconnect_code::load; break; 249 case 12: _disconnect = disconnect_code::load; break;
243 default: _disconnect = disconnect_code::unknown; 250 default: _disconnect = disconnect_code::unknown;
244 } 251 }
245 } else if (_data.find("friends") != _data.end()) 252 } else if (!json["friends"].is_null())
246 { 253 {
247 _type = type::friends; 254 _type = type::friends;
248 255
249 new(&_friends) std::set<user_id>(_data.at("friends").begin(), _data.at("friends").end()); 256 new(&_friends) std::set<user_id>(std::begin(json["friends"]), std::end(json["friends"]));
250 } else if (_data.find("direct_message") != _data.end()) 257 } else if (!json["direct_message"].is_null())
251 { 258 {
252 _type = type::direct; 259 _type = type::direct;
253 260
254 new(&_direct_message) direct_message(_data.at("direct_message").dump()); 261 new(&_direct_message) direct_message(json["direct_message"].dump());
255 } else { 262 } else {
256 _type = type::unknown; 263 _type = type::unknown;
257 } 264 }
258 } catch (std::invalid_argument e) 265 } catch (const std::domain_error& error)
259 { 266 {
260 _type = type::invalid; 267 std::throw_with_nested(invalid_response(data));
261 } 268 }
262 } 269 }
263 270
264 notification::notification(const notification& other) 271 notification::notification(notification&& other)
265 { 272 {
266 _type = other._type; 273 _type = other._type;
267 274
@@ -269,11 +276,11 @@ namespace twitter {
269 { 276 {
270 case type::tweet: 277 case type::tweet:
271 { 278 {
272 new(&_tweet) tweet(other._tweet); 279 new(&_tweet) tweet(std::move(other._tweet));
273 280
274 break; 281 break;
275 } 282 }
276 283
277 case type::update_user: 284 case type::update_user:
278 case type::block: 285 case type::block:
279 case type::unblock: 286 case type::unblock:
@@ -281,32 +288,32 @@ namespace twitter {
281 case type::followed: 288 case type::followed:
282 case type::unfollow: 289 case type::unfollow:
283 { 290 {
284 new(&_user) user(other._user); 291 new(&_user) user(std::move(other._user));
285 292
286 break; 293 break;
287 } 294 }
288 295
289 case type::favorite: 296 case type::favorite:
290 case type::favorited: 297 case type::favorited:
291 case type::unfavorite: 298 case type::unfavorite:
292 case type::unfavorited: 299 case type::unfavorited:
293 case type::quoted: 300 case type::quoted:
294 { 301 {
295 new(&_user_and_tweet._user) user(other._user_and_tweet._user); 302 new(&_user_and_tweet._user) user(std::move(other._user_and_tweet._user));
296 new(&_user_and_tweet._tweet) tweet(other._user_and_tweet._tweet); 303 new(&_user_and_tweet._tweet) tweet(std::move(other._user_and_tweet._tweet));
297 304
298 break; 305 break;
299 } 306 }
300 307
301 case type::list_created: 308 case type::list_created:
302 case type::list_destroyed: 309 case type::list_destroyed:
303 case type::list_updated: 310 case type::list_updated:
304 { 311 {
305 new(&_list) list(other._list); 312 new(&_list) list(std::move(other._list));
306 313
307 break; 314 break;
308 } 315 }
309 316
310 case type::list_add: 317 case type::list_add:
311 case type::list_added: 318 case type::list_added:
312 case type::list_remove: 319 case type::list_remove:
@@ -316,78 +323,84 @@ namespace twitter {
316 case type::list_unsubscribe: 323 case type::list_unsubscribe:
317 case type::list_unsubscribed: 324 case type::list_unsubscribed:
318 { 325 {
319 new(&_user_and_list._user) user(other._user_and_list._user); 326 new(&_user_and_list._user) user(std::move(other._user_and_list._user));
320 new(&_user_and_list._list) list(other._user_and_list._list); 327 new(&_user_and_list._list) list(std::move(other._user_and_list._list));
321 328
322 break; 329 break;
323 } 330 }
324 331
325 case type::stall: 332 case type::stall:
326 case type::follow_limit: 333 case type::follow_limit:
327 case type::unknown_warning: 334 case type::unknown_warning:
328 { 335 {
329 new(&_warning) std::string(other._warning); 336 new(&_warning) std::string(std::move(other._warning));
330 337
331 break; 338 break;
332 } 339 }
333 340
334 case type::deletion: 341 case type::deletion:
335 case type::scrub_location: 342 case type::scrub_location:
336 { 343 {
337 _user_id_and_tweet_id._user_id = other._user_id_and_tweet_id._user_id; 344 _user_id_and_tweet_id._user_id = other._user_id_and_tweet_id._user_id;
338 _user_id_and_tweet_id._tweet_id = other._user_id_and_tweet_id._tweet_id; 345 _user_id_and_tweet_id._tweet_id = other._user_id_and_tweet_id._tweet_id;
339 346
340 break; 347 break;
341 } 348 }
342 349
343 case type::limit: 350 case type::limit:
344 { 351 {
345 _limit = other._limit; 352 _limit = other._limit;
346 353
347 break; 354 break;
348 } 355 }
349 356
350 case type::withhold_status: 357 case type::withhold_status:
351 { 358 {
352 _withhold_status._user_id = other._withhold_status._user_id; 359 _withhold_status._user_id = other._withhold_status._user_id;
353 _withhold_status._tweet_id = other._withhold_status._tweet_id; 360 _withhold_status._tweet_id = other._withhold_status._tweet_id;
354 new(&_withhold_status._countries) std::vector<std::string>(other._withhold_status._countries); 361 new(&_withhold_status._countries) std::vector<std::string>(std::move(other._withhold_status._countries));
355 362
356 break; 363 break;
357 } 364 }
358 365
359 case type::withhold_user: 366 case type::withhold_user:
360 { 367 {
361 _withhold_user._user_id = other._withhold_user._user_id; 368 _withhold_user._user_id = other._withhold_user._user_id;
362 new(&_withhold_user._countries) std::vector<std::string>(other._withhold_user._countries); 369 new(&_withhold_user._countries) std::vector<std::string>(std::move(other._withhold_user._countries));
363 370
364 break; 371 break;
365 } 372 }
366 373
367 case type::disconnect: 374 case type::disconnect:
368 { 375 {
369 _disconnect = other._disconnect; 376 _disconnect = other._disconnect;
370 377
371 break; 378 break;
372 } 379 }
373 380
374 case type::friends: 381 case type::friends:
375 { 382 {
376 new(&_friends) std::set<user_id>(other._friends); 383 new(&_friends) std::set<user_id>(std::move(other._friends));
377 384
378 break; 385 break;
379 } 386 }
380 387
381 case type::direct: 388 case type::direct:
382 { 389 {
383 new(&_direct_message) direct_message(other._direct_message); 390 new(&_direct_message) direct_message(std::move(other._direct_message));
384 391
392 break;
393 }
394
395 case type::unknown:
396 case type::invalid:
397 {
385 break; 398 break;
386 } 399 }
387 } 400 }
388 } 401 }
389 402
390 notification& notification::operator=(const notification& other) 403 notification& notification::operator=(notification&& other)
391 { 404 {
392 this->~notification(); 405 this->~notification();
393 406
@@ -397,7 +410,7 @@ namespace twitter {
397 { 410 {
398 case type::tweet: 411 case type::tweet:
399 { 412 {
400 new(&_tweet) tweet(other._tweet); 413 new(&_tweet) tweet(std::move(other._tweet));
401 414
402 break; 415 break;
403 } 416 }
@@ -409,7 +422,7 @@ namespace twitter {
409 case type::followed: 422 case type::followed:
410 case type::unfollow: 423 case type::unfollow:
411 { 424 {
412 new(&_user) user(other._user); 425 new(&_user) user(std::move(other._user));
413 426
414 break; 427 break;
415 } 428 }
@@ -420,8 +433,8 @@ namespace twitter {
420 case type::unfavorited: 433 case type::unfavorited:
421 case type::quoted: 434 case type::quoted:
422 { 435 {
423 new(&_user_and_tweet._user) user(other._user_and_tweet._user); 436 new(&_user_and_tweet._user) user(std::move(other._user_and_tweet._user));
424 new(&_user_and_tweet._tweet) tweet(other._user_and_tweet._tweet); 437 new(&_user_and_tweet._tweet) tweet(std::move(other._user_and_tweet._tweet));
425 438
426 break; 439 break;
427 } 440 }
@@ -430,7 +443,7 @@ namespace twitter {
430 case type::list_destroyed: 443 case type::list_destroyed:
431 case type::list_updated: 444 case type::list_updated:
432 { 445 {
433 new(&_list) list(other._list); 446 new(&_list) list(std::move(other._list));
434 447
435 break; 448 break;
436 } 449 }
@@ -444,8 +457,8 @@ namespace twitter {
444 case type::list_unsubscribe: 457 case type::list_unsubscribe:
445 case type::list_unsubscribed: 458 case type::list_unsubscribed:
446 { 459 {
447 new(&_user_and_list._user) user(other._user_and_list._user); 460 new(&_user_and_list._user) user(std::move(other._user_and_list._user));
448 new(&_user_and_list._list) list(other._user_and_list._list); 461 new(&_user_and_list._list) list(std::move(other._user_and_list._list));
449 462
450 break; 463 break;
451 } 464 }
@@ -454,7 +467,7 @@ namespace twitter {
454 case type::follow_limit: 467 case type::follow_limit:
455 case type::unknown_warning: 468 case type::unknown_warning:
456 { 469 {
457 new(&_warning) std::string(other._warning); 470 new(&_warning) std::string(std::move(other._warning));
458 471
459 break; 472 break;
460 } 473 }
@@ -479,7 +492,7 @@ namespace twitter {
479 { 492 {
480 _withhold_status._user_id = other._withhold_status._user_id; 493 _withhold_status._user_id = other._withhold_status._user_id;
481 _withhold_status._tweet_id = other._withhold_status._tweet_id; 494 _withhold_status._tweet_id = other._withhold_status._tweet_id;
482 new(&_withhold_status._countries) std::vector<std::string>(other._withhold_status._countries); 495 new(&_withhold_status._countries) std::vector<std::string>(std::move(other._withhold_status._countries));
483 496
484 break; 497 break;
485 } 498 }
@@ -487,7 +500,7 @@ namespace twitter {
487 case type::withhold_user: 500 case type::withhold_user:
488 { 501 {
489 _withhold_user._user_id = other._withhold_user._user_id; 502 _withhold_user._user_id = other._withhold_user._user_id;
490 new(&_withhold_user._countries) std::vector<std::string>(other._withhold_user._countries); 503 new(&_withhold_user._countries) std::vector<std::string>(std::move(other._withhold_user._countries));
491 504
492 break; 505 break;
493 } 506 }
@@ -501,17 +514,23 @@ namespace twitter {
501 514
502 case type::friends: 515 case type::friends:
503 { 516 {
504 new(&_friends) std::set<user_id>(other._friends); 517 new(&_friends) std::set<user_id>(std::move(other._friends));
505 518
506 break; 519 break;
507 } 520 }
508 521
509 case type::direct: 522 case type::direct:
510 { 523 {
511 new(&_direct_message) direct_message(other._direct_message); 524 new(&_direct_message) direct_message(std::move(other._direct_message));
512 525
513 break; 526 break;
514 } 527 }
528
529 case type::invalid:
530 case type::unknown:
531 {
532 break;
533 }
515 } 534 }
516 535
517 return *this; 536 return *this;
@@ -578,6 +597,7 @@ namespace twitter {
578 597
579 case type::stall: 598 case type::stall:
580 case type::follow_limit: 599 case type::follow_limit:
600 case type::unknown_warning:
581 { 601 {
582 using string_type = std::string; 602 using string_type = std::string;
583 _warning.~string_type(); 603 _warning.~string_type();
@@ -615,10 +635,20 @@ namespace twitter {
615 635
616 break; 636 break;
617 } 637 }
638
639 case type::deletion:
640 case type::scrub_location:
641 case type::limit:
642 case type::disconnect:
643 case type::unknown:
644 case type::invalid:
645 {
646 break;
647 }
618 } 648 }
619 } 649 }
620 650
621 tweet notification::getTweet() const 651 const tweet& notification::getTweet() const
622 { 652 {
623 switch (_type) 653 switch (_type)
624 { 654 {
@@ -639,13 +669,11 @@ namespace twitter {
639 default: 669 default:
640 { 670 {
641 assert(false); 671 assert(false);
642
643 return tweet();
644 } 672 }
645 } 673 }
646 } 674 }
647 675
648 user notification::getUser() const 676 const user& notification::getUser() const
649 { 677 {
650 switch (_type) 678 switch (_type)
651 { 679 {
@@ -683,13 +711,11 @@ namespace twitter {
683 default: 711 default:
684 { 712 {
685 assert(false); 713 assert(false);
686
687 return user();
688 } 714 }
689 } 715 }
690 } 716 }
691 717
692 list notification::getList() const 718 const list& notification::getList() const
693 { 719 {
694 switch (_type) 720 switch (_type)
695 { 721 {
@@ -715,8 +741,6 @@ namespace twitter {
715 default: 741 default:
716 { 742 {
717 assert(false); 743 assert(false);
718
719 return list();
720 } 744 }
721 } 745 }
722 } 746 }
@@ -739,8 +763,6 @@ namespace twitter {
739 default: 763 default:
740 { 764 {
741 assert(false); 765 assert(false);
742
743 return 0;
744 } 766 }
745 } 767 }
746 } 768 }
@@ -768,13 +790,11 @@ namespace twitter {
768 default: 790 default:
769 { 791 {
770 assert(false); 792 assert(false);
771
772 return 0;
773 } 793 }
774 } 794 }
775 } 795 }
776 796
777 std::vector<std::string> notification::getCountries() const 797 const std::vector<std::string>& notification::getCountries() const
778 { 798 {
779 switch (_type) 799 switch (_type)
780 { 800 {
@@ -791,8 +811,6 @@ namespace twitter {
791 default: 811 default:
792 { 812 {
793 assert(false); 813 assert(false);
794
795 return std::vector<std::string>();
796 } 814 }
797 } 815 }
798 } 816 }
@@ -804,14 +822,14 @@ namespace twitter {
804 return _disconnect; 822 return _disconnect;
805 } 823 }
806 824
807 std::set<user_id> notification::getFriends() const 825 const std::set<user_id>& notification::getFriends() const
808 { 826 {
809 assert(_type == type::friends); 827 assert(_type == type::friends);
810 828
811 return _friends; 829 return _friends;
812 } 830 }
813 831
814 direct_message notification::getDirectMessage() const 832 const direct_message& notification::getDirectMessage() const
815 { 833 {
816 assert(_type == type::direct); 834 assert(_type == type::direct);
817 835
@@ -825,7 +843,7 @@ namespace twitter {
825 return _limit; 843 return _limit;
826 } 844 }
827 845
828 std::string notification::getWarning() const 846 const std::string& notification::getWarning() const
829 { 847 {
830 switch (_type) 848 switch (_type)
831 { 849 {
@@ -839,15 +857,8 @@ namespace twitter {
839 default: 857 default:
840 { 858 {
841 assert(false); 859 assert(false);
842
843 return "";
844 } 860 }
845 } 861 }
846 } 862 }
847 863
848 notification::operator bool() const
849 {
850 return _type != type::invalid;
851 }
852
853}; 864};