Initial event system implementation

This version has several limitations that are addressed in later
commits in this series.

(imported from commit 5d452b312d4204935059c4d602af0b9a8be1a009)
This commit is contained in:
Zev Benjamin
2013-03-26 13:06:00 -04:00
parent 5a58fb3c29
commit 8f4eaa63ad
4 changed files with 175 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ from zephyr.models import Message, UserProfile, UserMessage, \
from zephyr.decorator import JsonableError
from zephyr.lib.cache_helpers import cache_get_message
from zephyr.lib.queue import queue_json_publish
from zephyr.lib.event_queue import user_clients
import os
import sys
@@ -239,12 +240,21 @@ def update_pointer(user_profile_id, new_pointer):
new_pointer=new_pointer,
update_types=["pointer_update"])
for client in user_clients.get(user_profile_id, []):
event = dict(type='pointer', pointer=new_pointer)
client.add_event(event)
def process_new_message(data):
message = cache_get_message(data['message'])
for user_profile_id in data['users']:
user_receive_message(user_profile_id, message)
for client in user_clients.get(user_profile_id, []):
event = dict(type='message', message=message.to_dict(client.apply_markdown))
client.add_event(event)
if 'stream_name' in data:
stream_receive_message(data['realm_id'], data['stream_name'], message)