Skip to content

Commit

Permalink
rref #5367
Browse files Browse the repository at this point in the history
rref #5366

ref #66
ref #65
  • Loading branch information
evrenesat committed Jul 8, 2016
1 parent 7b3448e commit cb95cdf
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 53 deletions.
2 changes: 1 addition & 1 deletion zengine/messaging/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_message(cls, channel_key, body, title=None, sender=None, url=None, typ=2
typ=typ, channel_id=channel_key, receiver=receiver).save()

def get_last_messages(self):
# TODO: Refactor this with RabbitMQ Last Cached Messages exchange
# TODO: Try to refactor this with https://github.com/rabbitmq/rabbitmq-recent-history-exchange
return self.message_set.objects.filter()[:20]

@classmethod
Expand Down
16 changes: 16 additions & 0 deletions zengine/messaging/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
"""

# Copyright (C) 2015 ZetaOps Inc.
#
# This file is licensed under the GNU General Public License v3
# (GPLv3). See LICENSE.txt for details.
from zengine.auth.permissions import CustomPermission

CustomPermission.add_multi(
# ('code_name', 'human_readable_name', 'description'),
[
('messaging.can_invite_user_by_unit', 'Can invite all users of a unit', ''),
('messaging.can_invite_user_by_searching', 'Can invite any user by searching on name', ''),
])
128 changes: 76 additions & 52 deletions zengine/messaging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ def create_message(current):
{
'view':'_zops_create_message',
'message': {
'channel': key, # of channel",
'receiver': key, " of receiver. Should be set only for direct messages",
'title': "Title of the message. Can be blank.",
'body': "Message body.",
'type': zengine.messaging.model.MSG_TYPES,
'channel': key, # of channel
'receiver': key, # of receiver. Should be set only for direct messages,
'body': string, # message text.,
'type': int, # zengine.messaging.model.MSG_TYPES,
'attachments': [{
'description': "Can be blank.",
'name': "File name with extension.",
'content': "base64 encoded file content"
'description': string, # can be blank,
'name': string, # file name with extension,
'content': string, # base64 encoded file content
}]}
# response:
{
'msg_key': key, # of the just created message object,
}
{
'status': string, # 'OK' for success
'code': int, # 201 for success
'msg_key': key, # key of the message object,
}
"""
msg = current.input['message']
Expand Down Expand Up @@ -73,31 +74,29 @@ def show_channel(current):
# response:
{
'channel_key': key,
'description': string,
'no_of_members': int,
'member_list': [
{'name': string,
'is_online': bool,
'avatar_url': string,
}],
'last_messages': [
{'content': string,
'title': string,
'time': datetime,
'channel_key': key,
'sender_name': string,
'sender_key': key,
'type': int,
'key': key,
'actions':[('name_string', 'cmd_string'),]
}
]
'channel_key': key,
'description': string,
'no_of_members': int,
'member_list': [
{'name': string,
'is_online': bool,
'avatar_url': string,
}],
'last_messages': [
{'content': string,
'title': string,
'time': datetime,
'channel_key': key,
'sender_name': string,
'sender_key': key,
'type': int,
'key': key,
'actions':[('name_string', 'cmd_string'),]
}]
}
"""
ch_key = current.input['channel_key']
ch = Channel.objects.get(ch_key)
current.output = {'channel_key': ch_key,
ch = Channel.objects.get(current.input['channel_key'])
current.output = {'channel_key': current.input['channel_key'],
'description': ch.description,
'no_of_members': len(ch.subscriber_set),
'member_list': [{'name': sb.user.full_name,
Expand All @@ -111,29 +110,28 @@ def show_channel(current):

def last_seen_msg(current):
"""
Initial display of channel content.
Returns channel description, members, no of members, last 20 messages etc.
Push timestamp of last seen message for a channel
.. code-block:: python
# request:
{
'view':'_zops_last_seen_msg',
'channel_key': key,
'msg_key': key,
'msg_date': datetime,
'view':'_zops_last_seen_msg',
'channel_key': key,
'msg_key': key,
'timestamp': datetime,
}
# response:
None
{
'status': 'OK',
'code': 200,
}
"""
Subscriber.objects.filter(channel_id=current.input['channel_key'],
user_id=current.user_id
).update(last_seen_msg_time=current.input['msg_date'])



).update(last_seen_msg_time=current.input['timestamp'])


def list_channels(current):
Expand All @@ -145,21 +143,20 @@ def list_channels(current):
# request:
{
'view':'_zops_list_channels',
'view':'_zops_list_channels',
}
# response:
{
# response:
{
'channels': [
{'name': string,
'key': key,
'unread': int,
'type': int,
'key': key,
'actions':[('name_string', 'cmd_string'),]
}
]
}
},]
}
"""
current.output['channels'] = [
{'name': sbs.channel.name,
Expand All @@ -171,7 +168,34 @@ def list_channels(current):


def create_public_channel(current):
pass
"""
Create a public chat room
.. code-block:: python
# request:
{
'view':'_zops_create_public_channel,
'name': string,
'description': string,
}
# response:
{
'status': 'Created',
'code': 201,
'channel_key': key, # of just created channel
}
"""
channel = Channel(name=current.input['name'],
description=current.input['description'],
owner=current.user,
typ=15).save()
current.output = {
'channel_key': channel.key,
'status': 'OK',
'code': 201
}


def create_direct_channel(current):
Expand Down

0 comments on commit cb95cdf

Please sign in to comment.