diff options
author | Tommy Lindgren <tommy.lindgren@gmail.com> | 2014-11-17 00:52:54 +0800 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2016-12-06 21:15:14 +0000 |
commit | 24cd60139c8b27732d8844b9512a02b6dea36faa (patch) | |
tree | 93f4c641e6afb87a77836fcba3907a21e0206353 /alot/db/thread.py | |
parent | da31729ee86f4a5619f571847701354d6448142a (diff) |
New option `thread_authors_order_by` to control author order
Default value 'first_message' lists authors in the order they joined the
conversation. Value 'latest_message' order authors by their latest
message, which makes it easier to see which authors who wrote the most
recent messages.
Note that authors with duplicate emails were previously filtered. We now
keep all authors where name + email is unique. This is behavior is
desired for some email notification services. For example, Jira will
set the From header to "Joe User <jira@company.com>" meaning you will
only see one author if you only keep unique email addresses.
Diffstat (limited to 'alot/db/thread.py')
-rw-r--r-- | alot/db/thread.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/alot/db/thread.py b/alot/db/thread.py index 8bb94a10..d3cd0757 100644 --- a/alot/db/thread.py +++ b/alot/db/thread.py @@ -1,6 +1,7 @@ # Copyright (C) 2011-2012 Patrick Totzke <patricktotzke@gmail.com> # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file +import operator from datetime import datetime from message import Message @@ -144,12 +145,11 @@ class Thread(object): def get_authors(self): """ returns a list of authors (name, addr) of the messages. - The authors are ordered by msg date and unique (by addr). + The authors are ordered by msg date and unique (by name/addr). :rtype: list of (str, str) """ if self._authors is None: - self._authors = [] seen = {} msgs = self.get_messages().keys() msgs_with_date = filter(lambda m: m.get_date() is not None, msgs) @@ -157,11 +157,18 @@ class Thread(object): # sort messages with date and append the others msgs_with_date.sort(None, lambda m: m.get_date()) msgs = msgs_with_date + msgs_without_date - for m in msgs: - pair = m.get_author() - if not pair[1] in seen: - seen[pair[1]] = True - self._authors.append(pair) + orderby = settings.get('thread_authors_order_by') + if orderby == 'latest_message': + for i, m in enumerate(msgs): + pair = m.get_author() + seen[pair] = i + else: # i.e. first_message + for i, m in enumerate(msgs): + pair = m.get_author() + if pair not in seen: + seen[pair] = i + self._authors = [ name for name, addr in + sorted(seen.items(), key=operator.itemgetter(1)) ] return self._authors def get_authors_string(self, own_addrs=None, replace_own=None): |