diff --git a/src/chat_control.py b/src/chat_control.py index 64dc56d41..3e65efb96 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -337,14 +337,15 @@ class ChatControlBase(MessageControl): return True return False - def send_message(self, message, keyID = '', type = 'chat', chatstate = None, msg_id = None): + def send_message(self, message, keyID = '', type = 'chat', chatstate = None, msg_id = None, + composing_jep = None): '''Send the given message to the active tab''' if not message or message == '\n': return if not self._process_command(message): MessageControl.send_message(self, message, keyID, type = type, - chatstate = chatstate, msg_id = msg_id) + chatstate = chatstate, msg_id = msg_id, composing_jep = composing_jep) # Record message history self.save_sent_message(message) @@ -954,7 +955,7 @@ class ChatControl(ChatControlBase): chatstates_on = gajim.config.get('chat_state_notifications') != 'disabled' chatstate_to_send = None if chatstates_on and contact is not None: - if contact.our_chatstate is None: + if contact.composing_jep is None: # no info about peer # send active to discover chat state capabilities # this is here (and not in send_chatstate) @@ -964,7 +965,7 @@ class ChatControl(ChatControlBase): contact.our_chatstate = 'ask' # pseudo state # if peer supports jep85 and we are not 'ask', send 'active' # NOTE: first active and 'ask' is set in gajim.py - elif contact.our_chatstate not in (False, 'ask'): + elif contact.composing_jep is not False: #send active chatstate on every message (as JEP says) chatstate_to_send = 'active' contact.our_chatstate = 'active' @@ -974,7 +975,8 @@ class ChatControl(ChatControlBase): self._schedule_activity_timers() ChatControlBase.send_message(self, message, keyID, type = 'chat', - chatstate = chatstate_to_send, msg_id = contact.msg_id) + chatstate = chatstate_to_send, + composing_jep = contact.composing_jep) self.print_conversation(message, self.contact.jid, encrypted = encrypted) def check_for_possible_paused_chatstate(self, arg): @@ -1183,20 +1185,17 @@ class ChatControl(ChatControlBase): if contact is None: contact = self.parent_win.get_active_contact() - jid = contact.jid - else: - jid = contact.jid - - if contact is None: - # contact was from pm in MUC, and left the room so contact is None - # so we cannot send chatstate anymore - return + if contact is None: + # contact was from pm in MUC, and left the room so contact is None + # so we cannot send chatstate anymore + return + jid = contact.jid # Don't send chatstates to offline contacts if contact.show == 'offline': return - if contact.our_chatstate is False: # jid cannot do jep85 + if contact.composing_jep is False: # jid cannot do jep85 nor jep22 return # if the new state we wanna send (state) equals @@ -1204,7 +1203,7 @@ class ChatControl(ChatControlBase): if contact.our_chatstate == state: return - if contact.our_chatstate is None: + if contact.composing_jep is None: # we don't know anything about jid, so return # NOTE: # send 'active', set current state to 'ask' and return is done @@ -1216,6 +1215,15 @@ class ChatControl(ChatControlBase): if contact.our_chatstate == 'ask': return + # in JEP22, when we already sent stop composing + # notification on paused, don't resend it + if contact.composing_jep == 'JEP-0022' and \ + contact.our_chatstate in ('paused', 'active', 'inactive') and \ + state is not 'composing': # not composing == in (active, inactive, gone) + contact.our_chatstate = 'active' + self.reset_kbd_mouse_timeout_vars() + return + # prevent going paused if we we were not composing (JEP violation) if state == 'paused' and not contact.our_chatstate == 'composing': MessageControl.send_message(self, None, chatstate = 'active') # go active before @@ -1228,7 +1236,8 @@ class ChatControl(ChatControlBase): contact.our_chatstate = 'active' self.reset_kbd_mouse_timeout_vars() - MessageControl.send_message(self, None, chatstate = state) + MessageControl.send_message(self, None, chatstate = state, msg_id = contact.msg_id, + composing_jep = contact.composing_jep) contact.our_chatstate = state if contact.our_chatstate == 'active': self.reset_kbd_mouse_timeout_vars() diff --git a/src/common/connection.py b/src/common/connection.py index 0a643c2c2..c901317b4 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -398,6 +398,7 @@ class Connection: invite = None delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None msg_id = None + composing_jep = None # FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) do NOT RECOMMENDED # invitation # stanza (MUC JEP) remove in 2007, as we do not do NOT RECOMMENDED @@ -409,16 +410,19 @@ class Connection: return # chatstates - look for chatstate tags in a message if not delayed if not delayed: + composing_jep = False children = msg.getChildren() for child in children: if child.getNamespace() == 'http://jabber.org/protocol/chatstates': chatstate = child.getName() + composing_jep = 'JEP-0085' break # No JEP-0085 support, fallback to JEP-0022 if not chatstate: chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT) if chatstate_child: chatstate = 'active' + composing_jep = 'JEP-0022' if not msgtxt and chatstate_child.getTag('composing'): chatstate = 'composing' @@ -456,7 +460,7 @@ class Connection: no_log_for: gajim.logger.write('chat_msg_recv', frm, msgtxt, tim = tim, subject = subject) self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject, - chatstate, msg_id)) + chatstate, msg_id, composing_jep)) else: # it's single message if self.name not in no_log_for and jid not in no_log_for: gajim.logger.write('single_msg_recv', frm, msgtxt, tim = tim, subject = subject) @@ -469,7 +473,7 @@ class Connection: self.dispatch('GC_INVITATION',(frm, jid_from, reason, password)) else: self.dispatch('MSG', (frm, msgtxt, tim, encrypted, 'normal', - subject, chatstate, msg_id)) + subject, chatstate, msg_id, composing_jep)) # END messageCB def _presenceCB(self, con, prs): @@ -2112,7 +2116,8 @@ class Connection: msg_iq = common.xmpp.Message(to = jid, body = msg, subject = subject) self.connection.send(msg_iq) - def send_message(self, jid, msg, keyID, type = 'chat', subject='', chatstate = None, msg_id = None): + def send_message(self, jid, msg, keyID, type = 'chat', subject='', + chatstate = None, msg_id = None, composing_jep = None): if not self.connection: return if not msg and chatstate is None: @@ -2144,14 +2149,19 @@ class Connection: # please note that the only valid tag inside a message containing a
# tag is the active event if chatstate is not None: - # JEP-0085 - msg_iq.setTag(chatstate, namespace = common.xmpp.NS_CHATSTATES) - # JEP-0022 - chatstate_node = msg_iq.setTag('x', namespace = common.xmpp.NS_EVENT) - if msg_id: - chatstate_node.setTagData('id', msg_id) - if chatstate is 'composing' or msgtxt: - chatstate_node.addChild(name = 'composing') # we request JEP-0022 composing notification + if composing_jep == 'JEP-0085' or not composing_jep: + # JEP-0085 + msg_iq.setTag(chatstate, namespace = common.xmpp.NS_CHATSTATES) + if composing_jep == 'JEP-0022' or not composing_jep: + # JEP-0022 + chatstate_node = msg_iq.setTag('x', namespace = common.xmpp.NS_EVENT) + if not msgtxt: # when no , add