changeset 35:0e853a889c27

Entire conversation is sent on page load now.
author Atul Varma <varmaa@toolness.com>
date Mon, 27 Apr 2009 16:24:15 -0700
parents 10fcf63961d8
children d93c08dca64b
files openwebchat.py
diffstat 1 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/openwebchat.py	Mon Apr 27 16:01:52 2009 -0700
+++ b/openwebchat.py	Mon Apr 27 16:24:15 2009 -0700
@@ -11,9 +11,6 @@
 class Conversation(list):
     pass
 
-class Conversations(dict):
-    pass
-
 class OpenWebChatServer(object):
     CONVERSATION_URL = re.compile('\/conversations\/([A-Za-z0-9_]+)')
 
@@ -25,8 +22,8 @@
                   'js' : 'text/javascript',
                   'css' : 'text/css'}
 
-    def __init__(self, addr, conversations):
-        self._convs = conversations
+    def __init__(self, addr, conversation):
+        self._conv = conversation
         self._server = CoroutineSocketServer(addr,
                                              self._server_coroutine)
 
@@ -98,13 +95,18 @@
         req_parts = request_line.split()
         if req_parts[1] == '/listen':
             yield self._until_multipart_header_sent(self.BOUNDARY)
+            i = 0
             while 1:
-                msg = yield channels.until_message_received('global')
-                yield self._until_multipart_part_sent(self.BOUNDARY, msg)
+                while i < len(self._conv):
+                    msg = self._conv[i]
+                    i += 1
+                    yield self._until_multipart_part_sent(self.BOUNDARY, msg)
+                yield channels.until_message_received('new-message')
         elif req_parts[1] == '/send':
             length = int(headers.getheader('Content-Length', 0))
             msg = yield until_received(bytes = length)
-            yield channels.until_message_sent('global', msg)
+            self._conv.append(msg)
+            yield channels.until_message_sent('new-message', None)
             yield self._until_http_response_sent('sent.')
         elif req_parts[1] in ['/', '/jquery.js', '/openwebchat.js',
                               '/json2.js', '/openwebchat.css']:
@@ -125,5 +127,5 @@
 
 if __name__ == '__main__':
     server = OpenWebChatServer(('127.0.0.1', 8071),
-                               Conversations())
+                               Conversation())
     server.run()