From 24e91235f36c0746f51c68cd8fd1e462e7c67d8c Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sun, 5 Feb 2023 19:09:27 -0600 Subject: [PATCH] Mastodon: Implemented setting to disable Streaming API endpoints on sessions --- src/controller/mastodon/settings.py | 5 +++++ src/mastodon.defaults | 1 + src/sessions/mastodon/session.py | 3 ++- src/wxUI/dialogs/mastodon/configuration.py | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controller/mastodon/settings.py b/src/controller/mastodon/settings.py index be4d5f93..5ce6fd1c 100644 --- a/src/controller/mastodon/settings.py +++ b/src/controller/mastodon/settings.py @@ -31,6 +31,7 @@ class accountSettingsController(globalSettingsController): self.dialog.create_general_account() # widgetUtils.connect_event(self.dialog.general.userAutocompletionScan, widgetUtils.BUTTON_PRESSED, self.on_autocompletion_scan) # widgetUtils.connect_event(self.dialog.general.userAutocompletionManage, widgetUtils.BUTTON_PRESSED, self.on_autocompletion_manage) + self.dialog.set_value("general", "disable_streaming", self.config["general"]["disable_streaming"]) self.dialog.set_value("general", "relative_time", self.config["general"]["relative_times"]) self.dialog.set_value("general", "read_preferences_from_instance", self.config["general"]["read_preferences_from_instance"]) self.dialog.set_value("general", "show_screen_names", self.config["general"]["show_screen_names"]) @@ -112,6 +113,10 @@ class accountSettingsController(globalSettingsController): self.needs_restart = True log.debug("Triggered app restart due to change in relative times.") self.config["general"]["relative_times"] = self.dialog.get_value("general", "relative_time") + if self.config["general"]["disable_streaming"] != self.dialog.get_value("general", "disable_streaming"): + self.needs_restart = True + log.debug("Triggered app restart due to change in streaming settings.") + self.config["general"]["disable_streaming"] = self.dialog.get_value("general", "disable_streaming") self.config["general"]["read_preferences_from_instance"] = self.dialog.get_value("general", "read_preferences_from_instance") self.config["general"]["show_screen_names"] = self.dialog.get_value("general", "show_screen_names") self.config["general"]["hide_emojis"] = self.dialog.get_value("general", "hide_emojis") diff --git a/src/mastodon.defaults b/src/mastodon.defaults index 618e0cd3..44c69bab 100644 --- a/src/mastodon.defaults +++ b/src/mastodon.defaults @@ -15,6 +15,7 @@ show_screen_names = boolean(default=False) hide_emojis = boolean(default=False) buffer_order = list(default=list('home', 'local', 'mentions', 'direct_messages', 'sent', 'favorites', 'bookmarks', 'followers', 'following', 'blocked', 'muted', 'notifications')) boost_mode = string(default="ask") +disable_streaming = boolean(default=False) [sound] volume = float(default=1.0) diff --git a/src/sessions/mastodon/session.py b/src/sessions/mastodon/session.py index 2aae5637..67264627 100644 --- a/src/sessions/mastodon/session.py +++ b/src/sessions/mastodon/session.py @@ -223,7 +223,8 @@ class Session(base.baseSession): return "Mastodon: {}@{}".format(user, instance) def start_streaming(self): - if config.app["app-settings"]["no_streaming"]: + if self.settings["general"]["disable_streaming"]: + log.info("Streaming is disabled for session {}. Skipping...".format(self.get_name())) return listener = streaming.StreamListener(session_name=self.get_name(), user_id=self.db["user_id"]) try: diff --git a/src/wxUI/dialogs/mastodon/configuration.py b/src/wxUI/dialogs/mastodon/configuration.py index 5c219c4b..4737f7e0 100644 --- a/src/wxUI/dialogs/mastodon/configuration.py +++ b/src/wxUI/dialogs/mastodon/configuration.py @@ -20,6 +20,8 @@ class generalAccount(wx.Panel, baseDialog.BaseWXDialog): autocompletionSizer.Add(self.userAutocompletionScan, 0, wx.ALL, 5) autocompletionSizer.Add(self.userAutocompletionManage, 0, wx.ALL, 5) sizer.Add(autocompletionSizer, 0, wx.ALL, 5) + self.disable_streaming = wx.CheckBox(self, wx.ID_ANY, _("Disable Streaming API endpoints")) + sizer.Add(self.disable_streaming, 0, wx.ALL, 5) self.relative_time = wx.CheckBox(self, wx.ID_ANY, _("Relative timestamps")) sizer.Add(self.relative_time, 0, wx.ALL, 5) self.read_preferences_from_instance = wx.CheckBox(self, wx.ID_ANY, _("Read preferences from instance (default visibility when publishing and displaying sensitive content)"))