Mastodon: Added missing method to search buffer and removed some unneeded code

This commit is contained in:
Manuel Cortez 2023-07-10 12:52:42 -06:00
parent 2cd90e8df1
commit 7c5a41791c
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
2 changed files with 30 additions and 35 deletions

View File

@ -2,6 +2,13 @@ TWBlue Changelog
## changes in this version
* Mastodon:
* Implemented update profile dialog. ([#547](https://github.com/MCV-Software/TWBlue/pull/547))
* Added possibility to vote in polls.
* Added posts search. Take into account that Mastodon instances should be configured with full text search enabled. Search for posts only include posts the logged-in user has interacted with. ([#541](https://github.com/MCV-Software/TWBlue/pull/541))
## changes in version 2023.4.13
During the development of the current TWBlue version, Twitter has cut out access from their API, meaning TWBlue will no longer be able to communicate with Twitter. This is the end of the support of TWBlue for Twitter sessions. No new sessions will be available for this social network, and we will focus in adding more features to our Mastodon support and writing support for more websites and networks. Thank you everyone who have been using TWBlue to manage your Twitter accounts since 2013.
* TWBlue should be able to display variables within templates (for example, now it is possible to send a template inside a post's text). Before, it was removing $variables so it was difficult to show how to edit templates from the client. ([#515](https://github.com/MCV-Software/TWBlue/issues/515))
@ -15,7 +22,7 @@ During the development of the current TWBlue version, Twitter has cut out access
* Fixed an error on mentions buffer that was making TWBlue unable to load posts if there were mentions from a blocked or deleted account.
* Fixed an error when loading timelines during startup where TWBlue was unable to change the buffer title properly.
## Changes on version 2023.2.6
## Changes on version 2023.2.8
This release focuses on fixing some important bugs that have been reported in the previous version. Particularly, TWBlue should be able to authorize on some instances that have blocked the Mastodon.py library, and should be able to avoid repeatedly calling some endpoints that cause excessive connections for some instances. Additionally, it is possible to disable Streaming from the account options in Mastodon. This can be especially useful if TWBlue keeps making a lot of API calls for some instances.

View File

@ -3,19 +3,16 @@
Implements searching functionality for mastodon
Used for searching for statuses (posts) or possibly hashtags
"""
import logging
import time
from pubsub import pub
from .base import BaseBuffer
import output
import widgetUtils
from wxUI import commonMessageDialogs
log = logging.getLogger("controller.buffers.mastodon.search")
class SearchBuffer(BaseBuffer):
"""Search buffer
There are some methods of the Base Buffer that can't be used here
@ -31,42 +28,32 @@ class SearchBuffer(BaseBuffer):
"""
log.debug(f"Starting streamd for buffer {self.name} account {self.account} and type {self.type}")
log.debug(f"Args: {self.args}, Kwargs: {self.kwargs}")
current_time = time.time()
if self.execution_time == 0 or current_time-self.execution_time >= 180 or mandatory==True:
self.execution_time = current_time
min_id = None
if self.name in self.session.db and len(self.session.db[self.name]) > 0:
if self.session.settings["general"]["reverse_timelines"]:
min_id = self.session.db[self.name][0].id
else:
min_id = self.session.db[self.name][-1].id
try:
results = getattr(self.session.api, self.function)(min_id=min_id, **self.kwargs)
except Exception as mess:
log.exception(f"Error while receiving search posts {mess}")
return
# Results is either in results.statuses or results.hashtags.
results = results.statuses if results.statuses else results.hashtags
results.reverse()
num_of_items = self.session.order_buffer(self.name, results)
log.debug(f"Number of items retrieved: {num_of_items}")
self.put_items_on_list(num_of_items)
if hasattr(self, "finished_timeline") and self.finished_timeline == False:
pub.sendMessage("core.change_buffer_title", name=self.session.get_name(), buffer=self.name, title=_("{}-searchterm").format(self.kwargs['q']))
self.finished_timeline = True
min_id = None
if self.name in self.session.db and len(self.session.db[self.name]) > 0:
if self.session.settings["general"]["reverse_timelines"]:
min_id = self.session.db[self.name][0].id
else:
min_id = self.session.db[self.name][-1].id
try:
results = getattr(self.session.api, self.function)(min_id=min_id, **self.kwargs)
except Exception as mess:
log.exception(f"Error while receiving search posts {mess}")
return
results = results.statuses
results.reverse()
num_of_items = self.session.order_buffer(self.name, results)
log.debug(f"Number of items retrieved: {num_of_items}")
self.put_items_on_list(num_of_items)
# playsound and autoread
if num_of_items > 0:
if self.sound != None and self.session.settings["sound"]["session_mute"] == False and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and play_sound == True:
self.session.sound.play(self.sound)
if avoid_autoreading == False and mandatory == True and self.name in self.session.settings["other_buffers"]["autoread_buffers"]:
self.auto_read(num_of_items)
return num_of_items
return num_of_items
def remove_buffer(self, force: bool=False) -> bool:
"""Performs clean-up tasks before removing buffer
@ -80,14 +67,15 @@ class SearchBuffer(BaseBuffer):
response = commonMessageDialogs.remove_buffer()
else:
response = widgetUtils.YES
if response == widgetUtils.NO:
return False
# remove references of this buffer in db and settings
if self.name in self.session.db:
self.session.db.pop(self.name)
if self.kwargs.get('q') in self.session.settings['other_buffers']['post_searches']:
self.session.settings['other_buffers']['post_searches'].remove(self.kwargs['q'])
return True
def get_more_items(self):
output.speak(_(u"This action is not supported for this buffer"), True)