Mercurial > libervia-web
diff src/browser/sat_browser/plugin_xep_0085.py @ 582:c6380dd30602
plugin XEP-0085: follow the changes in sat plugin
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 22 Oct 2014 14:17:17 +0200 |
parents | 97c72fe4a5f2 |
children | 9877607c719a |
line wrap: on
line diff
--- a/src/browser/sat_browser/plugin_xep_0085.py Mon Oct 20 10:00:44 2014 +0200 +++ b/src/browser/sat_browser/plugin_xep_0085.py Wed Oct 22 14:17:17 2014 +0200 @@ -46,7 +46,8 @@ self.timer = None def _onEvent(self, state): - """Pyjamas callback takes no extra argument so we need this trick""" + # Pyjamas callback takes no extra argument so we need this trick + # Here we should check the value of the parameter "Send chat state notifications" # but this costs two messages. It's even better to call chatStateComposing # with a doubt, it will be checked by the back-end anyway before sending @@ -58,25 +59,19 @@ self.__onEvent(None) def __onEvent(self, timer): - # print "on event %s" % self.next_state state = self.next_state - self.next_state = "" + + assert(state in TRANSITIONS) + transition = TRANSITIONS[state] + assert("next_state" in transition and "delay" in transition) + if state != self.state and state == "composing": self.host.bridge.call('chatStateComposing', None, self.target_s) + self.state = state - if not self.timer is None: + if self.timer is not None: self.timer.cancel() - if not state in TRANSITIONS: - return - if not "next_state" in TRANSITIONS[state]: - return - if not "delay" in TRANSITIONS[state]: - return - next_state = TRANSITIONS[state]["next_state"] - delay = TRANSITIONS[state]["delay"] - if next_state == "" or delay < 0: - return - self.next_state = next_state - # pyjamas timer in milliseconds - self.timer = Timer(delay * 1000, self.__onEvent) + if transition["next_state"] and transition["delay"] > 0: + self.next_state = transition["next_state"] + self.timer = Timer(transition["delay"] * 1000, self.__onEvent) # pyjamas timer is in milliseconds