diff --git a/server.py b/server.py index 25b5fd9..1d1445b 100644 --- a/server.py +++ b/server.py @@ -217,10 +217,12 @@ def delete_email(conversation_id, email): # Get email by id conversation = get_conversation(conversation_id) if not conversation: + print("No conversation found") return print(conversation) if len(conversation) < 1: + print("No conversation found") return headers = { @@ -231,6 +233,7 @@ def delete_email(conversation_id, email): if email in message["to"]: requests.delete( f"https://ticket.woodburn.au/api/conversations/{thread['id']}", headers=headers) + clear_cache() return @@ -249,11 +252,11 @@ def newemail(): return jsonify(json) - -@app.route("/api/email/") -def getemail(path): - email = f'{path}@login.hns.au' - return jsonify(get_email(email)) +# Removed for now +# @app.route("/api/email/") +# def getemail(path): +# email = f'{path}@login.hns.au' +# return jsonify(get_email(email)) def send_notification(data): @@ -327,7 +330,7 @@ def send_webhook(webhook, data): } } ], - "username": "HNS Login Email", + "username": "HNS Email", "avatar_url": "https://hns.au/favicon.png", "attachments": [] } @@ -339,6 +342,24 @@ def send_webhook(webhook, data): req = requests.post( webhook, json=body) +@app.route("/refresh") +def refresh(): + # Check if user is logged in + token = request.cookies.get("token") + if not token: + return redirect("/") + + # Get user info + user = get_user(token) + if not user: + return redirect("/logout") + + clear_cache() + return redirect("/inbox") + + +def clear_cache(): + get_email.cache_clear() @cache def get_user(token): @@ -445,7 +466,8 @@ def parse_email(conversation): "name": f'{thread["createdBy"]["firstName"]} {thread["createdBy"]["lastName"]}', "body": thread["body"], "date": thread["createdAt"], - "to": thread["to"] + "to": thread["to"], + "subject": conversation["subject"] }) return {"messages": messages, "id": conversation["id"]} diff --git a/templates/inbox.html b/templates/inbox.html index f2adb98..21e3adc 100644 --- a/templates/inbox.html +++ b/templates/inbox.html @@ -12,16 +12,21 @@
-

HNS Email

{{emails.email}} | Notifications | Logout +

HNS Email

{{emails.email}} | Notifications | Logout
- +
+ Refresh
+ {% for conversation in emails.conversations %}
Conversation: {{conversation.id}} {% for message in conversation.messages %} {% endfor %}