mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-04-05 03:12:29 -04:00
Attempt to load pinned posts when loading a timeline for an user
This commit is contained in:
parent
6aa84daf5e
commit
3d7d1142d3
@ -108,13 +108,24 @@ class BaseBuffer(base.Buffer):
|
|||||||
min_id = self.session.db[self.name][0].id
|
min_id = self.session.db[self.name][0].id
|
||||||
else:
|
else:
|
||||||
min_id = self.session.db[self.name][-1].id
|
min_id = self.session.db[self.name][-1].id
|
||||||
|
# loads pinned posts from user accounts.
|
||||||
|
# Load those posts only when there are no items previously loaded.
|
||||||
|
if "-timeline" in self.name and "account_statuses" in self.function and len(self.session.db.get(self.name, [])) == 0:
|
||||||
|
pinned_posts = self.session.api.account_statuses(pinned=True, limit=count, *self.args, **self.kwargs)
|
||||||
|
pinned_posts.reverse()
|
||||||
|
else:
|
||||||
|
pinned_posts = None
|
||||||
try:
|
try:
|
||||||
results = getattr(self.session.api, self.function)(min_id=min_id, limit=count, *self.args, **self.kwargs)
|
results = getattr(self.session.api, self.function)(min_id=min_id, limit=count, *self.args, **self.kwargs)
|
||||||
results.reverse()
|
results.reverse()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception("Error %s" % (str(e)))
|
log.exception("Error %s" % (str(e)))
|
||||||
return
|
return
|
||||||
|
if pinned_posts != None and len(pinned_posts) > 0:
|
||||||
|
amount_of_pinned_posts = self.session.order_buffer(self.name, pinned_posts)
|
||||||
number_of_items = self.session.order_buffer(self.name, results)
|
number_of_items = self.session.order_buffer(self.name, results)
|
||||||
|
if pinned_posts != None and len(pinned_posts) > 0:
|
||||||
|
number_of_items = amount_of_pinned_posts+number_of_items
|
||||||
log.debug("Number of items retrieved: %d" % (number_of_items,))
|
log.debug("Number of items retrieved: %d" % (number_of_items,))
|
||||||
if hasattr(self, "finished_timeline") and self.finished_timeline == False:
|
if hasattr(self, "finished_timeline") and self.finished_timeline == False:
|
||||||
if "-timeline" in self.name:
|
if "-timeline" in self.name:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user