diff options
Diffstat (limited to 'src/notification.cpp')
| -rw-r--r-- | src/notification.cpp | 518 |
1 files changed, 434 insertions, 84 deletions
| diff --git a/src/notification.cpp b/src/notification.cpp index 3269a90..0e46112 100644 --- a/src/notification.cpp +++ b/src/notification.cpp | |||
| @@ -28,16 +28,11 @@ namespace twitter { | |||
| 28 | 28 | ||
| 29 | try | 29 | try |
| 30 | { | 30 | { |
| 31 | if (!json["in_reply_to_status_id"].is_null()) | 31 | if (!json["event"].is_null()) |
| 32 | { | ||
| 33 | _type = type::tweet; | ||
| 34 | |||
| 35 | new(&_tweet) tweet(tclient, data); | ||
| 36 | } else if (!json["event"].is_null()) | ||
| 37 | { | 32 | { |
| 38 | std::string event = json["event"]; | 33 | std::string event = json["event"]; |
| 39 | user source(tclient, json["source"].dump()); | 34 | user source(json["source"].dump()); |
| 40 | user target(tclient, json["target"].dump()); | 35 | user target(json["target"].dump()); |
| 41 | 36 | ||
| 42 | if (event == "user_update") | 37 | if (event == "user_update") |
| 43 | { | 38 | { |
| @@ -56,7 +51,7 @@ namespace twitter { | |||
| 56 | new(&_user) user(target); | 51 | new(&_user) user(target); |
| 57 | } else if (event == "favorite") | 52 | } else if (event == "favorite") |
| 58 | { | 53 | { |
| 59 | new(&_user_and_tweet._tweet) tweet(tclient, json["target_object"].dump()); | 54 | new(&_user_and_tweet._tweet) tweet(json["target_object"].dump()); |
| 60 | 55 | ||
| 61 | if (current_user == source) | 56 | if (current_user == source) |
| 62 | { | 57 | { |
| @@ -70,7 +65,7 @@ namespace twitter { | |||
| 70 | } | 65 | } |
| 71 | } else if (event == "unfavorite") | 66 | } else if (event == "unfavorite") |
| 72 | { | 67 | { |
| 73 | new(&_user_and_tweet._tweet) tweet(tclient, json["target_object"].dump()); | 68 | new(&_user_and_tweet._tweet) tweet(json["target_object"].dump()); |
| 74 | 69 | ||
| 75 | if (current_user == source) | 70 | if (current_user == source) |
| 76 | { | 71 | { |
| @@ -175,7 +170,9 @@ namespace twitter { | |||
| 175 | _type = type::quoted; | 170 | _type = type::quoted; |
| 176 | 171 | ||
| 177 | new(&_user_and_tweet._user) user(source); | 172 | new(&_user_and_tweet._user) user(source); |
| 178 | new(&_user_and_tweet._tweet) tweet(tclient, json["target_object"].dump()); | 173 | new(&_user_and_tweet._tweet) tweet(json["target_object"].dump()); |
| 174 | } else { | ||
| 175 | _type = type::unknown; | ||
| 179 | } | 176 | } |
| 180 | } else if (!json["warning"].is_null()) | 177 | } else if (!json["warning"].is_null()) |
| 181 | { | 178 | { |
| @@ -260,7 +257,9 @@ namespace twitter { | |||
| 260 | 257 | ||
| 261 | new(&_direct_message) direct_message(json["direct_message"].dump()); | 258 | new(&_direct_message) direct_message(json["direct_message"].dump()); |
| 262 | } else { | 259 | } else { |
| 263 | _type = type::unknown; | 260 | _type = type::tweet; |
| 261 | |||
| 262 | new(&_tweet) tweet(data); | ||
| 264 | } | 263 | } |
| 265 | } catch (const std::domain_error& error) | 264 | } catch (const std::domain_error& error) |
| 266 | { | 265 | { |
| @@ -268,7 +267,7 @@ namespace twitter { | |||
| 268 | } | 267 | } |
| 269 | } | 268 | } |
| 270 | 269 | ||
| 271 | notification::notification(notification&& other) | 270 | notification::notification(const notification& other) |
| 272 | { | 271 | { |
| 273 | _type = other._type; | 272 | _type = other._type; |
| 274 | 273 | ||
| @@ -276,7 +275,7 @@ namespace twitter { | |||
| 276 | { | 275 | { |
| 277 | case type::tweet: | 276 | case type::tweet: |
| 278 | { | 277 | { |
| 279 | new(&_tweet) tweet(std::move(other._tweet)); | 278 | new(&_tweet) tweet(other._tweet); |
| 280 | 279 | ||
| 281 | break; | 280 | break; |
| 282 | } | 281 | } |
| @@ -288,7 +287,7 @@ namespace twitter { | |||
| 288 | case type::followed: | 287 | case type::followed: |
| 289 | case type::unfollow: | 288 | case type::unfollow: |
| 290 | { | 289 | { |
| 291 | new(&_user) user(std::move(other._user)); | 290 | new(&_user) user(other._user); |
| 292 | 291 | ||
| 293 | break; | 292 | break; |
| 294 | } | 293 | } |
| @@ -299,8 +298,8 @@ namespace twitter { | |||
| 299 | case type::unfavorited: | 298 | case type::unfavorited: |
| 300 | case type::quoted: | 299 | case type::quoted: |
| 301 | { | 300 | { |
| 302 | new(&_user_and_tweet._user) user(std::move(other._user_and_tweet._user)); | 301 | new(&_user_and_tweet._user) user(other._user_and_tweet._user); |
| 303 | new(&_user_and_tweet._tweet) tweet(std::move(other._user_and_tweet._tweet)); | 302 | new(&_user_and_tweet._tweet) tweet(other._user_and_tweet._tweet); |
| 304 | 303 | ||
| 305 | break; | 304 | break; |
| 306 | } | 305 | } |
| @@ -309,7 +308,7 @@ namespace twitter { | |||
| 309 | case type::list_destroyed: | 308 | case type::list_destroyed: |
| 310 | case type::list_updated: | 309 | case type::list_updated: |
| 311 | { | 310 | { |
| 312 | new(&_list) list(std::move(other._list)); | 311 | new(&_list) list(other._list); |
| 313 | 312 | ||
| 314 | break; | 313 | break; |
| 315 | } | 314 | } |
| @@ -323,8 +322,8 @@ namespace twitter { | |||
| 323 | case type::list_unsubscribe: | 322 | case type::list_unsubscribe: |
| 324 | case type::list_unsubscribed: | 323 | case type::list_unsubscribed: |
| 325 | { | 324 | { |
| 326 | new(&_user_and_list._user) user(std::move(other._user_and_list._user)); | 325 | new(&_user_and_list._user) user(other._user_and_list._user); |
| 327 | new(&_user_and_list._list) list(std::move(other._user_and_list._list)); | 326 | new(&_user_and_list._list) list(other._user_and_list._list); |
| 328 | 327 | ||
| 329 | break; | 328 | break; |
| 330 | } | 329 | } |
| @@ -333,7 +332,7 @@ namespace twitter { | |||
| 333 | case type::follow_limit: | 332 | case type::follow_limit: |
| 334 | case type::unknown_warning: | 333 | case type::unknown_warning: |
| 335 | { | 334 | { |
| 336 | new(&_warning) std::string(std::move(other._warning)); | 335 | new(&_warning) std::string(other._warning); |
| 337 | 336 | ||
| 338 | break; | 337 | break; |
| 339 | } | 338 | } |
| @@ -358,7 +357,7 @@ namespace twitter { | |||
| 358 | { | 357 | { |
| 359 | _withhold_status._user_id = other._withhold_status._user_id; | 358 | _withhold_status._user_id = other._withhold_status._user_id; |
| 360 | _withhold_status._tweet_id = other._withhold_status._tweet_id; | 359 | _withhold_status._tweet_id = other._withhold_status._tweet_id; |
| 361 | new(&_withhold_status._countries) std::vector<std::string>(std::move(other._withhold_status._countries)); | 360 | new(&_withhold_status._countries) std::vector<std::string>(other._withhold_status._countries); |
| 362 | 361 | ||
| 363 | break; | 362 | break; |
| 364 | } | 363 | } |
| @@ -366,7 +365,7 @@ namespace twitter { | |||
| 366 | case type::withhold_user: | 365 | case type::withhold_user: |
| 367 | { | 366 | { |
| 368 | _withhold_user._user_id = other._withhold_user._user_id; | 367 | _withhold_user._user_id = other._withhold_user._user_id; |
| 369 | new(&_withhold_user._countries) std::vector<std::string>(std::move(other._withhold_user._countries)); | 368 | new(&_withhold_user._countries) std::vector<std::string>(other._withhold_user._countries); |
| 370 | 369 | ||
| 371 | break; | 370 | break; |
| 372 | } | 371 | } |
| @@ -380,14 +379,14 @@ namespace twitter { | |||
| 380 | 379 | ||
| 381 | case type::friends: | 380 | case type::friends: |
| 382 | { | 381 | { |
| 383 | new(&_friends) std::set<user_id>(std::move(other._friends)); | 382 | new(&_friends) std::set<user_id>(other._friends); |
| 384 | 383 | ||
| 385 | break; | 384 | break; |
| 386 | } | 385 | } |
| 387 | 386 | ||
| 388 | case type::direct: | 387 | case type::direct: |
| 389 | { | 388 | { |
| 390 | new(&_direct_message) direct_message(std::move(other._direct_message)); | 389 | new(&_direct_message) direct_message(other._direct_message); |
| 391 | 390 | ||
| 392 | break; | 391 | break; |
| 393 | } | 392 | } |
| @@ -400,17 +399,25 @@ namespace twitter { | |||
| 400 | } | 399 | } |
| 401 | } | 400 | } |
| 402 | 401 | ||
| 403 | notification& notification::operator=(notification&& other) | 402 | notification::notification(notification&& other) : notification() |
| 404 | { | 403 | { |
| 405 | this->~notification(); | 404 | swap(*this, other); |
| 406 | 405 | } | |
| 407 | _type = other._type; | 406 | |
| 407 | notification& notification::operator=(notification other) | ||
| 408 | { | ||
| 409 | swap(*this, other); | ||
| 408 | 410 | ||
| 411 | return *this; | ||
| 412 | } | ||
| 413 | |||
| 414 | notification::~notification() | ||
| 415 | { | ||
| 409 | switch (_type) | 416 | switch (_type) |
| 410 | { | 417 | { |
| 411 | case type::tweet: | 418 | case type::tweet: |
| 412 | { | 419 | { |
| 413 | new(&_tweet) tweet(std::move(other._tweet)); | 420 | _tweet.~tweet(); |
| 414 | 421 | ||
| 415 | break; | 422 | break; |
| 416 | } | 423 | } |
| @@ -422,7 +429,7 @@ namespace twitter { | |||
| 422 | case type::followed: | 429 | case type::followed: |
| 423 | case type::unfollow: | 430 | case type::unfollow: |
| 424 | { | 431 | { |
| 425 | new(&_user) user(std::move(other._user)); | 432 | _user.~user(); |
| 426 | 433 | ||
| 427 | break; | 434 | break; |
| 428 | } | 435 | } |
| @@ -433,8 +440,8 @@ namespace twitter { | |||
| 433 | case type::unfavorited: | 440 | case type::unfavorited: |
| 434 | case type::quoted: | 441 | case type::quoted: |
| 435 | { | 442 | { |
| 436 | new(&_user_and_tweet._user) user(std::move(other._user_and_tweet._user)); | 443 | _user_and_tweet._user.~user(); |
| 437 | new(&_user_and_tweet._tweet) tweet(std::move(other._user_and_tweet._tweet)); | 444 | _user_and_tweet._tweet.~tweet(); |
| 438 | 445 | ||
| 439 | break; | 446 | break; |
| 440 | } | 447 | } |
| @@ -443,7 +450,7 @@ namespace twitter { | |||
| 443 | case type::list_destroyed: | 450 | case type::list_destroyed: |
| 444 | case type::list_updated: | 451 | case type::list_updated: |
| 445 | { | 452 | { |
| 446 | new(&_list) list(std::move(other._list)); | 453 | _list.~list(); |
| 447 | 454 | ||
| 448 | break; | 455 | break; |
| 449 | } | 456 | } |
| @@ -457,8 +464,8 @@ namespace twitter { | |||
| 457 | case type::list_unsubscribe: | 464 | case type::list_unsubscribe: |
| 458 | case type::list_unsubscribed: | 465 | case type::list_unsubscribed: |
| 459 | { | 466 | { |
| 460 | new(&_user_and_list._user) user(std::move(other._user_and_list._user)); | 467 | _user_and_list._user.~user(); |
| 461 | new(&_user_and_list._list) list(std::move(other._user_and_list._list)); | 468 | _user_and_list._list.~list(); |
| 462 | 469 | ||
| 463 | break; | 470 | break; |
| 464 | } | 471 | } |
| @@ -467,65 +474,192 @@ namespace twitter { | |||
| 467 | case type::follow_limit: | 474 | case type::follow_limit: |
| 468 | case type::unknown_warning: | 475 | case type::unknown_warning: |
| 469 | { | 476 | { |
| 470 | new(&_warning) std::string(std::move(other._warning)); | 477 | using string_type = std::string; |
| 478 | _warning.~string_type(); | ||
| 471 | 479 | ||
| 472 | break; | 480 | break; |
| 473 | } | 481 | } |
| 474 | 482 | ||
| 475 | case type::deletion: | 483 | case type::withhold_status: |
| 476 | case type::scrub_location: | ||
| 477 | { | 484 | { |
| 478 | _user_id_and_tweet_id._user_id = other._user_id_and_tweet_id._user_id; | 485 | using list_type = std::vector<std::string>; |
| 479 | _user_id_and_tweet_id._tweet_id = other._user_id_and_tweet_id._tweet_id; | 486 | _withhold_status._countries.~list_type(); |
| 480 | 487 | ||
| 481 | break; | 488 | break; |
| 482 | } | 489 | } |
| 483 | 490 | ||
| 484 | case type::limit: | 491 | case type::withhold_user: |
| 485 | { | 492 | { |
| 486 | _limit = other._limit; | 493 | using list_type = std::vector<std::string>; |
| 494 | _withhold_user._countries.~list_type(); | ||
| 487 | 495 | ||
| 488 | break; | 496 | break; |
| 489 | } | 497 | } |
| 490 | 498 | ||
| 491 | case type::withhold_status: | 499 | case type::friends: |
| 492 | { | 500 | { |
| 493 | _withhold_status._user_id = other._withhold_status._user_id; | 501 | using list_type = std::set<user_id>; |
| 494 | _withhold_status._tweet_id = other._withhold_status._tweet_id; | 502 | _friends.~list_type(); |
| 495 | new(&_withhold_status._countries) std::vector<std::string>(std::move(other._withhold_status._countries)); | ||
| 496 | 503 | ||
| 497 | break; | 504 | break; |
| 498 | } | 505 | } |
| 499 | 506 | ||
| 500 | case type::withhold_user: | 507 | case type::direct: |
| 501 | { | 508 | { |
| 502 | _withhold_user._user_id = other._withhold_user._user_id; | 509 | _direct_message.~direct_message(); |
| 503 | new(&_withhold_user._countries) std::vector<std::string>(std::move(other._withhold_user._countries)); | ||
| 504 | 510 | ||
| 505 | break; | 511 | break; |
| 506 | } | 512 | } |
| 507 | 513 | ||
| 514 | case type::deletion: | ||
| 515 | case type::scrub_location: | ||
| 516 | case type::limit: | ||
| 508 | case type::disconnect: | 517 | case type::disconnect: |
| 518 | case type::unknown: | ||
| 519 | case type::invalid: | ||
| 509 | { | 520 | { |
| 510 | _disconnect = other._disconnect; | 521 | break; |
| 522 | } | ||
| 523 | } | ||
| 524 | } | ||
| 525 | |||
| 526 | void swap(notification& first, notification& second) | ||
| 527 | { | ||
| 528 | using type = notification::type; | ||
| 529 | |||
| 530 | type tempType = first._type; | ||
| 531 | tweet tempTweet; | ||
| 532 | user tempUser; | ||
| 533 | list tempList; | ||
| 534 | std::string tempWarning; | ||
| 535 | user_id tempUserId; | ||
| 536 | tweet_id tempTweetId; | ||
| 537 | int tempLimit; | ||
| 538 | std::vector<std::string> tempCountries; | ||
| 539 | disconnect_code tempDisconnectCode; | ||
| 540 | std::set<user_id> tempFriends; | ||
| 541 | direct_message tempDirectMessage; | ||
| 542 | |||
| 543 | switch (first._type) | ||
| 544 | { | ||
| 545 | case type::tweet: | ||
| 546 | { | ||
| 547 | tempTweet = std::move(first._tweet); | ||
| 511 | 548 | ||
| 512 | break; | 549 | break; |
| 513 | } | 550 | } |
| 514 | 551 | ||
| 515 | case type::friends: | 552 | case type::update_user: |
| 553 | case type::block: | ||
| 554 | case type::unblock: | ||
| 555 | case type::follow: | ||
| 556 | case type::followed: | ||
| 557 | case type::unfollow: | ||
| 516 | { | 558 | { |
| 517 | new(&_friends) std::set<user_id>(std::move(other._friends)); | 559 | tempUser = std::move(first._user); |
| 518 | 560 | ||
| 519 | break; | 561 | break; |
| 520 | } | 562 | } |
| 563 | |||
| 564 | case type::favorite: | ||
| 565 | case type::favorited: | ||
| 566 | case type::unfavorite: | ||
| 567 | case type::unfavorited: | ||
| 568 | case type::quoted: | ||
| 569 | { | ||
| 570 | tempTweet = std::move(first._user_and_tweet._tweet); | ||
| 571 | tempUser = std::move(first._user_and_tweet._user); | ||
| 521 | 572 | ||
| 522 | case type::direct: | 573 | break; |
| 574 | } | ||
| 575 | |||
| 576 | case type::list_created: | ||
| 577 | case type::list_destroyed: | ||
| 578 | case type::list_updated: | ||
| 523 | { | 579 | { |
| 524 | new(&_direct_message) direct_message(std::move(other._direct_message)); | 580 | tempList = std::move(first._list); |
| 525 | 581 | ||
| 582 | break; | ||
| 583 | } | ||
| 584 | |||
| 585 | case type::list_add: | ||
| 586 | case type::list_added: | ||
| 587 | case type::list_remove: | ||
| 588 | case type::list_removed: | ||
| 589 | case type::list_subscribe: | ||
| 590 | case type::list_subscribed: | ||
| 591 | case type::list_unsubscribe: | ||
| 592 | case type::list_unsubscribed: | ||
| 593 | { | ||
| 594 | tempList = std::move(first._user_and_list._list); | ||
| 595 | tempUser = std::move(first._user_and_list._user); | ||
| 596 | |||
| 597 | break; | ||
| 598 | } | ||
| 599 | |||
| 600 | case type::stall: | ||
| 601 | case type::follow_limit: | ||
| 602 | case type::unknown_warning: | ||
| 603 | { | ||
| 604 | tempWarning = std::move(first._warning); | ||
| 605 | |||
| 526 | break; | 606 | break; |
| 527 | } | 607 | } |
| 608 | |||
| 609 | case type::deletion: | ||
| 610 | case type::scrub_location: | ||
| 611 | { | ||
| 612 | tempUserId = first._user_id_and_tweet_id._user_id; | ||
| 613 | tempTweetId = first._user_id_and_tweet_id._tweet_id; | ||
| 614 | |||
| 615 | break; | ||
| 616 | } | ||
| 617 | |||
| 618 | case type::limit: | ||
| 619 | { | ||
| 620 | tempLimit = first._limit; | ||
| 528 | 621 | ||
| 622 | break; | ||
| 623 | } | ||
| 624 | |||
| 625 | case type::withhold_status: | ||
| 626 | { | ||
| 627 | tempUserId = first._withhold_status._user_id; | ||
| 628 | tempTweetId = first._withhold_status._tweet_id; | ||
| 629 | tempCountries = std::move(first._withhold_status._countries); | ||
| 630 | |||
| 631 | break; | ||
| 632 | } | ||
| 633 | |||
| 634 | case type::withhold_user: | ||
| 635 | { | ||
| 636 | tempUserId = first._withhold_user._user_id; | ||
| 637 | tempCountries = std::move(first._withhold_user._countries); | ||
| 638 | |||
| 639 | break; | ||
| 640 | } | ||
| 641 | |||
| 642 | case type::disconnect: | ||
| 643 | { | ||
| 644 | tempDisconnectCode = first._disconnect; | ||
| 645 | |||
| 646 | break; | ||
| 647 | } | ||
| 648 | |||
| 649 | case type::friends: | ||
| 650 | { | ||
| 651 | tempFriends = std::move(first._friends); | ||
| 652 | |||
| 653 | break; | ||
| 654 | } | ||
| 655 | |||
| 656 | case type::direct: | ||
| 657 | { | ||
| 658 | tempDirectMessage = std::move(first._direct_message); | ||
| 659 | |||
| 660 | break; | ||
| 661 | } | ||
| 662 | |||
| 529 | case type::invalid: | 663 | case type::invalid: |
| 530 | case type::unknown: | 664 | case type::unknown: |
| 531 | { | 665 | { |
| @@ -533,16 +667,19 @@ namespace twitter { | |||
| 533 | } | 667 | } |
| 534 | } | 668 | } |
| 535 | 669 | ||
| 536 | return *this; | 670 | first.~notification(); |
| 537 | } | 671 | |
| 538 | 672 | first._type = second._type; | |
| 539 | notification::~notification() | 673 | |
| 540 | { | 674 | // Okay now you need to initialize the first with the data from the second |
| 541 | switch (_type) | 675 | // And then destruct the second and initialize it with the data stored in temp |
| 676 | // This is hell | ||
| 677 | |||
| 678 | switch (second._type) | ||
| 542 | { | 679 | { |
| 543 | case type::tweet: | 680 | case type::tweet: |
| 544 | { | 681 | { |
| 545 | _tweet.~tweet(); | 682 | new(&first._tweet) tweet(std::move(second._tweet)); |
| 546 | 683 | ||
| 547 | break; | 684 | break; |
| 548 | } | 685 | } |
| @@ -554,7 +691,7 @@ namespace twitter { | |||
| 554 | case type::followed: | 691 | case type::followed: |
| 555 | case type::unfollow: | 692 | case type::unfollow: |
| 556 | { | 693 | { |
| 557 | _user.~user(); | 694 | new(&first._user) user(std::move(second._user)); |
| 558 | 695 | ||
| 559 | break; | 696 | break; |
| 560 | } | 697 | } |
| @@ -565,8 +702,8 @@ namespace twitter { | |||
| 565 | case type::unfavorited: | 702 | case type::unfavorited: |
| 566 | case type::quoted: | 703 | case type::quoted: |
| 567 | { | 704 | { |
| 568 | _user_and_tweet._user.~user(); | 705 | new(&first._user_and_tweet._user) user(std::move(second._user_and_tweet._user)); |
| 569 | _user_and_tweet._tweet.~tweet(); | 706 | new(&first._user_and_tweet._tweet) tweet(std::move(second._user_and_tweet._tweet)); |
| 570 | 707 | ||
| 571 | break; | 708 | break; |
| 572 | } | 709 | } |
| @@ -575,7 +712,7 @@ namespace twitter { | |||
| 575 | case type::list_destroyed: | 712 | case type::list_destroyed: |
| 576 | case type::list_updated: | 713 | case type::list_updated: |
| 577 | { | 714 | { |
| 578 | _list.~list(); | 715 | new(&first._list) list(std::move(second._list)); |
| 579 | 716 | ||
| 580 | break; | 717 | break; |
| 581 | } | 718 | } |
| @@ -589,8 +726,8 @@ namespace twitter { | |||
| 589 | case type::list_unsubscribe: | 726 | case type::list_unsubscribe: |
| 590 | case type::list_unsubscribed: | 727 | case type::list_unsubscribed: |
| 591 | { | 728 | { |
| 592 | _user_and_list._user.~user(); | 729 | new(&first._user_and_list._user) user(std::move(second._user_and_list._user)); |
| 593 | _user_and_list._list.~list(); | 730 | new(&first._user_and_list._list) list(std::move(second._user_and_list._list)); |
| 594 | 731 | ||
| 595 | break; | 732 | break; |
| 596 | } | 733 | } |
| @@ -599,49 +736,199 @@ namespace twitter { | |||
| 599 | case type::follow_limit: | 736 | case type::follow_limit: |
| 600 | case type::unknown_warning: | 737 | case type::unknown_warning: |
| 601 | { | 738 | { |
| 602 | using string_type = std::string; | 739 | new(&first._warning) std::string(std::move(second._warning)); |
| 603 | _warning.~string_type(); | 740 | |
| 741 | break; | ||
| 742 | } | ||
| 743 | |||
| 744 | case type::deletion: | ||
| 745 | case type::scrub_location: | ||
| 746 | { | ||
| 747 | first._user_id_and_tweet_id._user_id = second._user_id_and_tweet_id._user_id; | ||
| 748 | first._user_id_and_tweet_id._tweet_id = second._user_id_and_tweet_id._tweet_id; | ||
| 749 | |||
| 750 | break; | ||
| 751 | } | ||
| 752 | |||
| 753 | case type::limit: | ||
| 754 | { | ||
| 755 | first._limit = second._limit; | ||
| 604 | 756 | ||
| 605 | break; | 757 | break; |
| 606 | } | 758 | } |
| 607 | 759 | ||
| 608 | case type::withhold_status: | 760 | case type::withhold_status: |
| 609 | { | 761 | { |
| 610 | using list_type = std::vector<std::string>; | 762 | first._withhold_status._user_id = second._withhold_status._user_id; |
| 611 | _withhold_status._countries.~list_type(); | 763 | first._withhold_status._tweet_id = second._withhold_status._tweet_id; |
| 612 | 764 | new(&first._withhold_status._countries) std::vector<std::string>(std::move(second._withhold_status._countries)); | |
| 765 | |||
| 613 | break; | 766 | break; |
| 614 | } | 767 | } |
| 615 | 768 | ||
| 616 | case type::withhold_user: | 769 | case type::withhold_user: |
| 617 | { | 770 | { |
| 618 | using list_type = std::vector<std::string>; | 771 | first._withhold_user._user_id = second._withhold_user._user_id; |
| 619 | _withhold_user._countries.~list_type(); | 772 | new(&first._withhold_user._countries) std::vector<std::string>(std::move(second._withhold_user._countries)); |
| 620 | 773 | ||
| 621 | break; | 774 | break; |
| 622 | } | 775 | } |
| 623 | 776 | ||
| 777 | case type::disconnect: | ||
| 778 | { | ||
| 779 | first._disconnect = second._disconnect; | ||
| 780 | |||
| 781 | break; | ||
| 782 | } | ||
| 783 | |||
| 624 | case type::friends: | 784 | case type::friends: |
| 625 | { | 785 | { |
| 626 | using list_type = std::set<user_id>; | 786 | new(&first._friends) std::set<user_id>(std::move(second._friends)); |
| 627 | _friends.~list_type(); | ||
| 628 | 787 | ||
| 629 | break; | 788 | break; |
| 630 | } | 789 | } |
| 631 | 790 | ||
| 632 | case type::direct: | 791 | case type::direct: |
| 633 | { | 792 | { |
| 634 | _direct_message.~direct_message(); | 793 | new(&first._direct_message) direct_message(std::move(second._direct_message)); |
| 635 | 794 | ||
| 636 | break; | 795 | break; |
| 637 | } | 796 | } |
| 638 | 797 | ||
| 798 | case type::invalid: | ||
| 799 | case type::unknown: | ||
| 800 | { | ||
| 801 | break; | ||
| 802 | } | ||
| 803 | } | ||
| 804 | |||
| 805 | // Now destruct the second and initialize it with data from the first | ||
| 806 | second.~notification(); | ||
| 807 | |||
| 808 | second._type = tempType; | ||
| 809 | |||
| 810 | switch (tempType) | ||
| 811 | { | ||
| 812 | case type::tweet: | ||
| 813 | { | ||
| 814 | new(&second._tweet) tweet(std::move(tempTweet)); | ||
| 815 | |||
| 816 | break; | ||
| 817 | } | ||
| 818 | |||
| 819 | case type::update_user: | ||
| 820 | case type::block: | ||
| 821 | case type::unblock: | ||
| 822 | case type::follow: | ||
| 823 | case type::followed: | ||
| 824 | case type::unfollow: | ||
| 825 | { | ||
| 826 | new(&second._user) user(std::move(tempUser)); | ||
| 827 | |||
| 828 | break; | ||
| 829 | } | ||
| 830 | |||
| 831 | case type::favorite: | ||
| 832 | case type::favorited: | ||
| 833 | case type::unfavorite: | ||
| 834 | case type::unfavorited: | ||
| 835 | case type::quoted: | ||
| 836 | { | ||
| 837 | new(&second._user_and_tweet._user) user(std::move(tempUser)); | ||
| 838 | new(&second._user_and_tweet._tweet) tweet(std::move(tempTweet)); | ||
| 839 | |||
| 840 | break; | ||
| 841 | } | ||
| 842 | |||
| 843 | case type::list_created: | ||
| 844 | case type::list_destroyed: | ||
| 845 | case type::list_updated: | ||
| 846 | { | ||
| 847 | new(&second._list) list(std::move(tempList)); | ||
| 848 | |||
| 849 | break; | ||
| 850 | } | ||
| 851 | |||
| 852 | case type::list_add: | ||
| 853 | case type::list_added: | ||
| 854 | case type::list_remove: | ||
| 855 | case type::list_removed: | ||
| 856 | case type::list_subscribe: | ||
| 857 | case type::list_subscribed: | ||
| 858 | case type::list_unsubscribe: | ||
| 859 | case type::list_unsubscribed: | ||
| 860 | { | ||
| 861 | new(&second._user_and_list._user) user(std::move(tempUser)); | ||
| 862 | new(&second._user_and_list._list) list(std::move(tempList)); | ||
| 863 | |||
| 864 | break; | ||
| 865 | } | ||
| 866 | |||
| 867 | case type::stall: | ||
| 868 | case type::follow_limit: | ||
| 869 | case type::unknown_warning: | ||
| 870 | { | ||
| 871 | new(&second._warning) std::string(std::move(tempWarning)); | ||
| 872 | |||
| 873 | break; | ||
| 874 | } | ||
| 875 | |||
| 639 | case type::deletion: | 876 | case type::deletion: |
| 640 | case type::scrub_location: | 877 | case type::scrub_location: |
| 878 | { | ||
| 879 | second._user_id_and_tweet_id._user_id = tempUserId; | ||
| 880 | second._user_id_and_tweet_id._tweet_id = tempTweetId; | ||
| 881 | |||
| 882 | break; | ||
| 883 | } | ||
| 884 | |||
| 641 | case type::limit: | 885 | case type::limit: |
| 886 | { | ||
| 887 | second._limit = tempLimit; | ||
| 888 | |||
| 889 | break; | ||
| 890 | } | ||
| 891 | |||
| 892 | case type::withhold_status: | ||
| 893 | { | ||
| 894 | second._withhold_status._user_id = tempUserId; | ||
| 895 | second._withhold_status._tweet_id = tempTweetId; | ||
| 896 | new(&second._withhold_status._countries) std::vector<std::string>(std::move(tempCountries)); | ||
| 897 | |||
| 898 | break; | ||
| 899 | } | ||
| 900 | |||
| 901 | case type::withhold_user: | ||
| 902 | { | ||
| 903 | second._withhold_user._user_id = tempUserId; | ||
| 904 | new(&second._withhold_user._countries) std::vector<std::string>(std::move(tempCountries)); | ||
| 905 | |||
| 906 | break; | ||
| 907 | } | ||
| 908 | |||
| 642 | case type::disconnect: | 909 | case type::disconnect: |
| 643 | case type::unknown: | 910 | { |
| 911 | second._disconnect = tempDisconnectCode; | ||
| 912 | |||
| 913 | break; | ||
| 914 | } | ||
| 915 | |||
| 916 | case type::friends: | ||
| 917 | { | ||
| 918 | new(&second._friends) std::set<user_id>(std::move(tempFriends)); | ||
| 919 | |||
| 920 | break; | ||
| 921 | } | ||
| 922 | |||
| 923 | case type::direct: | ||
| 924 | { | ||
| 925 | new(&second._direct_message) direct_message(std::move(tempDirectMessage)); | ||
| 926 | |||
| 927 | break; | ||
| 928 | } | ||
| 929 | |||
| 644 | case type::invalid: | 930 | case type::invalid: |
| 931 | case type::unknown: | ||
| 645 | { | 932 | { |
| 646 | break; | 933 | break; |
| 647 | } | 934 | } |
| @@ -767,6 +1054,28 @@ namespace twitter { | |||
| 767 | } | 1054 | } |
| 768 | } | 1055 | } |
| 769 | 1056 | ||
| 1057 | void notification::setTweetID(tweet_id _arg) | ||
| 1058 | { | ||
| 1059 | switch (_type) | ||
| 1060 | { | ||
| 1061 | case type::deletion: | ||
| 1062 | case type::scrub_location: | ||
| 1063 | { | ||
| 1064 | _user_id_and_tweet_id._tweet_id = _arg;; | ||
| 1065 | } | ||
| 1066 | |||
| 1067 | case type::withhold_status: | ||
| 1068 | { | ||
| 1069 | _withhold_status._tweet_id = _arg; | ||
| 1070 | } | ||
| 1071 | |||
| 1072 | default: | ||
| 1073 | { | ||
| 1074 | assert(false); | ||
| 1075 | } | ||
| 1076 | } | ||
| 1077 | } | ||
| 1078 | |||
| 770 | user_id notification::getUserID() const | 1079 | user_id notification::getUserID() const |
| 771 | { | 1080 | { |
| 772 | switch (_type) | 1081 | switch (_type) |
| @@ -794,6 +1103,33 @@ namespace twitter { | |||
| 794 | } | 1103 | } |
| 795 | } | 1104 | } |
| 796 | 1105 | ||
| 1106 | void notification::setUserID(user_id _arg) | ||
| 1107 | { | ||
| 1108 | switch (_type) | ||
| 1109 | { | ||
| 1110 | case type::deletion: | ||
| 1111 | case type::scrub_location: | ||
| 1112 | { | ||
| 1113 | _user_id_and_tweet_id._user_id = _arg; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | case type::withhold_status: | ||
| 1117 | { | ||
| 1118 | _withhold_status._user_id = _arg; | ||
| 1119 | } | ||
| 1120 | |||
| 1121 | case type::withhold_user: | ||
| 1122 | { | ||
| 1123 | _withhold_user._user_id = _arg; | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | default: | ||
| 1127 | { | ||
| 1128 | assert(false); | ||
| 1129 | } | ||
| 1130 | } | ||
| 1131 | } | ||
| 1132 | |||
| 797 | const std::vector<std::string>& notification::getCountries() const | 1133 | const std::vector<std::string>& notification::getCountries() const |
| 798 | { | 1134 | { |
| 799 | switch (_type) | 1135 | switch (_type) |
| @@ -822,6 +1158,13 @@ namespace twitter { | |||
| 822 | return _disconnect; | 1158 | return _disconnect; |
| 823 | } | 1159 | } |
| 824 | 1160 | ||
| 1161 | void notification::setDisconnectCode(disconnect_code _arg) | ||
| 1162 | { | ||
| 1163 | assert(_type == type::disconnect); | ||
| 1164 | |||
| 1165 | _disconnect = _arg; | ||
| 1166 | } | ||
| 1167 | |||
| 825 | const std::set<user_id>& notification::getFriends() const | 1168 | const std::set<user_id>& notification::getFriends() const |
| 826 | { | 1169 | { |
| 827 | assert(_type == type::friends); | 1170 | assert(_type == type::friends); |
| @@ -843,6 +1186,13 @@ namespace twitter { | |||
| 843 | return _limit; | 1186 | return _limit; |
| 844 | } | 1187 | } |
| 845 | 1188 | ||
| 1189 | void notification::setLimit(int _arg) | ||
| 1190 | { | ||
| 1191 | assert(_type == type::limit); | ||
| 1192 | |||
| 1193 | _limit = _arg; | ||
| 1194 | } | ||
| 1195 | |||
| 846 | const std::string& notification::getWarning() const | 1196 | const std::string& notification::getWarning() const |
| 847 | { | 1197 | { |
| 848 | switch (_type) | 1198 | switch (_type) |
