Mastodon: Use TWBlue user agent, check streaming API health before starting streaming session

This commit is contained in:
Manuel Cortez 2023-01-29 14:34:36 -06:00
parent fd176f92d3
commit 3be01013f4
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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"])
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"]: