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 10, 2016
1 parent 408cd37 commit 1f70d8a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
2 changes: 1 addition & 1 deletion zengine/management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def create_user_channels(self):
ch, new = Channel.objects.get_or_create(owner=usr, typ=5)
print("%s exchange: %s" % ('created' if new else 'existing', ch.code_name))
# create notification subscription to private exchange
sb, new = Subscriber.objects.get_or_create(channel=ch, user=usr, is_visible=False,
sb, new = Subscriber.objects.get_or_create(channel=ch, user=usr, is_visible=True,
can_leave=False, inform_me=False)
print("%s notify sub: %s" % ('created' if new else 'existing', ch.code_name))

Expand Down
4 changes: 3 additions & 1 deletion zengine/messaging/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def encrypt_password(self):

def prepare_channels(self):
from zengine.messaging.model import Channel, Subscriber
# create private channel of user
ch, new = Channel.objects.get_or_create(owner=self, typ=5)
sb, new = Subscriber.objects.get_or_create(channel=ch, user=self, is_visible=False,
# create subscription entry for notification messages
sb, new = Subscriber.objects.get_or_create(channel=ch, user=self, is_visible=True,
can_leave=False, inform_me=False)

def check_password(self, raw_password):
Expand Down
3 changes: 3 additions & 0 deletions zengine/messaging/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class Channel(Model):
# class Managers(ListNode):
# user = UserModel()

def is_private(self):
return self.typ == 5

This comment has been minimized.

Copy link
@kunthar

kunthar Jul 10, 2016

Member

was is das?


@classmethod
def get_or_create_direct_channel(cls, initiator_key, receiver_key):
"""
Expand Down
86 changes: 63 additions & 23 deletions zengine/messaging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,33 @@
# (GPLv3). See LICENSE.txt for details.
from pyoko.conf import settings
from pyoko.lib.utils import get_object_from_path
from zengine.messaging.model import Channel, Attachment, Subscriber
from zengine.messaging.model import Channel, Attachment, Subscriber, Message
from zengine.views.base import BaseView

UserModel = get_object_from_path(settings.USER_MODEL)
UnitModel = get_object_from_path(settings.UNIT_MODEL)

"""
.. code-block:: python
MSG_DICT_FORMAT = {'content': string,
'title': string,
'time': datetime,
'channel_key': key,
'sender_name': string,
'sender_key': key,
'type': int,
'key': key,
'actions':[('name_string', 'cmd_string'),]
'attachments': [{
'description': string,
'file_name': string,
'url': string,
},]
}
"""


def create_message(current):
"""
Expand Down Expand Up @@ -83,17 +104,7 @@ def show_channel(current):
'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'),]
}]
'last_messages': [MSG_DICT_FORMAT]
}
"""
ch = Channel(current).objects.get(current.input['channel_key'])
Expand Down Expand Up @@ -131,8 +142,8 @@ def last_seen_msg(current):
}
"""
Subscriber(current).objects.filter(channel_id=current.input['channel_key'],
user_id=current.user_id
).update(last_seen_msg_time=current.input['timestamp'])
user_id=current.user_id
).update(last_seen_msg_time=current.input['timestamp'])


def list_channels(current):
Expand Down Expand Up @@ -160,7 +171,7 @@ def list_channels(current):
}
"""
current.output['channels'] = [
{'name': sbs.channel.name,
{'name': sbs.channel.name or ('Notifications' if sbs.channel.is_private() else ''),
'key': sbs.channel.key,
'type': sbs.channel.typ,
'actions': sbs.channel.get_actions_for(current.user),
Expand Down Expand Up @@ -223,7 +234,7 @@ def add_members(current):
newly_added, existing = [], []
for member_key in current.input['members']:
sb, new = Subscriber(current).objects.get_or_create(user_id=member_key,
channel_id=current.input['channel_key'])
channel_id=current.input['channel_key'])
if new:
newly_added.append(member_key)
else:
Expand Down Expand Up @@ -258,9 +269,9 @@ def add_unit_to_channel(current):
}
"""
newly_added, existing = [], []
for member_key in current.input['members']:
for member_key in UnitModel.get_user_keys(current, current.input['unit_key']):
sb, new = Subscriber(current).objects.get_or_create(user_id=member_key,
channel_id=current.input['channel_key'])
channel_id=current.input['channel_key'])
if new:
newly_added.append(member_key)
else:
Expand All @@ -273,6 +284,7 @@ def add_unit_to_channel(current):
'code': 201
}


def search_user(current):
"""
Search users for adding to a public rooms
Expand All @@ -299,9 +311,10 @@ def search_user(current):
'code': 201
}
for user in UserModel(current).objects.search_on(settings.MESSAGING_USER_SEARCH_FIELDS,
contains=current.input['query']):
contains=current.input['query']):
current.input['results'].append((user.full_name, user.key, user.avatar))


def search_unit(current):
"""
Search units for subscribing it's users to a channel
Expand All @@ -327,12 +340,10 @@ def search_unit(current):
'code': 201
}
for user in UnitModel(current).objects.search_on(settings.MESSAGING_UNIT_SEARCH_FIELDS,
contains=current.input['query']):
contains=current.input['query']):
current.input['results'].append((user.name, user.key))




def create_direct_channel(current):
"""
Create a One-To-One channel between current and selected user.
Expand Down Expand Up @@ -362,7 +373,36 @@ def create_direct_channel(current):


def find_message(current):
pass
"""
Search in messages. If "channel_key" given, search will be limited in that channel.
.. code-block:: python
# request:
{
'view':'_zops_search_unit,
'channel_key': key,
'query': string,
}
# response:
{
'results': [MSG_DICT_FORMAT, ],
'status': 'OK',
'code': 200
}
"""
current.output = {
'results': [],
'status': 'OK',
'code': 201
}
query_set = Message(current).objects.search_on(['msg_title', 'body', 'url'],
contains=current.input['query'])
if current.input['channel_key']:
query_set = query_set.filter(channel_id=current.input['channel_key'])
for msg in query_set:
current.input['results'].append(msg.serialize_for(current.user))


def delete_message(current):
Expand Down

0 comments on commit 1f70d8a

Please sign in to comment.