added order_buffer method to sort toots in database

This commit is contained in:
Manuel Cortez 2022-11-08 12:19:41 -06:00
parent 02b8330ca0
commit d53decb165
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790

View File

@ -12,6 +12,7 @@ import application
from pubsub import pub from pubsub import pub
from mysc.thread_utils import call_threaded from mysc.thread_utils import call_threaded
from sessions import base from sessions import base
from sessions.mastodon import utils
from .wxUI import authorisationDialog from .wxUI import authorisationDialog
log = logging.getLogger("sessions.mastodonSession") log = logging.getLogger("sessions.mastodonSession")
@ -89,4 +90,27 @@ class Session(base.baseSession):
return user.name return user.name
def check_streams(self): def check_streams(self):
pass pass
def order_buffer(self, name, data, ignore_older=True):
num = 0
last_id = None
if self.db.get(name) == None:
self.db[name] = []
objects = self.db[name]
if ignore_older and len(self.db[name]) > 0:
if self.settings["general"]["reverse_timelines"] == False:
last_id = self.db[name][0].id
else:
last_id = self.db[name][-1].id
for i in data:
if ignore_older and last_id != None:
if i.id < last_id:
log.error("Ignoring an older tweet... Last id: {0}, tweet id: {1}".format(last_id, i.id))
continue
if utils.find_item(i, self.db[name]) == None:
if self.settings["general"]["reverse_timelines"] == False: objects.append(i)
else: objects.insert(0, i)
num = num+1
self.db[name] = objects
return num