fixed mastodon displaying an empty buffer when no result was found for a serch

This commit is contained in:
Abdulqadir Ahmad 2023-03-12 16:43:10 +01:00
parent c480554e01
commit ebca124397
2 changed files with 11 additions and 3 deletions
src/controller

@ -9,8 +9,9 @@ from controller.buffers.mastodon.base import BaseBuffer
from controller.mastodon import messages from controller.mastodon import messages
from sessions.mastodon import templates, utils from sessions.mastodon import templates, utils
from wxUI import buffers, commonMessageDialogs from wxUI import buffers, commonMessageDialogs
from pubsub import pub
log = logging.getLogger("controller.buffers.mastodon.conversations") log = logging.getLogger("controller.buffers.mastodon.users")
class UserBuffer(BaseBuffer): class UserBuffer(BaseBuffer):
@ -86,6 +87,12 @@ class UserBuffer(BaseBuffer):
return return
number_of_items = self.session.order_buffer(self.name, results) number_of_items = self.session.order_buffer(self.name, results)
log.debug("Number of items retrieved: %d" % (number_of_items,)) log.debug("Number of items retrieved: %d" % (number_of_items,))
if self.name.endswith("-searchUser") and number_of_items == 0:
# No search result found, alert user and destroy buffer
log.debug("Destroying buffer %s, account %s and type %s" % (self.name, self.account, self.type))
output.speak(_(u"Your search didn't match any results."))
pub.sendMessage("destroy_buffer", buffer_name=self.name,
session_name=self.account)
if hasattr(self, "finished_timeline") and self.finished_timeline == False: if hasattr(self, "finished_timeline") and self.finished_timeline == False:
if "-followers" in self.name or "-following" in self.name: if "-followers" in self.name or "-following" in self.name:
self.username = self.session.api.account(id=self.kwargs.get("id")).username self.username = self.session.api.account(id=self.kwargs.get("id")).username
@ -199,4 +206,4 @@ class UserBuffer(BaseBuffer):
return False return False
else: else:
output.speak(_(u"This buffer is not a timeline; it can't be deleted."), True) output.speak(_(u"This buffer is not a timeline; it can't be deleted."), True)
return False return False

@ -110,6 +110,7 @@ class Controller(object):
pub.subscribe(self.toggle_share_settings, "toggleShare") pub.subscribe(self.toggle_share_settings, "toggleShare")
pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed") pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed")
pub.subscribe(self.create_account_buffer, "core.create_account") pub.subscribe(self.create_account_buffer, "core.create_account")
pub.subscribe(self.destroy_buffer, "destroy_buffer")
# Twitter specific events. # Twitter specific events.
pub.subscribe(self.buffer_title_changed, "buffer-title-changed") pub.subscribe(self.buffer_title_changed, "buffer-title-changed")
@ -1265,4 +1266,4 @@ class Controller(object):
# if number_of_items > 0: # if number_of_items > 0:
# sound_to_play = "dm_received.ogg" # sound_to_play = "dm_received.ogg"
# if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]: # if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]:
# self.notify(buffer.session, sound_to_play) # self.notify(buffer.session, sound_to_play)