diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e76b85..207ba15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (expandurl-mastodon - VERSION 0.1.3 + VERSION 0.2.0 LANGUAGES CXX ) diff --git a/src/expandurl-mastodon.hpp b/src/expandurl-mastodon.hpp index 3a1c96d..7d2ec87 100644 --- a/src/expandurl-mastodon.hpp +++ b/src/expandurl-mastodon.hpp @@ -78,6 +78,8 @@ public: const bool send_reply(const Easy::Status &to_status, const string &message); const std::uint_fast64_t get_parent_id(Easy::Notification ¬if); + const bool stillrunning() const; + private: string _instance; string _access_token; @@ -85,6 +87,7 @@ private: string _stream; std::unique_ptr _ptr; std::thread _thread; + bool _running; }; #endif // EXPANDURL_MASTODON_HPP diff --git a/src/main.cpp b/src/main.cpp index e5a28d9..b4b9f8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,6 +74,11 @@ int main(int argc, char *argv[]) while (running) { std::this_thread::sleep_for(std::chrono::seconds(2)); + if (!listener.stillrunning()) + { + cerr << "DEBUG: Reestablishing connection...\n"; + listener.start(); + } for (Easy::Notification ¬if : listener.get_new_messages()) { diff --git a/src/masto.cpp b/src/masto.cpp index e5bbe21..13aee61 100644 --- a/src/masto.cpp +++ b/src/masto.cpp @@ -28,6 +28,7 @@ Listener::Listener() , _access_token("") , _stream("") , _ptr(nullptr) +, _running(false) { } @@ -56,10 +57,13 @@ const bool Listener::start() _thread = std::thread([=] { + _running = true; Easy masto(_instance, _access_token); masto.set_useragent(static_cast("expandurl-mastodon/") + global::version); masto.get_stream(Mastodon::API::v1::streaming_user, _stream, _ptr); + cerr << "DEBUG: Connection lost.\n"; + _running = false; }); return true; @@ -182,3 +186,8 @@ const std::uint_fast64_t Listener::get_parent_id(Easy::Notification ¬if) } return 0; } + +const bool Listener::stillrunning() const +{ + return _running; +}