diff --git a/src/controller/buffers/mastodon/base.py b/src/controller/buffers/mastodon/base.py index 2deff612..1595f932 100644 --- a/src/controller/buffers/mastodon/base.py +++ b/src/controller/buffers/mastodon/base.py @@ -40,9 +40,31 @@ class BaseBuffer(base.Buffer): self.buffer.account = account self.bind_events() self.sound = sound + pub.subscribe(self.on_mute_cleanup, "mastodon.mute_cleanup") if "-timeline" in self.name or "-followers" in self.name or "-following" in self.name or "searchterm" in self.name: self.finished_timeline = False + def on_mute_cleanup(self, conversation_id, session_name): + if self.name != "home_timeline": + return + if session_name != self.session.get_name(): + return + items_to_remove = [] + for index, item in enumerate(self.session.db[self.name]): + c_id = None + if hasattr(item, "conversation_id"): + c_id = item.conversation_id + elif isinstance(item, dict): + c_id = item.get("conversation_id") + + if c_id == conversation_id: + items_to_remove.append(index) + + items_to_remove.sort(reverse=True) + for index in items_to_remove: + self.session.db[self.name].pop(index) + self.buffer.list.remove_item(index) + def create_buffer(self, parent, name): self.buffer = buffers.mastodon.basePanel(parent, name) @@ -293,6 +315,7 @@ class BaseBuffer(base.Buffer): menu.boost.Enable(False) widgetUtils.connect_event(menu, widgetUtils.MENU, self.fav, menuitem=menu.fav) widgetUtils.connect_event(menu, widgetUtils.MENU, self.unfav, menuitem=menu.unfav) + widgetUtils.connect_event(menu, widgetUtils.MENU, self.mute_conversation, menuitem=menu.mute) widgetUtils.connect_event(menu, widgetUtils.MENU, self.url_, menuitem=menu.openUrl) widgetUtils.connect_event(menu, widgetUtils.MENU, self.audio, menuitem=menu.play) widgetUtils.connect_event(menu, widgetUtils.MENU, self.view, menuitem=menu.view) @@ -612,6 +635,22 @@ class BaseBuffer(base.Buffer): else: call_threaded(self.session.api_call, call_name="status_unbookmark", preexec_message=_("Removing from bookmarks..."), _sound="favourite.ogg", id=item.id) + def mute_conversation(self, event=None, item=None, *args, **kwargs): + if item == None: + item = self.get_item() + if item.reblog != None: + item = item.reblog + try: + item = self.session.api.status(item.id) + except MastodonNotFoundError: + output.speak(_("No status found with that ID")) + return + if item.muted == False: + call_threaded(self.session.api_call, call_name="status_mute", preexec_message=_("Muting conversation..."), _sound="favourite.ogg", id=item.id) + pub.sendMessage("mastodon.mute_cleanup", conversation_id=item.conversation_id, session_name=self.session.get_name()) + else: + call_threaded(self.session.api_call, call_name="status_unmute", preexec_message=_("Unmuting conversation..."), _sound="favourite.ogg", id=item.id) + def view_item(self, item=None): if item == None: item = self.get_item() diff --git a/src/keymaps/Windows 10.keymap b/src/keymaps/Windows 10.keymap index 426c598f..c12d78ee 100644 --- a/src/keymaps/Windows 10.keymap +++ b/src/keymaps/Windows 10.keymap @@ -57,5 +57,6 @@ update_buffer = string(default="control+alt+shift+u") ocr_image = string(default="win+alt+o") open_in_browser = string(default="alt+control+win+return") add_alias=string(default="") +mute_conversation=string(default="control+alt+win+back") find = string(default="control+win+{") vote=string(default="alt+win+shift+v") \ No newline at end of file diff --git a/src/keymaps/Windows11.keymap b/src/keymaps/Windows11.keymap index 9ed24488..c4301cff 100644 --- a/src/keymaps/Windows11.keymap +++ b/src/keymaps/Windows11.keymap @@ -57,5 +57,6 @@ update_buffer = string(default="control+alt+shift+u") ocr_image = string(default="win+alt+o") open_in_browser = string(default="alt+control+win+return") add_alias=string(default="") +mute_conversation=string(default="control+alt+win+back") find = string(default="control+win+{") vote=string(default="alt+win+shift+v") \ No newline at end of file diff --git a/src/keymaps/base.template b/src/keymaps/base.template index f95ffcc1..15429f06 100644 --- a/src/keymaps/base.template +++ b/src/keymaps/base.template @@ -56,4 +56,6 @@ configuration = string(default="control+win+o") accountConfiguration = string(default="control+win+shift+o") update_buffer = string(default="control+win+shift+u") open_in_browser = string(default="alt+control+win+return") -add_alias=string(default="") \ No newline at end of file +add_alias=string(default="") +mute_conversation=string(default="alt+win+shift+delete") +vote=string(default="alt+win+shift+v") \ No newline at end of file diff --git a/src/keymaps/default.keymap b/src/keymaps/default.keymap index 8e4bf9b2..30e6bcbb 100644 --- a/src/keymaps/default.keymap +++ b/src/keymaps/default.keymap @@ -59,4 +59,5 @@ update_buffer = string(default="control+win+shift+u") ocr_image = string(default="win+alt+o") open_in_browser = string(default="alt+control+win+return") add_alias=string(default="") +mute_conversation=string(default="alt+win+shift+delete") vote=string(default="alt+win+shift+v") \ No newline at end of file diff --git a/src/keystrokeEditor/actions/mastodon.py b/src/keystrokeEditor/actions/mastodon.py index 2dea1a9e..3f07f152 100644 --- a/src/keystrokeEditor/actions/mastodon.py +++ b/src/keystrokeEditor/actions/mastodon.py @@ -54,4 +54,5 @@ actions = { "update_buffer": _(u"Updates the buffer and retrieves possible lost items there."), "ocr_image": _(u"Extracts the text from a picture and displays the result in a dialog."), "add_alias": _("Adds an alias to an user"), + "mute_conversation": _("Mute/Unmute conversation"), } \ No newline at end of file diff --git a/src/sessions/mastodon/utils.py b/src/sessions/mastodon/utils.py index 05a6303f..589ee23f 100644 --- a/src/sessions/mastodon/utils.py +++ b/src/sessions/mastodon/utils.py @@ -140,6 +140,11 @@ def evaluate_filters(post: dict, current_context: str) -> str | None: - None if no applicable filters are found, meaning the post should be shown normally. """ filters = post.get("filtered", None) + + # Automatically hide muted conversations from home timeline. + if current_context == "home" and post.get("muted") == True: + return "hide" + if filters == None: return warn_filter_title = None diff --git a/src/wxUI/dialogs/mastodon/menus.py b/src/wxUI/dialogs/mastodon/menus.py index 7947d942..62dd3407 100644 --- a/src/wxUI/dialogs/mastodon/menus.py +++ b/src/wxUI/dialogs/mastodon/menus.py @@ -14,6 +14,8 @@ class base(wx.Menu): self.Append(self.fav) self.unfav = wx.MenuItem(self, wx.ID_ANY, _(u"R&emove from favorites")) self.Append(self.unfav) + self.mute = wx.MenuItem(self, wx.ID_ANY, _(u"Mute/Unmute conversation")) + self.Append(self.mute) self.openUrl = wx.MenuItem(self, wx.ID_ANY, _("&Open URL")) self.Append(self.openUrl) self.openInBrowser = wx.MenuItem(self, wx.ID_ANY, _(u"&Open in instance"))