diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-25 21:34:57 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-25 21:34:57 -0400 |
commit | 501880160ac69f90143bc38add541731a9242ab0 (patch) | |
tree | 30c0a94d056cba49b89a272c844cc2f459817fea | |
parent | cec9786bc11c897a00cf7ab8baafb142a709ba27 (diff) | |
download | libtwittercpp-501880160ac69f90143bc38add541731a9242ab0.tar.gz libtwittercpp-501880160ac69f90143bc38add541731a9242ab0.tar.bz2 libtwittercpp-501880160ac69f90143bc38add541731a9242ab0.zip |
Added option to receive all replies in user stream
-rw-r--r-- | src/client.cpp | 40 | ||||
-rw-r--r-- | src/client.h | 5 |
2 files changed, 35 insertions, 10 deletions
diff --git a/src/client.cpp b/src/client.cpp index c6bcd65..b7d1624 100644 --- a/src/client.cpp +++ b/src/client.cpp | |||
@@ -410,6 +410,11 @@ namespace twitter { | |||
410 | _user_stream.setNotifyCallback(callback); | 410 | _user_stream.setNotifyCallback(callback); |
411 | } | 411 | } |
412 | 412 | ||
413 | void client::setUserStreamReceiveAllReplies(bool _arg) | ||
414 | { | ||
415 | _user_stream.setReceiveAllReplies(_arg); | ||
416 | } | ||
417 | |||
413 | void client::startUserStream() | 418 | void client::startUserStream() |
414 | { | 419 | { |
415 | _user_stream.start(); | 420 | _user_stream.start(); |
@@ -614,8 +619,22 @@ namespace twitter { | |||
614 | 619 | ||
615 | void client::stream::setNotifyCallback(notify_callback _n) | 620 | void client::stream::setNotifyCallback(notify_callback _n) |
616 | { | 621 | { |
617 | std::lock_guard<std::mutex> _notify_lock(_notify_mutex); | 622 | std::lock_guard<std::mutex> _running_lock(_running_mutex); |
618 | _notify = _n; | 623 | |
624 | if (!_thread.joinable()) | ||
625 | { | ||
626 | _notify = _n; | ||
627 | } | ||
628 | } | ||
629 | |||
630 | void client::stream::setReceiveAllReplies(bool _arg) | ||
631 | { | ||
632 | std::lock_guard<std::mutex> _running_lock(_running_mutex); | ||
633 | |||
634 | if (!_thread.joinable()) | ||
635 | { | ||
636 | _receive_all_replies = _arg; | ||
637 | } | ||
619 | } | 638 | } |
620 | 639 | ||
621 | void client::stream::start() | 640 | void client::stream::start() |
@@ -643,8 +662,15 @@ namespace twitter { | |||
643 | void client::stream::run() | 662 | void client::stream::run() |
644 | { | 663 | { |
645 | curl::curl_easy conn; | 664 | curl::curl_easy conn; |
646 | std::string url = "https://userstream.twitter.com/1.1/user.json"; | 665 | std::ostringstream urlstr; |
666 | urlstr << "https://userstream.twitter.com/1.1/user.json"; | ||
647 | 667 | ||
668 | if (_receive_all_replies) | ||
669 | { | ||
670 | urlstr << "?replies=all"; | ||
671 | } | ||
672 | |||
673 | std::string url = urlstr.str(); | ||
648 | curl::curl_header headers; | 674 | curl::curl_header headers; |
649 | std::string oauth_header = _client._oauth_client->getFormattedHttpHeader(OAuth::Http::Get, url, ""); | 675 | std::string oauth_header = _client._oauth_client->getFormattedHttpHeader(OAuth::Http::Get, url, ""); |
650 | if (!oauth_header.empty()) | 676 | if (!oauth_header.empty()) |
@@ -768,13 +794,9 @@ namespace twitter { | |||
768 | _backoff_amount = std::chrono::milliseconds(0); | 794 | _backoff_amount = std::chrono::milliseconds(0); |
769 | } | 795 | } |
770 | 796 | ||
797 | if (_notify) | ||
771 | { | 798 | { |
772 | std::lock_guard<std::mutex> _notify_lock(_notify_mutex); | 799 | _notify(n); |
773 | |||
774 | if (_notify) | ||
775 | { | ||
776 | _notify(n); | ||
777 | } | ||
778 | } | 800 | } |
779 | 801 | ||
780 | _buffer = ""; | 802 | _buffer = ""; |
diff --git a/src/client.h b/src/client.h index 901c7b5..c1c6344 100644 --- a/src/client.h +++ b/src/client.h | |||
@@ -31,6 +31,7 @@ namespace twitter { | |||
31 | stream(client& _client); | 31 | stream(client& _client); |
32 | 32 | ||
33 | void setNotifyCallback(notify_callback _n); | 33 | void setNotifyCallback(notify_callback _n); |
34 | void setReceiveAllReplies(bool _arg); | ||
34 | 35 | ||
35 | bool isRunning() const; | 36 | bool isRunning() const; |
36 | void start(); | 37 | void start(); |
@@ -54,13 +55,13 @@ namespace twitter { | |||
54 | bool _stop = false; | 55 | bool _stop = false; |
55 | std::thread _thread; | 56 | std::thread _thread; |
56 | std::mutex _running_mutex; | 57 | std::mutex _running_mutex; |
57 | std::mutex _notify_mutex; | ||
58 | std::mutex _stall_mutex; | 58 | std::mutex _stall_mutex; |
59 | std::string _buffer; | 59 | std::string _buffer; |
60 | time_t _last_write; | 60 | time_t _last_write; |
61 | bool _established = false; | 61 | bool _established = false; |
62 | backoff _backoff_type = backoff::none; | 62 | backoff _backoff_type = backoff::none; |
63 | std::chrono::milliseconds _backoff_amount; | 63 | std::chrono::milliseconds _backoff_amount; |
64 | bool _receive_all_replies = false; | ||
64 | }; | 65 | }; |
65 | 66 | ||
66 | client(const auth& _auth); | 67 | client(const auth& _auth); |
@@ -80,7 +81,9 @@ namespace twitter { | |||
80 | 81 | ||
81 | const user& getUser() const; | 82 | const user& getUser() const; |
82 | 83 | ||
84 | // NOTE: stream setting function calls will fail silently when stream is running | ||
83 | void setUserStreamNotifyCallback(stream::notify_callback callback); | 85 | void setUserStreamNotifyCallback(stream::notify_callback callback); |
86 | void setUserStreamReceiveAllReplies(bool _arg); | ||
84 | void startUserStream(); | 87 | void startUserStream(); |
85 | void stopUserStream(); | 88 | void stopUserStream(); |
86 | 89 | ||