diff options
Diffstat (limited to 'hyperkitty/lib')
-rw-r--r-- | hyperkitty/lib/__init__.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py index a25dcd7..9bcded3 100644 --- a/hyperkitty/lib/__init__.py +++ b/hyperkitty/lib/__init__.py @@ -26,10 +26,11 @@ import datetime from django.core.exceptions import SuspiciousOperation from django.core.mail import EmailMessage from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from django.utils.timezone import utc from mailmanclient import MailmanConnectionError from hyperkitty.lib import mailman -from hyperkitty.models import ThreadCategory +from hyperkitty.models import ThreadCategory, LastView from hyperkitty.views.forms import CategoryForm @@ -214,3 +215,22 @@ def get_category_widget(request=None, current_category=None): except ThreadCategory.DoesNotExist: category = None return category, category_form + + +def is_thread_unread(request, mlist_name, thread): + """Returns True or False if the thread is unread or not.""" + unread = False + if request.user.is_authenticated(): + try: + last_view_obj = LastView.objects.get( + list_address=mlist_name, + threadid=thread.thread_id, + user=request.user) + except LastView.DoesNotExist: + unread = True + else: + if thread.date_active.replace(tzinfo=utc) \ + > last_view_obj.view_date: + unread = True + return unread + |