38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Message formatting for new-meeting announcements."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from html import escape
|
|
from urllib.parse import quote
|
|
|
|
from .api import Meeting
|
|
|
|
|
|
def _format_local(moment) -> str:
|
|
return moment.astimezone().strftime("%a, %d %b %Y %H:%M %Z") if moment else "unknown"
|
|
|
|
|
|
def room_link(web_base_url: str, room: str) -> str:
|
|
return f"{(web_base_url or '').rstrip('/')}/rooms/{quote(room, safe='')}"
|
|
|
|
|
|
def format_new_meeting(meeting: Meeting, *, web_base_url: str = "") -> str:
|
|
"""Render an announcement; the join link appears only when a room exists."""
|
|
lines = ["<b>New meeting scheduled</b>", ""]
|
|
lines.append(f"<b>{escape(meeting.title) or '(untitled meeting)'}</b>")
|
|
|
|
if meeting.intent:
|
|
lines += ["", escape(meeting.intent)]
|
|
|
|
lines.append("")
|
|
lines.append(f"<b>When:</b> {escape(_format_local(meeting.scheduled_at))}")
|
|
lines.append(f"<b>Planned by:</b> {escape(meeting.created_by_name or 'unknown')}")
|
|
|
|
if meeting.room:
|
|
lines.append(f"<b>Room:</b> <code>{escape(meeting.room)}</code>")
|
|
if web_base_url:
|
|
link = room_link(web_base_url, meeting.room)
|
|
lines.append(f'<a href="{escape(link)}">Join the meeting</a>')
|
|
|
|
return "\n".join(lines)
|