comparison libervia.tac @ 14:9bf8ed012adc

- Group microblog management, first draft - Bad connexion issue fixed
author Goffi <goffi@goffi.org>
date Thu, 07 Apr 2011 22:27:36 +0200
parents 331c093e4eb3
children e8e3704eb97f
comparison
equal deleted inserted replaced
13:0110d4e1d816 14:9bf8ed012adc
30 from twisted.web.resource import Resource 30 from twisted.web.resource import Resource
31 from twisted.words.protocols.jabber.jid import JID 31 from twisted.words.protocols.jabber.jid import JID
32 from txjsonrpc.web import jsonrpc 32 from txjsonrpc.web import jsonrpc
33 from txjsonrpc import jsonrpclib 33 from txjsonrpc import jsonrpclib
34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService 34 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService
35 35 import re
36 from server_side.blog import MicroBlog 36 from server_side.blog import MicroBlog
37 37
38 TIMEOUT = 120 #Session's time out, after that the user will be disconnected 38 TIMEOUT = 120 #Session's time out, after that the user will be disconnected
39 39
40 40
61 return self.sat_host.bridge.getContacts(profile) 61 return self.sat_host.bridge.getContacts(profile)
62 62
63 def jsonrpc_sendMblog(self, raw_text): 63 def jsonrpc_sendMblog(self, raw_text):
64 """Parse raw_text of the microblog box, and send message consequently""" 64 """Parse raw_text of the microblog box, and send message consequently"""
65 profile = self.session.sat_profile 65 profile = self.session.sat_profile
66 if raw_text.startswith('@@: '): 66 match = re.match(r'@(.+?): *(.*$)', raw_text)
67 #This text if for the public microblog 67 if match:
68 text = raw_text[4:] 68 recip = match.group(1)
69 if text: 69 text = match.group(2)
70 if recip == '@' and text:
71 #This text if for the public microblog
72 print "Sending message to everybody"
70 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile) 73 return self.sat_host.bridge.sendPersonalEvent("MICROBLOG", {'content':text}, profile)
74 else:
75 return self.sat_host.bridge.sendGroupBlog([recip], text, profile)
76
77
71 78
72 class Register(jsonrpc.JSONRPC): 79 class Register(jsonrpc.JSONRPC):
73 """This class manage the registration procedure with SàT 80 """This class manage the registration procedure with SàT
74 It provide an api for the browser, check password and setup the web server""" 81 It provide an api for the browser, check password and setup the web server"""
75 82
83 """Tell if a profile is trying to log in""" 90 """Tell if a profile is trying to log in"""
84 if self.profiles_waiting.has_key(profile): 91 if self.profiles_waiting.has_key(profile):
85 return self.profiles_waiting[profile] 92 return self.profiles_waiting[profile]
86 else: 93 else:
87 return None 94 return None
95
96 def _fillMblogNodes(self, result, session):
97 """Fill the microblog nodes association for this session"""
98 print "Filling session for %s with %s" % (session.sat_profile, result)
99 session.sat_mblog_nodes = dict(result)
88 100
89 def render(self, request): 101 def render(self, request):
90 """ 102 """
91 Render method with some hacks: 103 Render method with some hacks:
92 - if login is requested, try to login with form data 104 - if login is requested, try to login with form data
136 148
137 if self.profiles_waiting.has_key(_login): 149 if self.profiles_waiting.has_key(_login):
138 return "ALREADY WAITING" 150 return "ALREADY WAITING"
139 151
140 if self.sat_host.bridge.isConnected(_login): 152 if self.sat_host.bridge.isConnected(_login):
141 return self._logged(_login, request) 153 return self._logged(_login, request, finish=False)
142 154
143 self.profiles_waiting[_login] = request 155 self.profiles_waiting[_login] = request
144 self.sat_host.bridge.connect(_login) 156 self.sat_host.bridge.connect(_login)
145 return server.NOT_DONE_YET 157 return server.NOT_DONE_YET
146 158
149 try: 161 try:
150 del self.profiles_waiting[login] 162 del self.profiles_waiting[login]
151 except KeyError: 163 except KeyError:
152 pass 164 pass
153 165
154 def _logged(self, login, request): 166 def _logged(self, profile, request, finish=True):
155 """Set everything when a user just logged 167 """Set everything when a user just logged
156 and return "LOGGED" to the requester""" 168 and return "LOGGED" to the requester"""
157 self.__cleanWaiting(login) 169 self.__cleanWaiting(profile)
158 _session = request.getSession() 170 _session = request.getSession()
159 _session.sat_profile = login 171 _session.sat_profile = profile
160 return 'LOGGED' 172 d = defer.Deferred()
173 self.sat_host.bridge.getMblogNodes(profile, d.callback, d.errback)
174 d.addCallback(self._fillMblogNodes, _session)
175 if finish:
176 request.write('LOGGED')
177 request.finish()
178 else:
179 return "LOGGED"
161 180
162 def _logginError(self, login, request, error_type): 181 def _logginError(self, login, request, error_type):
163 """Something went wrong during loggin, return an error""" 182 """Something went wrong during loggin, return an error"""
164 self.__cleanWaiting(login) 183 self.__cleanWaiting(login)
165 return error_type 184 return error_type