Commit d9518ea8 by benjaoming

Only mark shown notifications as read -- never the ones that haven't been…

Only mark shown notifications as read -- never the ones that haven't been display because only 10 notifications are display at the same time...
parent ebfaff48
......@@ -2,12 +2,13 @@
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('',
url('^json/get/$', 'django_notify.views.get_notifications', name='json_get', kwargs={}),
url('^json/get/(?P<latest_id>\d+)/$', 'django_notify.views.get_notifications', name='json_get', kwargs={}),
url('^json/mark-read/$', 'django_notify.views.mark_read', name='json_mark_read_base', kwargs={}),
url('^json/mark-read/(\d+)/$', 'django_notify.views.mark_read', name='json_mark_read', kwargs={}),
url('^goto/(?P<notification_id>\d+)/$', 'django_notify.views.goto', name='goto', kwargs={}),
url('^goto/$', 'django_notify.views.goto', name='goto_base', kwargs={}),
url('^json/get/$', 'django_notify.views.get_notifications', name='json_get'),
url('^json/get/(?P<latest_id>\d+)/$', 'django_notify.views.get_notifications', name='json_get'),
url('^json/mark-read/$', 'django_notify.views.mark_read', name='json_mark_read_base'),
url('^json/mark-read/(\d+)/$', 'django_notify.views.mark_read', name='json_mark_read'),
url('^json/mark-read/(?P<id_lte>\d+)/(?P<id_gte>\d+)/$', 'django_notify.views.mark_read', name='json_mark_read'),
url('^goto/(?P<notification_id>\d+)/$', 'django_notify.views.goto', name='goto'),
url('^goto/$', 'django_notify.views.goto', name='goto_base'),
)
def get_pattern(app_name="notify", namespace="notify"):
......
......@@ -17,8 +17,9 @@ def get_notifications(request, latest_id=None, is_viewed=False, max_results=10):
if not latest_id is None:
notifications = notifications.filter(id__gt=latest_id)
notifications = notifications.order_by('-id')
notifications = notifications.prefetch_related('subscription')
notifications = notifications[:max_results]
notifications = notifications[:max_results]
from django.contrib.humanize.templatetags.humanize import naturaltime
......@@ -45,14 +46,17 @@ def goto(request, notification_id=None):
@login_required_ajax
@json_view
def mark_read(request, up_to_id, notification_type_id=None):
def mark_read(request, id_lte, notification_type_id=None, id_gte=None):
notifications = models.Notification.objects.filter(subscription__settings__user=request.user,
id__lte=up_to_id)
id__lte=id_lte)
if notification_type_id:
notifications = notifications.filter(notification_type__id=notification_type_id)
if id_gte:
notifications = notifications.filter(id__gte=id_gte)
notifications.update(is_viewed=True)
return {'success': True}
\ No newline at end of file
notify_oldest_id = 0;
notify_latest_id = 0;
notify_update_timeout = 30000;
notify_update_timeout_adjust = 1.2; // factor to adjust between each timeout.
......@@ -12,9 +13,10 @@ function notify_update() {
} else {
$('.notification-cnt').removeClass('badge-important');
}
for (var i=0; i < data.objects.length; i++) {
for (var i=data.objects.length-1; i >=0 ; i--) {
n = data.objects[i];
notify_latest_id = n.pk>notify_latest_id ? n.pk:notify_latest_id;
notify_oldest_id = (n.pk<notify_oldest_id || notify_oldest_id==0) ? n.pk:notify_oldest_id;
$('.notification-li-container').prepend($('<li><a href="'+URL_NOTIFY_GOTO+n.pk+'/"><div>'+n.message+'</div><div class="since">'+n.since+'</div></a></li>'))
}
}
......@@ -23,7 +25,9 @@ function notify_update() {
function notify_mark_read() {
$('.notification-li-container').empty();
url = URL_NOTIFY_MARK_READ+notify_latest_id+'/';
url = URL_NOTIFY_MARK_READ+notify_latest_id+'/'+notify_oldest_id+'/';
notify_oldest_id = 0;
notify_latest_id = 0;
jsonWrapper(url, function (data) {
if (data.success) {
notify_update();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment