From b8647c29eaa7bf03118678fc21052142b52a295d Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Mon, 19 Dec 2022 16:21:50 -0600 Subject: [PATCH] Mastodon: Dismiss notifications from GUI or invisible interface (by using the keystroke to delete an item in current buffer) --- src/controller/buffers/mastodon/notifications.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/controller/buffers/mastodon/notifications.py b/src/controller/buffers/mastodon/notifications.py index dc7976a3..ba84f244 100644 --- a/src/controller/buffers/mastodon/notifications.py +++ b/src/controller/buffers/mastodon/notifications.py @@ -32,6 +32,7 @@ class NotificationsBuffer(BaseBuffer): def bind_events(self): widgetUtils.connect_event(self.buffer.list.list, widgetUtils.KEYPRESS, self.get_event) widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.post_status, self.buffer.post) + widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.destroy_status, self.buffer.dismiss) def fav(self): pass @@ -41,3 +42,16 @@ class NotificationsBuffer(BaseBuffer): def can_share(self): return False + + def destroy_status(self, *args, **kwargs): + index = self.buffer.list.get_selected() + item = self.session.db[self.name][index] + items = self.session.db[self.name] + try: + self.session.api.notifications_dismiss(id=item.id) + items.pop(index) + self.buffer.list.remove_item(index) + output.speak(_("Notification dismissed.")) + except Exception as e: + self.session.sound.play("error.ogg") + self.session.db[self.name] = items