cleanup
This commit is contained in:
parent
c1fdaa73e6
commit
612c64b4d2
64
features.py
64
features.py
@ -35,7 +35,7 @@ LAST_ACTIVE_VISIBILITIES = {"everyone", "members", "nobody"}
|
|||||||
PRESENCE_MODES = {"online", "silent", "focus", "dnd"}
|
PRESENCE_MODES = {"online", "silent", "focus", "dnd"}
|
||||||
REACTION_EMOJI_RE = re.compile(r"^.{1,16}$")
|
REACTION_EMOJI_RE = re.compile(r"^.{1,16}$")
|
||||||
HEX_COLOR_RE = re.compile(r"^#[0-9a-fA-F]{6}$")
|
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:
|
def valid_hex_color(value: object) -> bool:
|
||||||
@ -72,19 +72,6 @@ def safe_profile_bio_html(html_module, bio: str, bio_mode: str) -> str:
|
|||||||
return "<p>" + html_module.escape(bio or "").replace("\n", "<br>") + "</p>"
|
return "<p>" + html_module.escape(bio or "").replace("\n", "<br>") + "</p>"
|
||||||
|
|
||||||
|
|
||||||
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(
|
def attachment_kind_from_name_and_mime(
|
||||||
original_name: Optional[str],
|
original_name: Optional[str],
|
||||||
@ -329,7 +316,7 @@ def page_payload(app_module, page, user: Optional[dict]) -> dict:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
rendered_html = render_markdown_to_safe_html(page["body"] or "")
|
|
||||||
return {
|
return {
|
||||||
"id": page["id"],
|
"id": page["id"],
|
||||||
"team_id": page["team_id"],
|
"team_id": page["team_id"],
|
||||||
@ -339,12 +326,10 @@ def page_payload(app_module, page, user: Optional[dict]) -> dict:
|
|||||||
"channel_slug": page["channel_slug"],
|
"channel_slug": page["channel_slug"],
|
||||||
"channel_name": page["channel_name"],
|
"channel_name": page["channel_name"],
|
||||||
"parent_page_id": page["parent_page_id"] if "parent_page_id" in page.keys() else None,
|
"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"],
|
"slug": page["slug"],
|
||||||
"title": page["title"],
|
"title": page["title"],
|
||||||
"body": page["body"],
|
"body": page["body"],
|
||||||
"body_html": rendered_html,
|
"body_html": render_markdown_to_safe_html(page["body"] or ""),
|
||||||
"visibility": page["visibility"],
|
"visibility": page["visibility"],
|
||||||
"page_type": page["page_type"],
|
"page_type": page["page_type"],
|
||||||
"created_by_user_id": page["created_by_user_id"],
|
"created_by_user_id": page["created_by_user_id"],
|
||||||
@ -359,18 +344,8 @@ def page_payload(app_module, page, user: Optional[dict]) -> dict:
|
|||||||
or app_module["is_team_admin"](page["team_id"], user)
|
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]:
|
def attachment_payload_from_row(row) -> Optional[dict]:
|
||||||
if not row or not row["id"]:
|
if not row or not row["id"]:
|
||||||
return None
|
return None
|
||||||
@ -838,7 +813,6 @@ def feed_message_payload(
|
|||||||
)
|
)
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
def profile_payload(
|
def profile_payload(
|
||||||
html_module,
|
html_module,
|
||||||
user_payload_func,
|
user_payload_func,
|
||||||
@ -849,32 +823,34 @@ def profile_payload(
|
|||||||
) -> dict:
|
) -> dict:
|
||||||
is_self = bool(viewer and viewer["id"] == user_row["id"])
|
is_self = bool(viewer and viewer["id"] == user_row["id"])
|
||||||
status_payload = user_payload_func(user_row, settings_row)
|
status_payload = user_payload_func(user_row, settings_row)
|
||||||
|
|
||||||
bio = profile_row["bio"] or ""
|
bio = profile_row["bio"] or ""
|
||||||
bio_mode = profile_row["bio_mode"] or "txt"
|
bio_mode = profile_row["bio_mode"] or "txt"
|
||||||
|
|
||||||
explicit_name_color = settings_row["name_color"] if settings_row else None
|
explicit_name_color = settings_row["name_color"] if settings_row else None
|
||||||
resolved = resolve_name_color(user_row["role"], explicit_name_color)
|
resolved_name_color = resolve_name_color(user_row["role"], explicit_name_color)
|
||||||
|
|
||||||
profile_visibility = settings_row["profile_visibility"] if settings_row else "public"
|
profile_visibility = (settings_row["profile_visibility"] if settings_row else "public") or "public"
|
||||||
if profile_visibility not in PROFILE_VISIBILITIES:
|
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"
|
last_active_visibility = (settings_row["last_active_visibility"] if settings_row else "everyone") or "everyone"
|
||||||
if last_active_visibility not in LAST_ACTIVE_VISIBILITIES:
|
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"
|
presence_mode = (settings_row["presence_mode"] if settings_row else "online") or "online"
|
||||||
if presence_mode not in PRESENCE_MODES:
|
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
|
last_active_at = user_row["last_login_at"] if "last_login_at" in user_row.keys() else None
|
||||||
|
|
||||||
can_show_last_active = False
|
can_show_last_active = False
|
||||||
if last_active_visibility == "everyone":
|
if is_self:
|
||||||
|
can_show_last_active = True
|
||||||
|
elif last_active_visibility == "everyone":
|
||||||
can_show_last_active = True
|
can_show_last_active = True
|
||||||
elif last_active_visibility == "members":
|
elif last_active_visibility == "members":
|
||||||
can_show_last_active = bool(viewer and (viewer["id"] == user_row["id"] or viewer["role"] in {"moderator", "admin"}))
|
can_show_last_active = bool(viewer and viewer["role"] in {"moderator", "admin"})
|
||||||
elif last_active_visibility == "nobody":
|
|
||||||
can_show_last_active = bool(viewer and viewer["id"] == user_row["id"])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": user_row["id"],
|
"id": user_row["id"],
|
||||||
@ -896,10 +872,10 @@ def profile_payload(
|
|||||||
"banner_image_url": f"/api/attachments/{profile_row['banner_attachment_id']}/download" if profile_row["banner_attachment_id"] else "",
|
"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"],
|
"updated_at": profile_row["updated_at"],
|
||||||
"is_self": is_self,
|
"is_self": is_self,
|
||||||
"name_color": explicit_name_color,
|
"name_color": normalized_hex_color(explicit_name_color) if explicit_name_color else None,
|
||||||
"resolved_name_color": resolved,
|
"resolved_name_color": resolved_name_color,
|
||||||
"profile_background_color": settings_row["profile_background_color"] if settings_row else None,
|
"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": settings_row["profile_banner_color"] if settings_row else None,
|
"profile_banner_color": normalized_hex_color(settings_row["profile_banner_color"]) if settings_row and settings_row["profile_banner_color"] else None,
|
||||||
"profile_visibility": profile_visibility,
|
"profile_visibility": profile_visibility,
|
||||||
"last_active_visibility": last_active_visibility,
|
"last_active_visibility": last_active_visibility,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user