mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-03-06 01:17:32 +01:00
URLS en interfaz invisible
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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", {})
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user