diff --git a/features.py b/features.py
index 0321828..25dd75e 100644
--- a/features.py
+++ b/features.py
@@ -35,7 +35,7 @@ LAST_ACTIVE_VISIBILITIES = {"everyone", "members", "nobody"}
PRESENCE_MODES = {"online", "silent", "focus", "dnd"}
REACTION_EMOJI_RE = re.compile(r"^.{1,16}$")
HEX_COLOR_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
-#PAGE_LINK_RE = re.compile(r"\]\((?:/teams/[^/]+/pages/)?([a-z0-9-]{1,48})\)", re.IGNORECASE)
+PAGE_LINK_RE = re.compile(r"\]\((?:/teams/[^/]+/pages/)?([a-z0-9-]{1,48})\)", re.IGNORECASE)
def valid_hex_color(value: object) -> bool:
@@ -72,6 +72,19 @@ def safe_profile_bio_html(html_module, bio: str, bio_mode: str) -> str:
return "
" + html_module.escape(bio or "").replace("\n", "
") + "
"
+def extract_page_reference_slugs(markdown_text: str) -> list[str]:
+ text = str(markdown_text or "")
+ matches = PAGE_LINK_RE.findall(text)
+ seen = set()
+ slugs = []
+ for slug in matches:
+ normalized = slug.lower().strip()
+ if not normalized or normalized in seen:
+ continue
+ seen.add(normalized)
+ slugs.append(normalized)
+ return slugs
+
def attachment_kind_from_name_and_mime(
original_name: Optional[str],
@@ -316,7 +329,7 @@ def page_payload(app_module, page, user: Optional[dict]) -> dict:
)
)
)
-
+ rendered_html = render_markdown_to_safe_html(page["body"] or "")
return {
"id": page["id"],
"team_id": page["team_id"],
@@ -326,10 +339,12 @@ def page_payload(app_module, page, user: Optional[dict]) -> dict:
"channel_slug": page["channel_slug"],
"channel_name": page["channel_name"],
"parent_page_id": page["parent_page_id"] if "parent_page_id" in page.keys() else None,
+ "parent_page_slug": page["parent_page_slug"] if "parent_page_slug" in page.keys() else None,
+ "parent_page_title": page["parent_page_title"] if "parent_page_title" in page.keys() else None,
"slug": page["slug"],
"title": page["title"],
"body": page["body"],
- "body_html": render_markdown_to_safe_html(page["body"] or ""),
+ "body_html": rendered_html,
"visibility": page["visibility"],
"page_type": page["page_type"],
"created_by_user_id": page["created_by_user_id"],
@@ -344,8 +359,18 @@ def page_payload(app_module, page, user: Optional[dict]) -> dict:
or app_module["is_team_admin"](page["team_id"], user)
)
),
+ "children": load_page_children(app_module["get_db"], page["id"]),
+ "backlinks": load_page_backlinks(
+ app_module["get_db"],
+ page["id"],
+ page["slug"],
+ page["team_id"],
+ ),
+ "references": extract_page_reference_slugs(page["body"] or ""),
+ "comments": load_page_comments(app_module["get_db"], page["id"]),
}
+
def attachment_payload_from_row(row) -> Optional[dict]:
if not row or not row["id"]:
return None
@@ -813,6 +838,7 @@ def feed_message_payload(
)
return payload
+
def profile_payload(
html_module,
user_payload_func,
@@ -823,34 +849,32 @@ def profile_payload(
) -> dict:
is_self = bool(viewer and viewer["id"] == user_row["id"])
status_payload = user_payload_func(user_row, settings_row)
-
bio = profile_row["bio"] or ""
bio_mode = profile_row["bio_mode"] or "txt"
-
explicit_name_color = settings_row["name_color"] if settings_row else None
- resolved_name_color = resolve_name_color(user_row["role"], explicit_name_color)
+ resolved = resolve_name_color(user_row["role"], explicit_name_color)
- profile_visibility = (settings_row["profile_visibility"] if settings_row else "public") or "public"
+ profile_visibility = settings_row["profile_visibility"] if settings_row else "public"
if profile_visibility not in PROFILE_VISIBILITIES:
- profile_visibility = "public"
+ profile_visibility = "public"
- last_active_visibility = (settings_row["last_active_visibility"] if settings_row else "everyone") or "everyone"
+ last_active_visibility = settings_row["last_active_visibility"] if settings_row else "everyone"
if last_active_visibility not in LAST_ACTIVE_VISIBILITIES:
- last_active_visibility = "everyone"
+ last_active_visibility = "everyone"
- presence_mode = (settings_row["presence_mode"] if settings_row else "online") or "online"
+ presence_mode = settings_row["presence_mode"] if settings_row else "online"
if presence_mode not in PRESENCE_MODES:
- presence_mode = "online"
+ presence_mode = "online"
last_active_at = user_row["last_login_at"] if "last_login_at" in user_row.keys() else None
can_show_last_active = False
- if is_self:
- can_show_last_active = True
- elif last_active_visibility == "everyone":
+ if last_active_visibility == "everyone":
can_show_last_active = True
elif last_active_visibility == "members":
- can_show_last_active = bool(viewer and viewer["role"] in {"moderator", "admin"})
+ can_show_last_active = bool(viewer and (viewer["id"] == user_row["id"] or viewer["role"] in {"moderator", "admin"}))
+ elif last_active_visibility == "nobody":
+ can_show_last_active = bool(viewer and viewer["id"] == user_row["id"])
return {
"id": user_row["id"],
@@ -872,10 +896,10 @@ def profile_payload(
"banner_image_url": f"/api/attachments/{profile_row['banner_attachment_id']}/download" if profile_row["banner_attachment_id"] else "",
"updated_at": profile_row["updated_at"],
"is_self": is_self,
- "name_color": normalized_hex_color(explicit_name_color) if explicit_name_color else None,
- "resolved_name_color": resolved_name_color,
- "profile_background_color": normalized_hex_color(settings_row["profile_background_color"]) if settings_row and settings_row["profile_background_color"] else None,
- "profile_banner_color": normalized_hex_color(settings_row["profile_banner_color"]) if settings_row and settings_row["profile_banner_color"] else None,
+ "name_color": explicit_name_color,
+ "resolved_name_color": resolved,
+ "profile_background_color": settings_row["profile_background_color"] if settings_row else None,
+ "profile_banner_color": settings_row["profile_banner_color"] if settings_row else None,
"profile_visibility": profile_visibility,
"last_active_visibility": last_active_visibility,
}