diff --git a/doc/changelog.md b/doc/changelog.md index c998f29d..ca6b7122 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -16,6 +16,8 @@ As we're sure users of TWBlue and other third-party clients already know, Twitte * TWBlue will now read default visibility preferences when posting new statuses, and display sensitive content. These preferences can be set on the mastodon instance, in the account's preferences section. If you wish to change TWBlue's behavior and have it not read those preferences from your instance, but instead set the default public visibility and hide sensitive content, you can uncheck the Read preferences from instance checkbox in the account options. * If a mastodon instance is not active or there are errors during login, TWBlue will report it in the log file and will continue with other sessions. * When replying to someone in a public post, TWBlue will default to "unlisted" as its visibility setting. This is done so replies will not clutter local and federated timelines. This setting might be changed when writing the reply, though. ([#504,](https://github.com/MCV-Software/TWBlue/issues/504)) + * TWBlue uses its own user agent in Mastodon sessions, so it will be easier to identify the client for instance admins. + * TWBlue will check if the streaming API endpoints are available before attempting to start Streaming for the current session. Before, TWBlue caused load issues in misconfigured mastodon instances where the streaming API were not available. ## Changes in version 2022.12.13 diff --git a/src/sessions/mastodon/session.py b/src/sessions/mastodon/session.py index 9bf0c1f8..82de4417 100644 --- a/src/sessions/mastodon/session.py +++ b/src/sessions/mastodon/session.py @@ -39,7 +39,7 @@ class Session(base.baseSession): if self.settings["mastodon"]["access_token"] != None and self.settings["mastodon"]["instance"] != None: try: log.debug("Logging in to Mastodon instance {}...".format(self.settings["mastodon"]["instance"])) - self.api = mastodon.Mastodon(access_token=self.settings["mastodon"]["access_token"], api_base_url=self.settings["mastodon"]["instance"], mastodon_version=MASTODON_VERSION) + self.api = mastodon.Mastodon(access_token=self.settings["mastodon"]["access_token"], api_base_url=self.settings["mastodon"]["instance"], mastodon_version=MASTODON_VERSION, user_agent="TWBlue/{}".format(application.version)) if verify_credentials == True: credentials = self.api.account_verify_credentials() self.db["user_name"] = credentials["username"] @@ -226,8 +226,14 @@ class Session(base.baseSession): if config.app["app-settings"]["no_streaming"]: return listener = streaming.StreamListener(session_name=self.get_name(), user_id=self.db["user_id"]) - self.user_stream = self.api.stream_user(listener, run_async=True) - self.direct_stream = self.api.stream_direct(listener, run_async=True) + try: + stream_healthy = self.api.stream_healthy() + if stream_healthy == True: + self.user_stream = self.api.stream_user(listener, run_async=True) + self.direct_stream = self.api.stream_direct(listener, run_async=True) + log.debug("Started streams for session {}.".format(self.get_name())) + except Exception as e: + log.exception("Detected streaming unhealthy in {} session.".format(self.get_name())) def stop_streaming(self): if config.app["app-settings"]["no_streaming"]: