Add filter creation within TWBlue

This commit is contained in:
Manuel Cortez 2025-03-07 10:13:13 -06:00
parent 38fe9c149b
commit 3f72185817
3 changed files with 22 additions and 5 deletions

View File

@ -91,7 +91,7 @@ class FilterController(object):
'context': [],
'filter_action': self.dialog.actions[self.dialog.action_choice.GetSelection()],
'expires_in': self.get_expires_in_seconds(selection=self.dialog.expiration_choice.GetSelection(), value=self.dialog.expiration_value.GetValue()),
'keywords': self.keywords
'keywords_attributes': self.keywords
}
for context, checkbox in self.dialog.context_checkboxes.items():
if checkbox.GetValue():
@ -99,4 +99,9 @@ class FilterController(object):
return filter_data
def get_response(self):
return self.dialog.ShowModal()
response = self.dialog.ShowModal()
if response == widgetUtils.OK:
filter_data = self.get_filter_data()
result = self.session.api.create_filter_v2(**filter_data)
return result
return None

View File

@ -14,7 +14,7 @@ from wxUI import commonMessageDialogs
from wxUI.dialogs.mastodon import updateProfile as update_profile_dialogs
from wxUI.dialogs.mastodon import showUserProfile, communityTimeline
from sessions.mastodon.utils import html_filter
from . import userActions, settings
from . import userActions, settings, filters
log = logging.getLogger("controller.mastodon.handler")
@ -51,7 +51,7 @@ class Handler(object):
favs=None,
# In buffer Menu.
community_timeline =_("Create c&ommunity timeline"),
filter=None,
filter=_("Create a &filter"),
manage_filters=None
)
# Name for the "tweet" menu in the menu bar.
@ -406,3 +406,12 @@ class Handler(object):
buffer.session.settings.write()
communities_position =controller.view.search("communities", buffer.session.get_name())
pub.sendMessage("createBuffer", buffer_type="CommunityBuffer", session_type=buffer.session.type, buffer_title=title, parent_tab=communities_position, start=True, kwargs=dict(parent=controller.view.nb, function="timeline", name=tl_info, sessionObject=buffer.session, account=buffer.session.get_name(), sound="tweet_timeline.ogg", community_url=url, timeline=bufftype))
def create_filter(self, controller, buffer):
filterController = filters.FilterController(buffer.session)
try:
filter = filterController.get_response()
except MastodonError as error:
log.exception("Error adding filter.")
commonMessageDialogs.error_adding_filter()
return self.create_filter(controller=controller, buffer=buffer)

View File

@ -47,3 +47,6 @@ def cant_update_source() -> wx.MessageDialog:
def invalid_instance():
return wx.MessageDialog(None, _("the provided instance is invalid. Please try again."), _("Invalid instance"), wx.ICON_ERROR).ShowModal()
def error_adding_filter():
return wx.MessageDialog(None, _("TWBlue was unable to add or update the filter with the specified settings. Please try again."), _("Error"), wx.ICON_ERROR).ShowModal()