Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added message count to js in templates

  • Loading branch information...
commit e9649736eb2d8e9d7baaad00e92f9bec0a81ebea 1 parent 2617f7f
Sam Karp authored
View
5 geocamTalk/templates/geocamTalk/base.html
@@ -12,8 +12,9 @@
<body>
<header>
{% if user.is_authenticated %}
- <a href="/talk/messages/{{user.username}}">Messages</a> |
- <a href="/talk/messages/">All Messages</a> | Hello {% firstof user.first_name user.username %} <a href="/accounts/logout/">Logout</a>
+ <a href="/talk/messages/{{user.username}}">My Messages (<span id="new_message_count">0</span>)</a> |
+ <a href="/talk/messages/">All Messages</a> | Hello {% firstof user.first_name user.username %}
+ <a href="/accounts/logout/">Logout</a>
{% else %}
<a href="/accounts/login/">Login</a>
{% endif %}
View
3  geocamTalk/templates/geocamTalk/message_list.html
@@ -31,6 +31,7 @@
<script>
$(document).ready(function() {
var running_timestamp = {{ timestamp }};
+ var new_message_count = 0;
setInterval(function(){
// messagefeed.json looks like this:
// [{"content": "The hospital is full, no more beds...", "content_timestamp": "02/19 21:35:52", "has_geolocation": -122.4048743, "author": "Adam Grant"},
@@ -72,6 +73,8 @@
}
$('#message_list').prepend(html_str);
running_timestamp = data['ts'];
+ new_message_count += data['msgCnt'];
+ $('#new_message_count').html(new_message_count);
});
}, 3*1000);
});
View
20 geocamTalk/views.py
@@ -52,24 +52,14 @@ def feed_messages(request, recipient_username=None, author_username=None):
if since is not None:
since_dt = datetime.fromtimestamp(float(since) / (1000 * 1000))
- messages = TalkMessage.getMessages(recipient, author).filter(content_timestamp__gt=since_dt)
+ messages = TalkMessage.getMessages(recipient, author).filter(content_timestamp__gt=since_dt)
+ message_count = TalkMessage.getMessages(request.user).filter(content_timestamp__gt=since_dt).count()
else:
messages = TalkMessage.getMessages(recipient, author)
- return HttpResponse(json.dumps({'ts': timestamp,
+ message_count = TalkMessage.getMessages(request.user).count()
+ return HttpResponse(json.dumps({'ts': timestamp,
+ 'msgCnt': message_count,
'ms':[msg.getJson() for msg in messages]}))
-
-@login_required
-def feed_messages_cnt(request):
- timestamp = int(time.time() * 1000 * 1000)
- since = request.GET.get('since', None)
- recipient = request.user
-
- if since is not None:
- since_dt = datetime.fromtimestamp(float(since) / (1000 * 1000))
- messages = TalkMessage.getMessages(recipient).filter(content_timestamp__gt=since_dt)
- else:
- messages = TalkMessage.getMessages(recipient)
- return HttpResponse(json.dumps({'messageCnt': messages.count()}))
@login_required
def index(request):
Please sign in to comment.
Something went wrong with that request. Please try again.