Mercurial > libervia-web
comparison libervia.tac @ 19:e8e3704eb97f
Added basic chat panel
- the chat panel show history, timestamp, and nickname (pretty similar to primitivus and wix chat window)
- JID has be rewritten to work with pyjamas, and is now in browser_side directory
- a widget can now be selected: the message send in uniBox will be sent to it if there is no explicit target prefix ("@something")
- a basic status panel is added under the uniBox, but not used yet
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 16 Apr 2011 01:46:01 +0200 |
parents | 9bf8ed012adc |
children | 8f4b1a8914c3 |
comparison
equal
deleted
inserted
replaced
18:795d144fc1d2 | 19:e8e3704eb97f |
---|---|
52 #user is not identified, we return a jsonrpc fault | 52 #user is not identified, we return a jsonrpc fault |
53 parsed = jsonrpclib.loads(request.content.read()) | 53 parsed = jsonrpclib.loads(request.content.read()) |
54 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia | 54 fault = jsonrpclib.Fault(0, "Not allowed") #FIXME: define some standard error codes for libervia |
55 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) | 55 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) |
56 return jsonrpc.JSONRPC.render(self, request) | 56 return jsonrpc.JSONRPC.render(self, request) |
57 | |
58 def jsonrpc_getProfileJid(self): | |
59 """Return the jid of the profile""" | |
60 profile = self.session.sat_profile | |
61 self.session.sat_jid = self.sat_host.bridge.getParamA("JabberID", "Connection", profile_key=profile) | |
62 return self.session.sat_jid | |
57 | 63 |
58 def jsonrpc_getContacts(self): | 64 def jsonrpc_getContacts(self): |
59 """Return all passed args.""" | 65 """Return all passed args.""" |
60 profile = self.session.sat_profile | 66 profile = self.session.sat_profile |
61 return self.sat_host.bridge.getContacts(profile) | 67 return self.sat_host.bridge.getContacts(profile) |
68 | |
69 def jsonrpc_sendMessage(self, to_jid, msg, subject, type): | |
70 """send message""" | |
71 profile = self.session.sat_profile | |
72 return self.sat_host.bridge.sendMessage(to_jid, msg, subject, type, profile) | |
62 | 73 |
63 def jsonrpc_sendMblog(self, raw_text): | 74 def jsonrpc_sendMblog(self, raw_text): |
64 """Parse raw_text of the microblog box, and send message consequently""" | 75 """Parse raw_text of the microblog box, and send message consequently""" |
65 profile = self.session.sat_profile | 76 profile = self.session.sat_profile |
66 match = re.match(r'@(.+?): *(.*$)', raw_text) | 77 match = re.match(r'@(.+?): *(.*$)', raw_text) |
71 #This text if for the public microblog | 82 #This text if for the public microblog |
72 print "Sending message to everybody" | 83 print "Sending message to everybody" |
73 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) | 84 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) |
74 else: | 85 else: |
75 return self.sat_host.bridge.sendGroupBlog([recip], text, profile) | 86 return self.sat_host.bridge.sendGroupBlog([recip], text, profile) |
87 | |
88 def jsonrpc_getHistory(self, from_jid, to_jid, size): | |
89 """Return history for the from_jid/to_jid couple""" | |
90 #FIXME: this method should definitely be asynchrone, need to fix it !!! | |
91 profile = self.session.sat_profile | |
92 try: | |
93 _jid = JID(self.session.sat_jid) | |
94 except: | |
95 error("No jid saved for this profile") | |
96 return {} | |
97 if JID(from_jid).userhost() != _jid.userhost() and JID(to_jid) != _jid.userhost(): | |
98 error("Trying to get history from a different jid, maybe a hack attempt ?") | |
99 return {} | |
100 return self.sat_host.bridge.getHistory(from_jid, to_jid, size) | |
76 | 101 |
77 | 102 |
78 | 103 |
79 class Register(jsonrpc.JSONRPC): | 104 class Register(jsonrpc.JSONRPC): |
80 """This class manage the registration procedure with SàT | 105 """This class manage the registration procedure with SàT |
283 print(u"Can't connect to SàT backend, are you sure it's launched ?") | 308 print(u"Can't connect to SàT backend, are you sure it's launched ?") |
284 import sys | 309 import sys |
285 sys.exit(1) | 310 sys.exit(1) |
286 self.bridge.register("connected", self.signal_handler.connected) | 311 self.bridge.register("connected", self.signal_handler.connected) |
287 self.bridge.register("connectionError", self.signal_handler.connectionError) | 312 self.bridge.register("connectionError", self.signal_handler.connectionError) |
288 for signal_name in ['presenceUpdate', 'personalEvent']: | 313 for signal_name in ['presenceUpdate', 'personalEvent', 'newMessage']: |
289 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) | 314 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) |
290 root.putChild('json_signal_api', self.signal_handler) | 315 root.putChild('json_signal_api', self.signal_handler) |
291 root.putChild('json_api', MethodHandler(self)) | 316 root.putChild('json_api', MethodHandler(self)) |
292 root.putChild('register_api', _register) | 317 root.putChild('register_api', _register) |
293 root.putChild('blog', MicroBlog(self)) | 318 root.putChild('blog', MicroBlog(self)) |