2026-01-11 20:13:56 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
import logging
|
2026-02-01 14:57:17 +01:00
|
|
|
import output
|
2026-01-11 20:13:56 +01:00
|
|
|
from .base import BaseBuffer
|
|
|
|
|
from wxUI.buffers.blueski import panels as BlueskiPanels
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger("controller.buffers.blueski.timeline")
|
|
|
|
|
|
2026-02-01 19:15:31 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
class HomeTimeline(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Discover feed buffer."""
|
|
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(HomeTimeline, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "home_timeline"
|
|
|
|
|
self.feed_uri = None
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 19:03:36 +01:00
|
|
|
self.sound = "tweet_received.ogg"
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-01-11 20:13:56 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not self.feed_uri:
|
|
|
|
|
self.feed_uri = self._resolve_discover_feed(api)
|
|
|
|
|
try:
|
|
|
|
|
if self.feed_uri:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_feed({"feed": self.feed_uri, "limit": count})
|
2026-01-11 20:13:56 +01:00
|
|
|
else:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_timeline({"limit": count})
|
|
|
|
|
items = list(getattr(res, "feed", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching home timeline: %s", e)
|
2026-01-11 20:13:56 +01:00
|
|
|
return 0
|
|
|
|
|
return self.process_items(items, play_sound)
|
|
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
try:
|
|
|
|
|
if self.feed_uri:
|
|
|
|
|
res = api.app.bsky.feed.get_feed({"feed": self.feed_uri, "limit": count, "cursor": self.next_cursor})
|
|
|
|
|
else:
|
|
|
|
|
res = api.app.bsky.feed.get_timeline({"limit": count, "cursor": self.next_cursor})
|
2026-02-01 19:15:31 +01:00
|
|
|
items = list(getattr(res, "feed", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
|
|
|
|
added = self.process_items(items, play_sound=False)
|
|
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more home timeline: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def _resolve_discover_feed(self, api):
|
2026-02-01 19:15:31 +01:00
|
|
|
cached = self.session.db.get("discover_feed_uri")
|
|
|
|
|
if cached:
|
|
|
|
|
return cached
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.feed.get_suggested_feeds({"limit": 50})
|
|
|
|
|
for feed in getattr(res, "feeds", []):
|
|
|
|
|
dn = getattr(feed, "displayName", "") or getattr(feed, "display_name", "")
|
|
|
|
|
if "discover" in dn.lower():
|
|
|
|
|
uri = getattr(feed, "uri", "")
|
|
|
|
|
self.session.db["discover_feed_uri"] = uri
|
|
|
|
|
return uri
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
return None
|
|
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
|
|
|
|
|
class FollowingTimeline(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Following-only timeline (reverse-chronological)."""
|
|
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(FollowingTimeline, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "following_timeline"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 19:03:36 +01:00
|
|
|
self.sound = "tweet_received.ogg"
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def create_buffer(self, parent, name):
|
2026-02-01 19:15:31 +01:00
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
2026-01-11 20:13:56 +01:00
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
|
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.feed.get_timeline({"limit": count, "algorithm": "reverse-chronological"})
|
|
|
|
|
items = list(getattr(res, "feed", []))
|
|
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching following timeline: %s", e)
|
|
|
|
|
return 0
|
|
|
|
|
return self.process_items(items, play_sound)
|
2026-01-11 20:13:56 +01:00
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.feed.get_timeline({"limit": count, "algorithm": "reverse-chronological", "cursor": self.next_cursor})
|
2026-02-01 19:15:31 +01:00
|
|
|
items = list(getattr(res, "feed", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
|
|
|
|
added = self.process_items(items, play_sound=False)
|
|
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more following timeline: %s", e)
|
|
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
class NotificationBuffer(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Notifications buffer."""
|
|
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
2026-02-01 10:42:05 +01:00
|
|
|
kwargs["compose_func"] = "compose_notification"
|
2026-01-11 20:13:56 +01:00
|
|
|
super(NotificationBuffer, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "notifications"
|
2026-02-01 10:42:05 +01:00
|
|
|
self.sound = "notification_received.ogg"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 10:42:05 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def create_buffer(self, parent, name):
|
2026-02-01 10:42:05 +01:00
|
|
|
self.buffer = BlueskiPanels.NotificationPanel(parent, name)
|
2026-01-11 20:13:56 +01:00
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 10:42:05 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return 0
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.notification.list_notifications({"limit": count})
|
2026-02-01 19:15:31 +01:00
|
|
|
notifications = list(getattr(res, "notifications", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 10:42:05 +01:00
|
|
|
if not notifications:
|
|
|
|
|
return 0
|
2026-02-01 19:15:31 +01:00
|
|
|
return self.process_items(notifications, play_sound)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching notifications: %s", e)
|
2026-02-01 10:42:05 +01:00
|
|
|
return 0
|
|
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.notification.list_notifications({"limit": count, "cursor": self.next_cursor})
|
2026-02-01 19:15:31 +01:00
|
|
|
notifications = list(getattr(res, "notifications", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
added = self.process_items(notifications, play_sound=False)
|
2026-02-01 14:57:17 +01:00
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more notifications: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-02-01 10:42:05 +01:00
|
|
|
def add_new_item(self, notification):
|
|
|
|
|
return self.process_items([notification], play_sound=True)
|
2026-01-11 20:13:56 +01:00
|
|
|
|
2026-02-01 19:15:31 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
class Conversation(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Thread/conversation view."""
|
|
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(Conversation, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "conversation"
|
|
|
|
|
self.root_uri = kwargs.get("uri")
|
2026-02-01 15:04:26 +01:00
|
|
|
self.sound = "search_updated.ogg"
|
2026-02-01 19:15:31 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
2026-02-01 19:15:31 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
if not self.root_uri:
|
|
|
|
|
return 0
|
2026-01-11 20:13:56 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
try:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_post_thread({"uri": self.root_uri, "depth": 100, "parentHeight": 100})
|
|
|
|
|
thread = getattr(res, "thread", None)
|
2026-02-01 13:01:32 +01:00
|
|
|
if not thread:
|
|
|
|
|
return 0
|
2026-01-11 20:13:56 +01:00
|
|
|
|
2026-02-01 19:15:31 +01:00
|
|
|
def g(obj, key, default=None):
|
|
|
|
|
return obj.get(key, default) if isinstance(obj, dict) else getattr(obj, key, default)
|
2026-01-11 20:13:56 +01:00
|
|
|
|
2026-02-01 19:15:31 +01:00
|
|
|
final_items = []
|
|
|
|
|
# Add ancestors
|
2026-02-01 13:01:32 +01:00
|
|
|
ancestors = []
|
|
|
|
|
parent = g(thread, "parent")
|
|
|
|
|
while parent:
|
|
|
|
|
ppost = g(parent, "post")
|
|
|
|
|
if ppost:
|
|
|
|
|
ancestors.insert(0, ppost)
|
|
|
|
|
parent = g(parent, "parent")
|
|
|
|
|
final_items.extend(ancestors)
|
|
|
|
|
|
2026-02-01 19:15:31 +01:00
|
|
|
# Traverse thread
|
2026-01-11 20:13:56 +01:00
|
|
|
def traverse(node):
|
|
|
|
|
if not node:
|
|
|
|
|
return
|
|
|
|
|
post = g(node, "post")
|
|
|
|
|
if post:
|
|
|
|
|
final_items.append(post)
|
2026-02-01 19:15:31 +01:00
|
|
|
for r in (g(node, "replies") or []):
|
2026-01-11 20:13:56 +01:00
|
|
|
traverse(r)
|
|
|
|
|
|
2026-02-01 13:01:32 +01:00
|
|
|
traverse(thread)
|
2026-02-01 19:15:31 +01:00
|
|
|
self.session.db[self.name] = []
|
|
|
|
|
self.buffer.list.clear()
|
2026-01-11 20:13:56 +01:00
|
|
|
return self.process_items(final_items, play_sound)
|
2026-02-01 19:15:31 +01:00
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching thread: %s", e)
|
2026-01-11 20:13:56 +01:00
|
|
|
return 0
|
|
|
|
|
|
2026-02-01 19:15:31 +01:00
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
class LikesBuffer(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""User's liked posts."""
|
|
|
|
|
|
2026-01-11 20:13:56 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(LikesBuffer, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "likes"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 15:04:26 +01:00
|
|
|
self.sound = "favourite.ogg"
|
2026-01-11 20:13:56 +01:00
|
|
|
|
|
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-01-11 20:13:56 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.feed.get_actor_likes({"actor": api.me.did, "limit": count})
|
2026-02-01 19:15:31 +01:00
|
|
|
items = list(getattr(res, "feed", None) or getattr(res, "items", None) or [])
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching likes: %s", e)
|
2026-01-11 20:13:56 +01:00
|
|
|
return 0
|
2026-02-01 19:15:31 +01:00
|
|
|
return self.process_items(items, play_sound)
|
2026-02-01 10:42:05 +01:00
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.feed.get_actor_likes({"actor": api.me.did, "limit": count, "cursor": self.next_cursor})
|
2026-02-01 19:15:31 +01:00
|
|
|
items = list(getattr(res, "feed", None) or getattr(res, "items", None) or [])
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
added = self.process_items(items, play_sound=False)
|
2026-02-01 14:57:17 +01:00
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more likes: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
class MentionsBuffer(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Mentions, replies and quotes."""
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
kwargs["compose_func"] = "compose_notification"
|
|
|
|
|
super(MentionsBuffer, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "mentions"
|
|
|
|
|
self.sound = "mention_received.ogg"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.NotificationPanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 10:42:05 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return 0
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.notification.list_notifications({"limit": count})
|
|
|
|
|
notifications = getattr(res, "notifications", [])
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
mentions = [n for n in notifications if getattr(n, "reason", "") in ("mention", "reply", "quote")]
|
2026-02-01 10:42:05 +01:00
|
|
|
if not mentions:
|
|
|
|
|
return 0
|
|
|
|
|
return self.process_items(mentions, play_sound)
|
2026-02-01 19:15:31 +01:00
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching mentions: %s", e)
|
2026-02-01 10:42:05 +01:00
|
|
|
return 0
|
|
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
res = api.app.bsky.notification.list_notifications({"limit": count, "cursor": self.next_cursor})
|
|
|
|
|
notifications = getattr(res, "notifications", [])
|
|
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
mentions = [n for n in notifications if getattr(n, "reason", "") in ("mention", "reply", "quote")]
|
2026-02-01 14:57:17 +01:00
|
|
|
if mentions:
|
|
|
|
|
added = self.process_items(mentions, play_sound=False)
|
|
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more mentions: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-02-01 10:42:05 +01:00
|
|
|
def add_new_item(self, notification):
|
2026-02-01 19:15:31 +01:00
|
|
|
if getattr(notification, "reason", "") in ("mention", "reply", "quote"):
|
2026-02-01 10:42:05 +01:00
|
|
|
return self.process_items([notification], play_sound=True)
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SentBuffer(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""User's sent posts."""
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(SentBuffer, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "sent"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 10:42:05 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api or not api.me:
|
|
|
|
|
return 0
|
|
|
|
|
try:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_author_feed({"actor": api.me.did, "limit": count, "filter": "posts_no_replies"})
|
|
|
|
|
items = list(getattr(res, "feed", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 10:42:05 +01:00
|
|
|
if not items:
|
|
|
|
|
return 0
|
2026-02-01 19:15:31 +01:00
|
|
|
return self.process_items(items, play_sound)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching sent posts: %s", e)
|
2026-02-01 10:42:05 +01:00
|
|
|
return 0
|
|
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api or not api.me:
|
|
|
|
|
return
|
|
|
|
|
try:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_author_feed({"actor": api.me.did, "limit": count, "filter": "posts_no_replies", "cursor": self.next_cursor})
|
|
|
|
|
items = list(getattr(res, "feed", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
added = self.process_items(items, play_sound=False)
|
2026-02-01 14:57:17 +01:00
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more sent posts: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-02-01 10:42:05 +01:00
|
|
|
|
2026-02-01 12:49:33 +01:00
|
|
|
class UserTimeline(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Timeline for a specific user."""
|
2026-02-01 12:49:33 +01:00
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
self.actor = kwargs.get("actor")
|
2026-02-01 13:01:32 +01:00
|
|
|
self.handle = kwargs.get("handle")
|
2026-02-01 12:49:33 +01:00
|
|
|
super(UserTimeline, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "user_timeline"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
|
|
|
|
self._resolved_actor = None
|
2026-02-01 15:04:26 +01:00
|
|
|
self.sound = "tweet_timeline.ogg"
|
2026-02-01 12:49:33 +01:00
|
|
|
|
|
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
|
|
|
|
if not self.actor:
|
|
|
|
|
return 0
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
|
|
|
|
actor = self.actor.strip().lstrip("@") if isinstance(self.actor, str) else self.actor
|
2026-02-01 12:49:33 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return 0
|
|
|
|
|
try:
|
2026-02-01 13:07:16 +01:00
|
|
|
if isinstance(actor, str) and not actor.startswith("did:"):
|
2026-02-01 19:15:31 +01:00
|
|
|
profile = self.session.get_profile(actor)
|
|
|
|
|
if profile:
|
|
|
|
|
did = profile.get("did") if isinstance(profile, dict) else getattr(profile, "did", None)
|
|
|
|
|
if did:
|
|
|
|
|
actor = did
|
2026-02-01 14:57:17 +01:00
|
|
|
self._resolved_actor = actor
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_author_feed({"actor": actor, "limit": count})
|
|
|
|
|
items = list(getattr(res, "feed", []) or [])
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching user timeline: %s", e)
|
2026-02-01 12:49:33 +01:00
|
|
|
return 0
|
2026-02-01 19:15:31 +01:00
|
|
|
return self.process_items(items, play_sound)
|
2026-02-01 12:49:33 +01:00
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor or not self._resolved_actor:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return
|
|
|
|
|
try:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.get_author_feed({"actor": self._resolved_actor, "limit": count, "cursor": self.next_cursor})
|
|
|
|
|
items = list(getattr(res, "feed", []) or [])
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
added = self.process_items(items, play_sound=False)
|
2026-02-01 14:57:17 +01:00
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more user timeline: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-02-01 13:01:32 +01:00
|
|
|
def remove_buffer(self, force=False):
|
|
|
|
|
if not force:
|
|
|
|
|
from wxUI import commonMessageDialogs
|
|
|
|
|
import widgetUtils
|
2026-02-01 19:15:31 +01:00
|
|
|
if commonMessageDialogs.remove_buffer() != widgetUtils.YES:
|
2026-02-01 13:01:32 +01:00
|
|
|
return False
|
2026-02-01 19:15:31 +01:00
|
|
|
self.session.db.pop(self.name, None)
|
|
|
|
|
timelines = self.session.settings["other_buffers"].get("timelines") or []
|
|
|
|
|
if isinstance(timelines, str):
|
|
|
|
|
timelines = [t for t in timelines.split(",") if t]
|
|
|
|
|
for key in (self.actor or "", self.handle or ""):
|
|
|
|
|
if key in timelines:
|
|
|
|
|
timelines.remove(key)
|
|
|
|
|
self.session.settings["other_buffers"]["timelines"] = timelines
|
|
|
|
|
self.session.settings.write()
|
2026-02-01 13:01:32 +01:00
|
|
|
return True
|
|
|
|
|
|
2026-02-01 12:49:33 +01:00
|
|
|
|
2026-02-01 10:42:05 +01:00
|
|
|
class SearchBuffer(BaseBuffer):
|
2026-02-01 19:15:31 +01:00
|
|
|
"""Search results buffer."""
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
self.search_query = kwargs.pop("query", "")
|
|
|
|
|
super(SearchBuffer, self).__init__(*args, **kwargs)
|
|
|
|
|
self.type = "search"
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = None
|
2026-02-01 15:04:26 +01:00
|
|
|
self.sound = "search_updated.ogg"
|
2026-02-01 10:42:05 +01:00
|
|
|
|
|
|
|
|
def create_buffer(self, parent, name):
|
|
|
|
|
self.buffer = BlueskiPanels.HomePanel(parent, name)
|
|
|
|
|
self.buffer.session = self.session
|
|
|
|
|
|
|
|
|
|
def start_stream(self, mandatory=False, play_sound=True):
|
|
|
|
|
if not self.search_query:
|
|
|
|
|
return 0
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 10:42:05 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return 0
|
|
|
|
|
try:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.search_posts({"q": self.search_query, "limit": count})
|
|
|
|
|
posts = list(getattr(res, "posts", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 10:42:05 +01:00
|
|
|
if not posts:
|
|
|
|
|
return 0
|
|
|
|
|
self.session.db[self.name] = []
|
|
|
|
|
self.buffer.list.clear()
|
2026-02-01 19:15:31 +01:00
|
|
|
return self.process_items(posts, play_sound)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error searching posts: %s", e)
|
2026-02-01 10:42:05 +01:00
|
|
|
return 0
|
|
|
|
|
|
2026-02-01 14:57:17 +01:00
|
|
|
def get_more_items(self):
|
|
|
|
|
if not self.next_cursor or not self.search_query:
|
|
|
|
|
return
|
2026-02-01 19:15:31 +01:00
|
|
|
count = self.get_max_items()
|
2026-02-01 14:57:17 +01:00
|
|
|
api = self.session._ensure_client()
|
|
|
|
|
if not api:
|
|
|
|
|
return
|
|
|
|
|
try:
|
2026-02-01 19:15:31 +01:00
|
|
|
res = api.app.bsky.feed.search_posts({"q": self.search_query, "limit": count, "cursor": self.next_cursor})
|
|
|
|
|
posts = list(getattr(res, "posts", []))
|
2026-02-01 14:57:17 +01:00
|
|
|
self.next_cursor = getattr(res, "cursor", None)
|
2026-02-01 19:15:31 +01:00
|
|
|
added = self.process_items(posts, play_sound=False)
|
2026-02-01 14:57:17 +01:00
|
|
|
if added:
|
2026-02-01 19:15:31 +01:00
|
|
|
output.speak(_(u"%s items retrieved") % added, True)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
log.error("Error fetching more search results: %s", e)
|
2026-02-01 14:57:17 +01:00
|
|
|
|
2026-02-01 10:42:05 +01:00
|
|
|
def remove_buffer(self, force=False):
|
2026-02-01 12:39:50 +01:00
|
|
|
if not force:
|
|
|
|
|
from wxUI import commonMessageDialogs
|
|
|
|
|
import widgetUtils
|
2026-02-01 19:15:31 +01:00
|
|
|
if commonMessageDialogs.remove_buffer() != widgetUtils.YES:
|
2026-02-01 12:39:50 +01:00
|
|
|
return False
|
2026-02-01 19:15:31 +01:00
|
|
|
self.session.db.pop(self.name, None)
|
|
|
|
|
searches = self.session.settings["other_buffers"].get("searches") or []
|
|
|
|
|
if isinstance(searches, str):
|
|
|
|
|
searches = [s for s in searches.split(",") if s]
|
|
|
|
|
if self.search_query in searches:
|
|
|
|
|
searches.remove(self.search_query)
|
|
|
|
|
self.session.settings["other_buffers"]["searches"] = searches
|
|
|
|
|
self.session.settings.write()
|
2026-02-01 10:42:05 +01:00
|
|
|
return True
|