summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-10-09 18:05:35 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-10-09 18:07:31 +0200
commitb366e589fd25a40a58f1e041370d6530b04d35fe (patch)
tree1b973acbbb6b45490fc435ca6ae5caa78172b94d
parentf231e1c86cea3ede1eceaa873d1a41e4e35277f9 (diff)
downloadkittystore-b366e589fd25a40a58f1e041370d6530b04d35fe.tar.gz
kittystore-b366e589fd25a40a58f1e041370d6530b04d35fe.tar.xz
kittystore-b366e589fd25a40a58f1e041370d6530b04d35fe.zip
Add a method to get the older and newer thread
-rw-r--r--kittystore/storm/store.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py
index b1d584e..5d9017c 100644
--- a/kittystore/storm/store.py
+++ b/kittystore/storm/store.py
@@ -377,6 +377,39 @@ class StormStore(object):
)).config(distinct=True)
return list(participants)
+ def get_thread_neighbors(self, list_name, thread_id):
+ """ Return the previous and the next threads of the specified thread,
+ in date order. The returned objects are the emails starting the
+ threads.
+
+ :param list_name: The name of the mailing list to query.
+ :param thread_id: The unique identifier of the thread as specified in
+ the database.
+ :returns: A couple formed of the older thread and the newer thread, in
+ this order.
+ :rtype: tuple
+ """
+ current_email = self.get_message_by_hash_from_list(list_name, thread_id)
+ next_email = self.db.find(Email, And(
+ Email.list_name == unicode(list_name),
+ Email.in_reply_to == None,
+ Email.date > current_email.date,
+ )).order_by(Email.date)
+ try:
+ next_email = next_email[0]
+ except IndexError:
+ next_email = None
+ prev_email = self.db.find(Email, And(
+ Email.list_name == unicode(list_name),
+ Email.in_reply_to == None,
+ Email.date < current_email.date,
+ )).order_by(Desc(Email.date))
+ try:
+ prev_email = prev_email[0]
+ except IndexError:
+ prev_email = None
+ return (prev_email, next_email)
+
def get_list(self, list_name):
""" Return the list object for a mailing list name.