Order alias by latest activity instead of alias creation date. Show the latest activity & contact

This commit is contained in:
Son NK 2020-04-05 19:03:06 +02:00
parent af9178e216
commit 460c306712
3 changed files with 34 additions and 3 deletions

View File

@ -135,19 +135,39 @@
<hr class="my-2">
<p class="small-text">
Created {{ alias.created_at | dt }}
{% if alias_info.highlight %}
- <span class="font-weight-bold text-success small-text">New</span>
{% endif %}
</p>
<div class="" style="font-size: 12px">
{% 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 %}
<span class="text-danger">Email from {{ contact.website_email }} bounced
{{ email_log.created_at | dt }}
</span>
{% 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 %}
<br>
<span class="alias-activity">{{ alias_info.nb_forward }}</span> forwards,
<span class="alias-activity">{{ alias_info.nb_blocked }}</span> blocks,
<span class="alias-activity">{{ alias_info.nb_reply }}</span> replies
<a href="{{ url_for('dashboard.alias_log', alias_id=alias.id) }}"
class="btn btn-sm btn-link">
See All Activity &nbsp;
See All &nbsp;
</a>
</div>

View File

@ -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

View File

@ -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 <ab@cd.com>