Mercurial > libervia-web
comparison libervia.py @ 55:d5266c41ca24
Roster list update, contact deletion + some refactoring
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 May 2011 02:13:53 +0200 |
parents | f25c4077f6b9 |
children | e552a67b933d |
comparison
equal
deleted
inserted
replaced
54:f25c4077f6b9 | 55:d5266c41ca24 |
---|---|
66 class BridgeCall(LiberviaJsonProxy): | 66 class BridgeCall(LiberviaJsonProxy): |
67 def __init__(self): | 67 def __init__(self): |
68 LiberviaJsonProxy.__init__(self, "/json_api", | 68 LiberviaJsonProxy.__init__(self, "/json_api", |
69 ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", | 69 ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus", |
70 "joinMUC", "getRoomJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", | 70 "joinMUC", "getRoomJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed", |
71 "tarotGamePlayCards", "getWaitingSub", "subscription"]) | 71 "tarotGamePlayCards", "getWaitingSub", "subscription", "delContact"]) |
72 | 72 |
73 class BridgeSignals(LiberviaJsonProxy): | 73 class BridgeSignals(LiberviaJsonProxy): |
74 def __init__(self): | 74 def __init__(self): |
75 LiberviaJsonProxy.__init__(self, "/json_signal_api", | 75 LiberviaJsonProxy.__init__(self, "/json_signal_api", |
76 ["getSignals"]) | 76 ["getSignals"]) |
158 | 158 |
159 | 159 |
160 def _getContactsCB(self, contacts_data): | 160 def _getContactsCB(self, contacts_data): |
161 for contact in contacts_data: | 161 for contact in contacts_data: |
162 jid, attributes, groups = contact | 162 jid, attributes, groups = contact |
163 self.contact_panel.addContact(jid, attributes, groups) | 163 self._newContactCb(jid, attributes, groups) |
164 | 164 |
165 def _getSignalsCB(self, signal_data): | 165 def _getSignalsCB(self, signal_data): |
166 bridge_signals = BridgeSignals() | 166 bridge_signals = BridgeSignals() |
167 bridge_signals.call('getSignals', self._getSignalsCB) | 167 bridge_signals.call('getSignals', self._getSignalsCB) |
168 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) | 168 print('Got signal ==> name: %s, params: %s' % (signal_data[0],signal_data[1])) |
189 name == 'tarotGameYourTurn' or \ | 189 name == 'tarotGameYourTurn' or \ |
190 name == 'tarotGameScore': | 190 name == 'tarotGameScore': |
191 self._tarotGameGenericCb(name, args[0], args[1:]) | 191 self._tarotGameGenericCb(name, args[0], args[1:]) |
192 elif name == 'subscribe': | 192 elif name == 'subscribe': |
193 self._subscribeCb(*args) | 193 self._subscribeCb(*args) |
194 elif name == 'contactDeleted': | |
195 self._contactDeletedCb(*args) | |
196 elif name == 'newContact': | |
197 self._newContactCb(*args) | |
194 | 198 |
195 def _getProfileJidCB(self, jid): | 199 def _getProfileJidCB(self, jid): |
196 self.whoami = JID(jid) | 200 self.whoami = JID(jid) |
197 #we can now ask our status | 201 #we can now ask our status |
198 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb) | 202 self.bridge.call('getPresenceStatus', self._getPresenceStatusCb) |
281 for sub in waiting_sub: | 285 for sub in waiting_sub: |
282 self._subscribeCb(waiting_sub[sub], sub) | 286 self._subscribeCb(waiting_sub[sub], sub) |
283 | 287 |
284 def _subscribeCb(self, sub_type, entity): | 288 def _subscribeCb(self, sub_type, entity): |
285 if sub_type == 'subscribed': | 289 if sub_type == 'subscribed': |
286 dialog.SimpleDialog('Subscription confirmation', 'The contact <b>%s</b> has added you to his/her contact list' % html_sanitize(entity)).show() | 290 dialog.InfoDialog('Subscription confirmation', 'The contact <b>%s</b> has added you to his/her contact list' % html_sanitize(entity)).show() |
287 | 291 |
288 elif sub_type == 'unsubscribed': | 292 elif sub_type == 'unsubscribed': |
289 dialog.SimpleDialog('Subscription refusal', 'The contact <b>%s</b> has refused to add you in his/her contact list' % html_sanitize(entity)).show() | 293 dialog.InfoDialog('Subscription refusal', 'The contact <b>%s</b> has refused to add you in his/her contact list' % html_sanitize(entity)).show() |
290 | 294 |
291 elif sub_type == 'subscribe': | 295 elif sub_type == 'subscribe': |
292 #The user want to subscribe to our presence | 296 #The user want to subscribe to our presence |
293 _dialog = None | 297 _dialog = None |
294 msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_sanitize(entity)) | 298 msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_sanitize(entity)) |
300 | 304 |
301 _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb) | 305 _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], ok_cb, cancel_cb) |
302 _dialog.setHTML('<b>Add contact request</b>') | 306 _dialog.setHTML('<b>Add contact request</b>') |
303 _dialog.show() | 307 _dialog.show() |
304 | 308 |
305 | 309 def _contactDeletedCb(self, entity): |
310 self.contact_panel.removeContact(entity) | |
311 | |
312 def _newContactCb(self, contact, attributes, groups): | |
313 self.contact_panel.updateContact(contact, attributes, groups) | |
306 | 314 |
307 if __name__ == '__main__': | 315 if __name__ == '__main__': |
308 pyjd.setup("http://localhost:8080/libervia.html") | 316 pyjd.setup("http://localhost:8080/libervia.html") |
309 app = SatWebFrontend() | 317 app = SatWebFrontend() |
310 app.onModuleLoad() | 318 app.onModuleLoad() |