Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0085.py @ 660:69a8bfd266a5
core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 15 Oct 2013 19:28:34 +0200 |
parents | b6c22d9f593a |
children | 4f747d7fde8c |
comparison
equal
deleted
inserted
replaced
659:b6c22d9f593a | 660:69a8bfd266a5 |
---|---|
25 try: | 25 try: |
26 from twisted.words.protocols.xmlstream import XMPPHandler | 26 from twisted.words.protocols.xmlstream import XMPPHandler |
27 except ImportError: | 27 except ImportError: |
28 from wokkel.subprotocols import XMPPHandler | 28 from wokkel.subprotocols import XMPPHandler |
29 from threading import Timer | 29 from threading import Timer |
30 from twisted.words.xish.domish import generateElementsNamed | 30 from twisted.words.xish import domish |
31 | 31 |
32 NS_XMPP_CLIENT = "jabber:client" | 32 NS_XMPP_CLIENT = "jabber:client" |
33 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates" | 33 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates" |
34 CHAT_STATES = ["active", "inactive", "gone", "composing", "paused"] | 34 CHAT_STATES = ["active", "inactive", "gone", "composing", "paused"] |
35 MESSAGE_TYPES = ["chat", "groupchat"] | 35 MESSAGE_TYPES = ["chat", "groupchat"] |
141 """ | 141 """ |
142 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile): | 142 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile): |
143 return True | 143 return True |
144 | 144 |
145 try: | 145 try: |
146 generateElementsNamed(message.children, name="body").next() | 146 domish.generateElementsNamed(message.elements(), name="body").next() |
147 from_jid = JID(message.getAttribute("from")) | 147 from_jid = JID(message.getAttribute("from")) |
148 try: | 148 try: |
149 generateElementsNamed(message.children, name="active").next() | 149 domish.generateElementsNamed(message.elements(), name="active").next() |
150 # contact enabled Chat State Notifications | 150 # contact enabled Chat State Notifications |
151 self.updateEntityData(from_jid, True, profile) | 151 self.updateEntityData(from_jid, True, profile) |
152 # init to send following "composing" state | 152 # init to send following "composing" state |
153 self.__chatStateInit(from_jid, message.getAttribute("type"), profile) | 153 self.__chatStateInit(from_jid, message.getAttribute("type"), profile) |
154 except StopIteration: | 154 except StopIteration: |
156 self.updateEntityData(from_jid, False, profile) | 156 self.updateEntityData(from_jid, False, profile) |
157 return True | 157 return True |
158 except StopIteration: | 158 except StopIteration: |
159 pass | 159 pass |
160 | 160 |
161 state_list = [child.name for child in message.children if | 161 state_list = [child.name for child in message.elements() if |
162 message.getAttribute("type") in MESSAGE_TYPES | 162 message.getAttribute("type") in MESSAGE_TYPES |
163 and child.name in CHAT_STATES | 163 and child.name in CHAT_STATES |
164 and child.defaultUri == NS_CHAT_STATES] | 164 and child.defaultUri == NS_CHAT_STATES] |
165 for state in state_list: | 165 for state in state_list: |
166 # there must be only one state according to the XEP | 166 # there must be only one state according to the XEP |
176 to_jid = JID(message.getAttribute("to")) | 176 to_jid = JID(message.getAttribute("to")) |
177 if not self.__checkActivation(to_jid, forceEntityData=True, profile=profile): | 177 if not self.__checkActivation(to_jid, forceEntityData=True, profile=profile): |
178 return True | 178 return True |
179 try: | 179 try: |
180 # message with a body always mean active state | 180 # message with a body always mean active state |
181 generateElementsNamed(message.children, name="body").next() | 181 domish.generateElementsNamed(message.elements(), name="body").next() |
182 message.addElement('active', NS_CHAT_STATES) | 182 message.addElement('active', NS_CHAT_STATES) |
183 # launch the chat state machine (init the timer) | 183 # launch the chat state machine (init the timer) |
184 self.__chatStateActive(to_jid, mess_data["type"], profile) | 184 self.__chatStateActive(to_jid, mess_data["type"], profile) |
185 except StopIteration: | 185 except StopIteration: |
186 if "chat_state" in mess_data["options"]: | 186 if "chat_state" in mess_data["options"]: |