# HG changeset patch # User souliane # Date 1383682334 -3600 # Node ID 24335e82fef043891574433949948586383768e5 # Parent 38e6211d36caa4def3b7f7f1e744b1cdb866012b plugin XEP-249: added parameter Misc / Auto-join MUC on invitation: - also cleaned getOrCreateLiberviaWidget and _chatStateReceivedCb from unused arguments diff -r 38e6211d36ca -r 24335e82fef0 libervia.py --- a/libervia.py Wed Oct 23 18:33:16 2013 +0200 +++ b/libervia.py Tue Nov 05 21:12:14 2013 +0100 @@ -119,7 +119,7 @@ "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective", "getWaitingSub", "subscription", "delContact", "updateContact", "getCard", "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction", - "disconnect", "chatStateComposing", "getNewAccountDomain" + "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer" ]) @@ -354,6 +354,10 @@ self._roomUserJoinedCb(*args) elif name == 'roomUserLeft': self._roomUserLeftCb(*args) + elif name == 'askConfirmation': + self._askConfirmation(*args) + elif name == 'newAlert': + self._newAlert(*args) elif name == 'tarotGameStarted': self._tarotGameStartedCb(*args) elif name == 'tarotGameNew' or \ @@ -509,14 +513,11 @@ return None return None - def getOrCreateLiberviaWidget(self, class_, entity, add=True, refresh=True, add=True): + def getOrCreateLiberviaWidget(self, class_, entity, select=True): """Get the matching LiberviaWidget if it exists, or create a new one. @param class_: class of the panel (ChatPanel, MicroblogPanel...) @param entity: polymorphic parameter, see class_.matchEntity. - @param refresh: if True, refresh the display of a widget that is found - (ignored if no widget is found and a new one is created) - @param add: if True, add a widget that is created to the selected tab - (ignored if a widget is found and no new one is created) + @param select: if True, select the widget that has been found or created @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS is set to False or if the widget has not been found, the existing widget that has been found otherwise.""" @@ -525,14 +526,13 @@ lib_wid = self.getLiberviaWidget(class_, entity) if lib_wid is None: lib_wid = class_.createPanel(self, entity) - elif refresh: + else: # remove the widget from its previous panel panel = lib_wid.getWidgetsPanel(verbose=False) if panel is not None: panel.removeWidget(lib_wid) - if add or refresh: - self.addWidget(lib_wid) - if refresh: + self.addWidget(lib_wid) + if select: # must be done after the widget is added, # for example to scroll to the bottom self.setSelected(lib_wid) @@ -657,11 +657,10 @@ if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare): lib_wid.updateValue('avatar', entity_jid_s, avatar) - def _chatStateReceivedCb(self, from_jid_s, state, profile): + def _chatStateReceivedCb(self, from_jid_s, state): """Callback when a new chat state is received. @param from_jid_s: JID from the contact who sent his state @param state: new state - @profile: current profile """ _from = JID(from_jid_s).bare if from_jid_s != "@ALL@" else from_jid_s for lib_wid in self.libervia_widgets: @@ -679,6 +678,17 @@ # TODO: chat state notification for groupchat pass + def _askConfirmation(self, confirmation_id, confirmation_type, data): + answer_data = {} + + def confirm_cb(result): + self.bridge.call('confirmationAnswer', None, confirmation_id, result, answer_data) + + if confirmation_type == "YES/NO": + dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show() + + def _newAlert(self, message, title, alert_type): + dialog.InfoDialog(title, message).show() if __name__ == '__main__': pyjd.setup("http://localhost:8080/libervia.html") diff -r 38e6211d36ca -r 24335e82fef0 libervia.tac --- a/libervia.tac Wed Oct 23 18:33:16 2013 +0200 +++ b/libervia.tac Tue Nov 05 21:12:14 2013 +0100 @@ -440,6 +440,12 @@ d = self.asyncBridgeCall("getNewAccountDomain") return d + def jsonrpc_confirmationAnswer(self, confirmation_id, result, answer_data): + """Send the user's answer to any previous 'askConfirmation' signal""" + profile = ISATSession(self.session).profile + self.sat_host.bridge.confirmationAnswer(confirmation_id, result, answer_data, profile) + + class Register(JSONRPCMethodManager): """This class manage the registration procedure with SàT It provide an api for the browser, check password and setup the web server""" @@ -653,7 +659,8 @@ _session = self.request.getSession() profile = ISATSession(_session).profile return bool(profile) - + + class SignalHandler(jsonrpc.JSONRPC): def __init__(self, sat_host): @@ -843,7 +850,7 @@ self.bridge.register("connectionError", self.signal_handler.connectionError) self.bridge.register("actionResult", self.action_handler.actionResultCb) #core - for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated']: + for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'entityDataUpdated', 'askConfirmation', 'newAlert']: self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) #plugins for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',