Fixes for message list pushed.
This commit is contained in:
@@ -164,48 +164,21 @@ async def mark_message_retrieved(
|
||||
@html_router.get("/messages", response_class=HTMLResponse)
|
||||
async def message_list_page(
|
||||
request: Request,
|
||||
msg_type: str = Query("all", description="Filter: received, sent, or all"),
|
||||
limit: Optional[int] = Query(50, le=200),
|
||||
type: str = Query("received", alias="msg_type"), # matches your filter links
|
||||
limit: Optional[int] = Query(50, le=100),
|
||||
current_user: HttpUser = Depends(get_current_http_user)
|
||||
):
|
||||
# Reuse the existing API endpoint logic directly (duplicate minimal code for simplicity)
|
||||
from packetserver.runners.http_server import get_db_connection
|
||||
from ..server import templates
|
||||
|
||||
conn = get_db_connection()
|
||||
root = conn.root()
|
||||
mailbox = root.get("mailbox", [])
|
||||
|
||||
# Filter based on type
|
||||
if msg_type == "received":
|
||||
filtered = [m for m in mailbox if current_user.username.upper() in [t.upper() for t in m.to]]
|
||||
elif msg_type == "sent":
|
||||
filtered = [m for m in mailbox if m.from_call.upper() == current_user.username.upper()]
|
||||
else: # all
|
||||
filtered = mailbox
|
||||
|
||||
# Sort newest first
|
||||
filtered.sort(key=lambda m: m.sent_at, reverse=True)
|
||||
|
||||
messages = []
|
||||
for msg in filtered[:limit]:
|
||||
messages.append({
|
||||
"id": msg.msg_id,
|
||||
"from": msg.from_call,
|
||||
"to": ", ".join(msg.to),
|
||||
"subject": msg.subject or "(no subject)",
|
||||
"text_preview": msg.text[:100] + ("..." if len(msg.text) > 100 else ""),
|
||||
"sent_at": msg.sent_at.isoformat() + "Z",
|
||||
"retrieved": getattr(msg, "retrieved", False),
|
||||
"has_attachments": bool(getattr(msg, "attachments", []))
|
||||
})
|
||||
from packetserver.http.server import templates
|
||||
# Directly call the existing API endpoint function
|
||||
api_resp = await get_messages(current_user=current_user, type=type, limit=limit, since=None)
|
||||
messages = api_resp["messages"]
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"message_list.html",
|
||||
{
|
||||
"request": request,
|
||||
"messages": messages,
|
||||
"msg_type": msg_type,
|
||||
"msg_type": type,
|
||||
"current_user": current_user.username
|
||||
}
|
||||
)
|
||||
@@ -48,5 +48,6 @@ app.include_router(dashboard.router)
|
||||
app.include_router(bulletins.router)
|
||||
app.include_router(bulletins.html_router)
|
||||
app.include_router(message_detail_router)
|
||||
app.include_router(messages.html_router)
|
||||
app.include_router(html_router)
|
||||
|
||||
|
||||
|
||||
@@ -12,21 +12,21 @@
|
||||
</div>
|
||||
|
||||
{% if messages %}
|
||||
<ul class="message-list">
|
||||
<ul class="message-list">
|
||||
{% for msg in messages %}
|
||||
<li>
|
||||
<strong><a href="/dashboard/message/{{ msg.id }}">{{ msg.subject }}</a></strong>
|
||||
<span class="meta">
|
||||
From: {{ msg.from }} | To: {{ msg.to }} | {{ msg.sent_at[:10] }} {{ msg.sent_at[11:19] }}
|
||||
{% if not msg.retrieved %}<span class="text-warning"> (Unread)</span>{% endif %}
|
||||
{% if msg.has_attachments %}<span class="text-info"> (Attachments)</span>{% endif %}
|
||||
</span>
|
||||
<div class="preview">{{ msg.text_preview }}</div>
|
||||
</li>
|
||||
<li>
|
||||
<strong><a href="/dashboard/message/{{ msg.id }}">{{ msg.text[:60] }}{% if msg.text|length > 60 %}...{% endif %}</a></strong>
|
||||
{% if msg.has_attachments %}<span class="text-info"> (Attachments)</span>{% endif %}
|
||||
{% if not msg.retrieved %}<span class="text-warning"> (Unread)</span>{% endif %}
|
||||
<span class="meta">
|
||||
From: {{ msg.from }} | To: {{ msg.to | join(', ') }} | {{ msg.sent_at[:10] }} {{ msg.sent_at[11:19] }}
|
||||
</span>
|
||||
<div class="preview">{{ msg.text[:200] }}{% if msg.text|length > 200 %}...{% endif %}</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</ul>
|
||||
{% else %}
|
||||
<p>No messages found.</p>
|
||||
<p>No messages found.</p>
|
||||
{% endif %}
|
||||
|
||||
<p><a href="/dashboard">← Back to Dashboard</a></p>
|
||||
|
||||
Reference in New Issue
Block a user