Skip to content

Commit

Permalink
fixed last message id when # of messages is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jpadilla1 committed Apr 30, 2014
1 parent 6e61846 commit bb160b6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/chats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def get_context_data(self, **kwargs):
context['form'] = self.get_form(self.get_form_class())
context['room'] = get_object_or_404(ChatRoom, slug=self.kwargs['slug'])
context['room_messages'] = Message.objects.filter(room=context['room'])
context['room_message_last'] = context['room_messages'].last().id - 1
if context['room_messages'].count() > 0:
context['room_message_last'] = context['room_messages'].last().id-1
users = User.objects.filter(
last_login__gt=self.request.user.last_logged_out,
is_active__exact=1, ).order_by('-last_login')
Expand Down Expand Up @@ -85,13 +86,14 @@ def get_ajax(self, request, *args, **kwargs):
m.append(i['fields'])
data = {
'messages': json.dumps(m),
'last_message_id': messages.last().id - 1,
'online_users': json.dumps(list(ChatRoom.objects.get(
slug=kwargs['slug']).members.filter(
last_login__gt=self.request.user.last_logged_out,
is_active__exact=1, ).order_by(
'-last_login').values('username')))
}
if messages.count() > 0:
data['last_message_id'] = messages.last().id - 1
return self.render_json_response(data)

def form_valid(self, form):
Expand Down

0 comments on commit bb160b6

Please sign in to comment.