From 460c3067123c52911ab36d5fd7c62fb1aded7037 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 5 Apr 2020 19:03:06 +0200 Subject: [PATCH] Order alias by latest activity instead of alias creation date. Show the latest activity & contact --- app/dashboard/templates/dashboard/index.html | 24 ++++++++++++++++++-- app/dashboard/views/index.py | 12 ++++++++++ app/models.py | 1 - 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 8d989090..c2da158e 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -135,19 +135,39 @@

- Created {{ alias.created_at | dt }} {% if alias_info.highlight %} - New {% endif %}

+ {% if alias_info.latest_email_log != None %} + {% set email_log = alias_info.latest_email_log %} + {% set contact = alias_info.latest_contact %} + + {% if email_log.is_reply %} + Email sent/reply to {{ contact.website_email }} + {{ email_log.created_at | dt }} + {% elif email_log.bounced %} + Email from {{ contact.website_email }} bounced + {{ email_log.created_at | dt }} + + {% elif email_log.blocked %} + Email from {{ contact.website_email }} blocked + {{ email_log.created_at | dt }} + {% else %} + Email from {{ contact.website_email }} + {{ email_log.created_at | dt }} + {% endif %} + {% endif %} +
+ {{ alias_info.nb_forward }} forwards, {{ alias_info.nb_blocked }} blocks, {{ alias_info.nb_reply }} replies - See All Activity  → + See All  →
diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 90ef1d49..8171cff8 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -26,10 +26,15 @@ from app.models import ( class AliasInfo: alias: Alias mailbox: Mailbox + nb_forward: int nb_blocked: int nb_reply: int + latest_activity: Arrow + latest_email_log: EmailLog = None + latest_contact: Contact = None + show_intro_test_send_email: bool = False highlight: bool = False @@ -210,12 +215,18 @@ def get_alias_infos(user, query=None, highlight_alias_id=None) -> [AliasInfo]: nb_forward=0, nb_reply=0, highlight=alias.id == highlight_alias_id, + latest_activity=alias.created_at, ) alias_info = aliases[alias.email] if not email_log: continue + if email_log.created_at > alias_info.latest_activity: + alias_info.latest_activity = email_log.created_at + alias_info.latest_email_log = email_log + alias_info.latest_contact = contact + if email_log.is_reply: alias_info.nb_reply += 1 elif email_log.blocked: @@ -224,6 +235,7 @@ def get_alias_infos(user, query=None, highlight_alias_id=None) -> [AliasInfo]: alias_info.nb_forward += 1 ret = list(aliases.values()) + ret = sorted(ret, key=lambda a: a.latest_activity, reverse=True) # make sure the highlighted alias is the first element highlight_index = None diff --git a/app/models.py b/app/models.py index e5cd7b43..2be7d095 100644 --- a/app/models.py +++ b/app/models.py @@ -732,7 +732,6 @@ class Contact(db.Model, ModelMixin): db.String(512), nullable=True, default=None, server_default=text("NULL") ) - # used to be envelope header, should be mail header from instead website_email = db.Column(db.String(512), nullable=False) # the email from header, e.g. AB CD