Skip to content

Commit

Permalink
web: be able to send messages :)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisfaure committed Jul 25, 2010
1 parent e85cddb commit a41498e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 12 additions & 4 deletions amsn2/ui/front_ends/web/bend.py
Expand Up @@ -48,8 +48,11 @@ def __init__(self, core):

gobject.io_add_watch(self._socket, gobject.IO_IN, self.on_accept)
self._q = ""

self.login_window = None
self.cl_window = None
self.chat_windows = {}
self.chat_widgets = {}

def on_accept(self, s, c):
w = s.accept()
Expand Down Expand Up @@ -115,7 +118,7 @@ def post_signin(self, w, uri, headers, body = None):
if (body and 'Content-Type' in headers
and headers['Content-Type'].startswith('application/x-www-form-urlencoded')):
args = cgi.parse_qs(body)
print "<<< %s" %(args,)
print "<<< signin: %s" %(args,)
self.login_window.signin(args['username'][0], args['password'][0])
w.write("HTTP/1.1 200 OK\r\n\r\n")
w.close()
Expand All @@ -129,19 +132,24 @@ def post_contact_clicked(self, w, uri, headers, body = None):
if (body and 'Content-Type' in headers
and headers['Content-Type'].startswith('application/x-www-form-urlencoded')):
args = cgi.parse_qs(body)
print "<<< %s" %(args,)
print "<<< contactClicked: %s" %(args,)
self.cl_window.get_contactlist_widget().contact_clicked(args['uid'][0])
w.write("HTTP/1.1 200 OK\r\n\r\n")
w.close()
return
w._400()

def post_send_msg(self, w, uri, headers, body = None):
print "Send Msg"
if (body and 'Content-Type' in headers
and headers['Content-Type'].startswith('application/x-www-form-urlencoded')):
args = cgi.parse_qs(body)
print "<<< %s" %(args,)
print "<<< sendMsg: %s" %(args,)
uid = args['uid'][0]
if uid not in self.chat_widgets:
w._400()
return
cw = self.chat_widgets[uid]
cw.send_message(uid, args['msg'])
w.write("HTTP/1.1 200 OK\r\n\r\n")
w.close()
return
Expand Down
14 changes: 11 additions & 3 deletions amsn2/ui/front_ends/web/chat_window.py
Expand Up @@ -10,8 +10,12 @@ def __init__(self, amsn_core):
self._amsn_core = amsn_core
self._uid = hashlib.md5(str(random.random())).hexdigest()
self._main = amsn_core._core._main
self._main.chat_windows[self._uid] = self
self._main.send("newChatWindow", self._uid)

def __del__(self):
self._main.chat_windows[self._uid] = None

def add_chat_widget(self, chat_widget):
""" add an aMSNChatWidget to the window """
self._main.send("addChatWidget", self._uid, chat_widget._uid)
Expand Down Expand Up @@ -60,14 +64,18 @@ def __init__(self, amsn_conversation, parent, contacts_uid):
it."""
self._main = parent._main
self._uid = hashlib.md5(str(random.random())).hexdigest()
self._main.chat_widgets[self._uid] = self
self._main.send("newChatWidget", self._uid)
self._amsn_conversation = amsn_conversation

def sendMessage(self, uid, msg):
def __del__(self):
self._main.chat_widgets[self._uid] = None

def send_message(self, uid, msg):
if uid == self._uid:
stmess = StringView()
stmess.appendText(msg)
self._amsn_conversation.sendMessage(stmess)
stmess.append_text('\n'.join(msg))
self._amsn_conversation.send_message(stmess)
return True


Expand Down

0 comments on commit a41498e

Please sign in to comment.