From da6cf4c6d661db401446023769253000484c3a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evren=20Esat=20=C3=96zkan?= Date: Fri, 22 Jul 2016 13:57:55 +0300 Subject: [PATCH] rref #5367 rref #5366 ref zetaops/zengine#66 ref zetaops/zengine#65 --- zengine/messaging/model.py | 2 +- zengine/messaging/views.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/zengine/messaging/model.py b/zengine/messaging/model.py index ed90656a..ee362659 100644 --- a/zengine/messaging/model.py +++ b/zengine/messaging/model.py @@ -216,7 +216,7 @@ def unread_count(self): return self.channel.message_set.objects.filter( timestamp__lt=self.last_seen_msg_time).count() else: - self.channel.message_set.objects.filter().count() + return self.channel.message_set.objects.filter().count() def create_exchange(self): """ diff --git a/zengine/messaging/views.py b/zengine/messaging/views.py index 524240f1..d1cebb9d 100644 --- a/zengine/messaging/views.py +++ b/zengine/messaging/views.py @@ -161,7 +161,7 @@ def show_channel(current, waited=False): """ ch = Channel(current).objects.get(current.input['key']) sbs = ch.get_subscription_for_user(current.user_id) - current.output = {'channel_key': current.input['key'], + current.output = {'key': current.input['key'], 'description': ch.description, 'name': sbs.name, 'actions': sbs.get_actions(), @@ -202,12 +202,13 @@ def channel_history(current): current.output = { 'status': 'OK', 'code': 201, - 'messages': [ - msg.serialize(current.user) - for msg in Message.objects.filter(channel_id=current.input['channel_key'], - timestamp__lt=current.input['timestamp'])[:20]] + 'messages': [] } + for msg in Message.objects.filter(channel_id=current.input['channel_key'], + updated_at__lt=current.input['timestamp'])[:20]: + current.output['messages'].insert(0, msg.serialize(current.user)) + def report_last_seen_message(current): """ @@ -273,14 +274,18 @@ def list_channels(current): current.output = { 'status': 'OK', 'code': 200, - 'channels': [{'name': sbs.name, - 'key': sbs.channel.key, - 'type': sbs.channel.typ, - 'read_only': sbs.read_only, - 'is_online': sbs.is_online(), - 'actions': sbs.get_actions(), - 'unread': sbs.unread_count()} for sbs in - current.user.subscriptions.objects.filter(is_visible=True)]} + 'channels': []} + for sbs in current.user.subscriptions.objects.filter(is_visible=True): + try: + current.output['channels'].append({'name': sbs.name, + 'key': sbs.channel.key, + 'type': sbs.channel.typ, + 'read_only': sbs.read_only, + 'is_online': sbs.is_online(), + 'actions': sbs.get_actions(), + 'unread': sbs.unread_count()}) + except ObjectDoesNotExist: + sbs.delete() def create_channel(current): @@ -311,7 +316,7 @@ def create_channel(current): 'last_messages': [MSG_DICT] 'status': 'Created', 'code': 201, - 'channel_key': key, # of just created channel + 'key': key, # of just created channel } """ channel = Channel(name=current.input['name'],