comparison 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
comparison
equal deleted inserted replaced
581:1c1dbe03d3c6 582:c6380dd30602
44 self.started = False 44 self.started = False
45 self.state = None 45 self.state = None
46 self.timer = None 46 self.timer = None
47 47
48 def _onEvent(self, state): 48 def _onEvent(self, state):
49 """Pyjamas callback takes no extra argument so we need this trick""" 49 # Pyjamas callback takes no extra argument so we need this trick
50
50 # Here we should check the value of the parameter "Send chat state notifications" 51 # Here we should check the value of the parameter "Send chat state notifications"
51 # but this costs two messages. It's even better to call chatStateComposing 52 # but this costs two messages. It's even better to call chatStateComposing
52 # with a doubt, it will be checked by the back-end anyway before sending 53 # with a doubt, it will be checked by the back-end anyway before sending
53 # the actual notifications to the other client. 54 # the actual notifications to the other client.
54 if state == "composing" and not self.started: 55 if state == "composing" and not self.started:
56 self.started = True 57 self.started = True
57 self.next_state = state 58 self.next_state = state
58 self.__onEvent(None) 59 self.__onEvent(None)
59 60
60 def __onEvent(self, timer): 61 def __onEvent(self, timer):
61 # print "on event %s" % self.next_state
62 state = self.next_state 62 state = self.next_state
63 self.next_state = "" 63
64 assert(state in TRANSITIONS)
65 transition = TRANSITIONS[state]
66 assert("next_state" in transition and "delay" in transition)
67
64 if state != self.state and state == "composing": 68 if state != self.state and state == "composing":
65 self.host.bridge.call('chatStateComposing', None, self.target_s) 69 self.host.bridge.call('chatStateComposing', None, self.target_s)
70
66 self.state = state 71 self.state = state
67 if not self.timer is None: 72 if self.timer is not None:
68 self.timer.cancel() 73 self.timer.cancel()
69 74
70 if not state in TRANSITIONS: 75 if transition["next_state"] and transition["delay"] > 0:
71 return 76 self.next_state = transition["next_state"]
72 if not "next_state" in TRANSITIONS[state]: 77 self.timer = Timer(transition["delay"] * 1000, self.__onEvent) # pyjamas timer is in milliseconds
73 return
74 if not "delay" in TRANSITIONS[state]:
75 return
76 next_state = TRANSITIONS[state]["next_state"]
77 delay = TRANSITIONS[state]["delay"]
78 if next_state == "" or delay < 0:
79 return
80 self.next_state = next_state
81 # pyjamas timer in milliseconds
82 self.timer = Timer(delay * 1000, self.__onEvent)