From 5abe9e7d749e573c4e5fc2856eb14e2a8621a060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Pav=C3=B3n=20Abi=C3=A1n?= Date: Mon, 2 Feb 2026 18:41:11 +0100 Subject: [PATCH] URLS en interfaz invisible --- src/controller/buffers/blueski/base.py | 16 +++++------ src/sessions/blueski/compose.py | 32 +++++++++++++++++++++ src/sessions/blueski/templates.py | 39 +++++++++++++++++++++++++- src/sessions/blueski/utils.py | 6 ++-- 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/controller/buffers/blueski/base.py b/src/controller/buffers/blueski/base.py index b6bc3e86..71beb9ac 100644 --- a/src/controller/buffers/blueski/base.py +++ b/src/controller/buffers/blueski/base.py @@ -619,8 +619,8 @@ class BaseBuffer(base.Buffer): try: reverse = self.session.settings["general"].get("reverse_timelines", False) except: pass - - if number_of_items == 0: + + if number_of_items == 0: return safe = True @@ -641,9 +641,9 @@ class BaseBuffer(base.Buffer): elif count > 0 and number_of_items > 0: if not reverse: - items = list_to_use[:number_of_items] # If we prepended items for normal (oldest first) timeline... wait. + items = list_to_use[:number_of_items] # If we prepended items for normal (oldest first) timeline... wait. # Standard flow: "New items" come from API. - # If standard timeline (oldest at top, newest at bottom): new items appended to DB. + # If standard timeline (oldest at top, newest at bottom): new items appended to DB. # UI: append to bottom. items = list_to_use[len(list_to_use)-number_of_items:] for i in items: @@ -651,16 +651,16 @@ class BaseBuffer(base.Buffer): self.buffer.list.insert_item(False, *post) else: # Reverse timeline (Newest at top). - # New items appended to DB? Or inserted at 0? - # Mastodon BaseBuffer: + # New items appended to DB? Or inserted at 0? + # Mastodon BaseBuffer: # if reverse_timelines == False: items_db.insert(0, i) (Wait, insert at 0?) # Actually let's look at `get_more_items` in Mastodon BaseBuffer again. # "if self.session.settings["general"]["reverse_timelines"] == False: items_db.insert(0, i)" # This means for standard timeline, new items (newer time) go to index 0? # No, standard timeline usually has oldest at top. Retrieve "more items" usually means "newer items" or "older items" depending on context (streaming vs styling). - + # Let's trust that we just need to insert based on how we updated DB in start_stream. - + # For now, simplistic approach: items = list_to_use[0:number_of_items] # Assuming we inserted at 0 in DB # items.reverse() if needed? diff --git a/src/sessions/blueski/compose.py b/src/sessions/blueski/compose.py index ffe9493c..a754ac23 100644 --- a/src/sessions/blueski/compose.py +++ b/src/sessions/blueski/compose.py @@ -76,6 +76,33 @@ def compose_post(post, db, settings, relative_times, show_screen_names=False, sa else: text = original_text + # Check facets for links not visible in text and append them + facets = g(record, "facets", []) or [] + hidden_urls = [] + for facet in facets: + features = g(facet, "features", []) or [] + for feature in features: + ftype = g(feature, "$type") or g(feature, "py_type") or "" + if "link" in ftype.lower(): + uri = g(feature, "uri", "") + if uri and uri not in text and uri not in hidden_urls: + # Check if a truncated version is in text (e.g., "example.com/path...") + # by checking if the domain is present + domain_match = False + try: + from urllib.parse import urlparse + parsed = urlparse(uri) + domain = parsed.netloc.replace("www.", "") + if domain and domain in text: + domain_match = True + except: + pass + if not domain_match: + hidden_urls.append(uri) + + if hidden_urls: + text += " " + " ".join(f"[{url}]" for url in hidden_urls) + # Labels / Content Warning labels = g(actual_post, "labels", []) cw_text = "" @@ -113,6 +140,11 @@ def compose_post(post, db, settings, relative_times, show_screen_names=False, sa images = g(media, "images", []) if images: text += f" [{len(images)} {_('images')}]" + elif mtype and "external" in mtype: + ext = g(media, "external", {}) + title = g(ext, "title", "") + if title: + text += f" [{_('Link')}: {title}]" elif etype and ("record" in etype): quote_rec = g(embed, "record", {}) diff --git a/src/sessions/blueski/templates.py b/src/sessions/blueski/templates.py index d6e66dd5..8e3015e5 100644 --- a/src/sessions/blueski/templates.py +++ b/src/sessions/blueski/templates.py @@ -92,6 +92,34 @@ def process_date(field, relative_times=True, offset_hours=0): return original_date.shift(hours=offset_hours).format(_("dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.curLang[:2]) +def _extract_link_info(post, record): + """Extract link information from post embeds and facets.""" + embed = _g(post, "embed") + if not embed: + return None + + etype = _g(embed, "$type") or _g(embed, "py_type") or "" + + # Direct external embed + if "external" in etype.lower(): + ext = _g(embed, "external", {}) + title = _g(ext, "title", "") + if title: + return title + + # RecordWithMedia with external + if "recordWithMedia" in etype: + media = _g(embed, "media", {}) + mtype = _g(media, "$type") or _g(media, "py_type") or "" + if "external" in mtype.lower(): + ext = _g(media, "external", {}) + title = _g(ext, "title", "") + if title: + return title + + return None + + def render_post(post, template, settings, relative_times=False, offset_hours=0): actual_post = _g(post, "post", post) record = _g(actual_post, "record") or _g(post, "record") or {} @@ -118,10 +146,19 @@ def render_post(post, template, settings, relative_times=False, offset_hours=0): original_handle = _g(author, "handle", "") text = _("Reposted from @{handle}: {text}").format(handle=original_handle, text=text) + # Add link indicator for external embeds + link_title = _extract_link_info(actual_post, record) + if link_title: + text += f" [{_('Link')}: {link_title}]" + cw_text = _extract_cw_text(actual_post, record) safe_text = text if cw_text: - safe_text = _("Content warning: {cw}").format(cw=cw_text) + # Include link info in safe_text even with content warning + if link_title: + safe_text = _("Content warning: {cw}").format(cw=cw_text) + f" [{_('Link')}: {link_title}]" + else: + safe_text = _("Content warning: {cw}").format(cw=cw_text) created_at = _g(record, "createdAt") or _g(record, "created_at") indexed_at = _g(actual_post, "indexedAt") or _g(actual_post, "indexed_at") diff --git a/src/sessions/blueski/utils.py b/src/sessions/blueski/utils.py index 785b7738..9048d36d 100644 --- a/src/sessions/blueski/utils.py +++ b/src/sessions/blueski/utils.py @@ -237,12 +237,12 @@ def find_urls(post): record = g(actual_post, "record", {}) # Check facets for link annotations - facets = g(record, "facets", []) + facets = g(record, "facets", []) or [] for facet in facets: - features = g(facet, "features", []) + features = g(facet, "features", []) or [] for feature in features: ftype = g(feature, "$type") or g(feature, "py_type") - if ftype and "link" in ftype: + if ftype and "link" in ftype.lower(): uri = g(feature, "uri", "") if uri and uri not in urls: urls.append(uri)