keep the stream flowing

This commit is contained in:
Morgan McMillian 2020-12-22 16:32:32 -08:00
parent 112df2abe2
commit 0f8d45219a

View file

@ -194,6 +194,8 @@ class Timeline(Gtk.Box):
super().__init__(orientation='vertical')
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
self.max_id = 0
self.min_id = 0
scroller = Gtk.ScrolledWindow(
halign='fill',
@ -209,6 +211,7 @@ class Timeline(Gtk.Box):
self.load_timeline()
self.view.connect('button-press-event', self.on_button_pressed)
scroller.connect('edge-reached', self.on_edge_reached)
action_group = Gio.SimpleActionGroup()
@ -241,15 +244,25 @@ class Timeline(Gtk.Box):
builder = Gtk.Builder.new_from_resource("/dev/thrrgilag/squeak/menu.ui")
self.menu = builder.get_object("post-menu")
def load_timeline(self):
def load_timeline(self, older=False):
params = {
'include_raw': 1
}
if older:
params['before_id'] = self.min_id
if self.stream == 'unified':
posts, meta = pnutpy.api.users_post_streams_unified(include_raw=1)
posts, meta = pnutpy.api.users_post_streams_unified(**params)
elif self.stream == 'mentions':
posts, meta = pnutpy.api.users_mentioned_posts('me', include_raw=1)
posts, meta = pnutpy.api.users_mentioned_posts('me', **params)
elif self.stream == 'bookmarks':
posts, meta = pnutpy.api.users_bookmarked_posts('me', include_raw=1)
posts, meta = pnutpy.api.users_bookmarked_posts('me', **params)
else:
posts, meta = pnutpy.api.posts_streams_global(include_raw=1)
posts, meta = pnutpy.api.posts_streams_global(**params)
self.max_id = meta.max_id
self.min_id = meta.min_id
for item in posts:
if 'is_deleted' in item:
@ -258,6 +271,8 @@ class Timeline(Gtk.Box):
postitem.connect('menu-pressed', self.show_menu)
self.view.add(postitem)
self.show_all()
def do_refresh(self):
rows = self.view.get_children()
for item in rows:
@ -265,10 +280,13 @@ class Timeline(Gtk.Box):
self.load_timeline()
self.show_all()
def on_edge_reached(self, widget, pos):
if pos == Gtk.PositionType.BOTTOM:
self.load_timeline(True)
def on_button_pressed(self, widget, event):
logging.debug("-blarp-")
if event.type == Gdk.EventType.BUTTON_PRESS and event.button == 3:
logging.debug("-blarp- right button")
pass
def show_menu(self, widget, index):
self.post_index = index