diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-09-24 21:43:36 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-09-24 21:43:36 -0400 |
commit | 27c52cc8c52157d539bb3c761a53d1b6192c8b64 (patch) | |
tree | 79def6b09af2fcd84709e9f34fc7505c514c8fd6 /group_messaging/views.py | |
parent | 18770de6588c50d9a2fdcc863cdf977f257c263b (diff) | |
download | askbot-27c52cc8c52157d539bb3c761a53d1b6192c8b64.tar.gz askbot-27c52cc8c52157d539bb3c761a53d1b6192c8b64.tar.bz2 askbot-27c52cc8c52157d539bb3c761a53d1b6192c8b64.zip |
hopefully fixed a corner case bug in the login system
Diffstat (limited to 'group_messaging/views.py')
-rw-r--r-- | group_messaging/views.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/group_messaging/views.py b/group_messaging/views.py index 8c06ff99..6511fe6e 100644 --- a/group_messaging/views.py +++ b/group_messaging/views.py @@ -141,12 +141,6 @@ class ThreadsList(InboxView): """returns thread list data""" #get threads and the last visit time threads = Message.objects.get_threads_for_user(request.user) - try: - last_visit = LastVisitTime.objects.get(user=request.user) - except LastVisitTime.DoesNotExist: - timestamp = datetime.datetime(2010, 3, 24)#day of askbot - last_visit = LastVisitTime(user=request.user, at=timestamp) - #for each thread we need to know if there is something #unread for the user - to mark "new" threads as bold @@ -154,21 +148,26 @@ class ThreadsList(InboxView): for thread in threads: thread_data = dict() #determine status - status = 'seen' - if thread.last_active_at > last_visit.at: - status = 'new' - thread_data['status'] = status + thread_data['status'] = 'new' #determine the senders info senders_names = thread.senders_info.split(',') if request.user.username in senders_names: senders_names.remove(request.user.username) thread_data['senders_info'] = ', '.join(senders_names) threads_data[thread.id] = thread_data + threads_data[thread] = thread + + last_visit_times = LastVisitTime.objects.filter( + user=request.user, + message__in=threads + ) + for last_visit in last_visit_times: + thread_data = threads_data[last_visit.thread_id] + if thread_data['thread'].last_active_at <= last_visit.at: + thread_data['status'] = 'seen' #after we have all the data - update the last visit time - last_visit.at = datetime.datetime.now() - last_visit.save() - + last_visit_times.update(at=datetime.datetime.now()) return {'threads': threads, 'threads_data': threads_data} |