diff --git a/plugins/banner_tweaks/plugin.py b/plugins/banner_tweaks/plugin.py index a100cfe45..2e7faeb31 100644 --- a/plugins/banner_tweaks/plugin.py +++ b/plugins/banner_tweaks/plugin.py @@ -135,27 +135,17 @@ class BannerTweaksPlugin(GajimPlugin): if cs and st in ('composing_only', 'all'): if contact.show == 'offline': chatstate = '' - elif contact.composing_xep == 'XEP-0085': - if st == 'all' or cs == 'composing': - chatstate = helpers.get_uf_chatstate(cs) - else: - chatstate = '' - elif contact.composing_xep == 'XEP-0022': - if cs in ('composing', 'paused'): - # only print composing, paused - chatstate = helpers.get_uf_chatstate(cs) - else: - chatstate = '' - else: - # When does that happen ? See [7797] and [7804] + elif st == 'all' or cs == 'composing': chatstate = helpers.get_uf_chatstate(cs) + else: + chatstate = '' label_text = '%s%s %s' % \ - (font_attrs, name, font_attrs_small, acct_info, chatstate) + (font_attrs, name, font_attrs_small, acct_info, chatstate) else: # weight="heavy" size="x-large" label_text = '%s%s' % \ - (font_attrs, name, font_attrs_small, acct_info) + (font_attrs, name, font_attrs_small, acct_info) banner_name_label.set_markup(label_text) diff --git a/src/chat_control.py b/src/chat_control.py index 295574271..136a0a018 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -54,6 +54,7 @@ from common.pep import MOODS, ACTIVITIES from common.xmpp.protocol import NS_XHTML, NS_XHTML_IM, NS_FILE, NS_MUC from common.xmpp.protocol import NS_RECEIPTS, NS_ESESSION from common.xmpp.protocol import NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO, NS_JINGLE_ICE_UDP +from common.xmpp.protocol import NS_CHATSTATES from common.connection_handlers_events import MessageOutgoingEvent from command_system.implementation.middleware import ChatCommandProcessor @@ -850,8 +851,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): return label def send_message(self, message, keyID='', type_='chat', chatstate=None, - msg_id=None, composing_xep=None, resource=None, xhtml=None, callback=None, - callback_args=[], process_commands=True): + msg_id=None, resource=None, xhtml=None, callback=None, callback_args=[], + process_commands=True): """ Send the given message to the active tab. Doesn't return None if error """ @@ -866,9 +867,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): gajim.nec.push_outgoing_event(MessageOutgoingEvent(None, account=self.account, jid=self.contact.jid, message=message, keyID=keyID, type_=type_, chatstate=chatstate, msg_id=msg_id, - composing_xep=composing_xep, resource=resource, - user_nick=self.user_nick, xhtml=xhtml, label=label, - callback=callback, callback_args=callback_args, control=self)) + resource=resource, user_nick=self.user_nick, xhtml=xhtml, + label=label, callback=callback, callback_args=callback_args, + control=self)) # Record the history of sent messages self.save_message(message, 'sent') @@ -2037,24 +2038,13 @@ class ChatControl(ChatControlBase): if cs and st in ('composing_only', 'all'): if contact.show == 'offline': chatstate = '' - elif contact.composing_xep == 'XEP-0085': - if st == 'all' or cs == 'composing': - chatstate = helpers.get_uf_chatstate(cs) - else: - chatstate = '' - elif contact.composing_xep == 'XEP-0022': - if cs in ('composing', 'paused'): - # only print composing, paused - chatstate = helpers.get_uf_chatstate(cs) - else: - chatstate = '' - else: - # When does that happen ? See [7797] and [7804] + elif st == 'all' or cs == 'composing': chatstate = helpers.get_uf_chatstate(cs) + else: + chatstate = '' label_text = '%s%s %s' \ - % (font_attrs, name, font_attrs_small, - acct_info, chatstate) + % (font_attrs, name, font_attrs_small, acct_info, chatstate) if acct_info: acct_info = ' ' + acct_info label_tooltip = '%s%s %s' % (name, acct_info, chatstate) @@ -2210,7 +2200,7 @@ class ChatControl(ChatControlBase): dialogs.ESessionInfoWindow(self.session) def send_message(self, message, keyID='', chatstate=None, xhtml=None, - process_commands=True): + process_commands=True): """ Send a message to contact """ @@ -2234,25 +2224,9 @@ class ChatControl(ChatControlBase): chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \ 'disabled' - composing_xep = contact.composing_xep chatstate_to_send = None if chatstates_on and contact is not None: - if composing_xep is None: - # no info about peer - # send active to discover chat state capabilities - # this is here (and not in send_chatstate) - # because we want it sent with REAL message - # (not standlone) eg. one that has body - - if contact.our_chatstate: - # We already asked for xep 85, don't ask it twice - composing_xep = 'asked_once' - - chatstate_to_send = 'active' - 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 composing_xep is not False: + if contact.supports(NS_CHATSTATES): # send active chatstate on every message (as XEP says) chatstate_to_send = 'active' contact.our_chatstate = 'active' @@ -2275,10 +2249,9 @@ class ChatControl(ChatControlBase): xep0184_id=xep0184_id, xhtml=xhtml, displaymarking=displaymarking) ChatControlBase.send_message(self, message, keyID, type_='chat', - chatstate=chatstate_to_send, composing_xep=composing_xep, - xhtml=xhtml, callback=_on_sent, - callback_args=[contact, message, encrypted, xhtml, self.get_seclabel()], - process_commands=process_commands) + chatstate=chatstate_to_send, xhtml=xhtml, callback=_on_sent, + callback_args=[contact, message, encrypted, xhtml, + self.get_seclabel()], process_commands=process_commands) def on_message_sent(self, account_and_message): @@ -2598,7 +2571,7 @@ class ChatControl(ChatControlBase): if contact.show == 'offline': return - if contact.composing_xep is False: # jid cannot do xep85 nor xep22 + if not contact.supports(NS_CHATSTATES): return # if the new state we wanna send (state) equals @@ -2606,28 +2579,7 @@ class ChatControl(ChatControlBase): if contact.our_chatstate == state: return - if contact.composing_xep is None: - # we don't know anything about jid, so return - # NOTE: - # send 'active', set current state to 'ask' and return is done - # in self.send_message() because we need REAL message (with
) - # for that procedure so return to make sure we send only once - # 'active' until we know peer supports jep85 - return - - if contact.our_chatstate == 'ask': - return - - # in JEP22, when we already sent stop composing - # notification on paused, don't resend it - if contact.composing_xep == 'XEP-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 - - # if we're inactive prevent composing (JEP violation) + # if wel're inactive prevent composing (XEP violation) if contact.our_chatstate == 'inactive' and state == 'composing': # go active before gajim.nec.push_outgoing_event(MessageOutgoingEvent(None, @@ -2638,11 +2590,10 @@ class ChatControl(ChatControlBase): gajim.nec.push_outgoing_event(MessageOutgoingEvent(None, account=self.account, jid=self.contact.jid, chatstate=state, - msg_id=contact.msg_id, composing_xep=contact.composing_xep, - control=self)) + msg_id=contact.msg_id, control=self)) contact.our_chatstate = state - if contact.our_chatstate == 'active': + if state == 'active': self.reset_kbd_mouse_timeout_vars() def shutdown(self): diff --git a/src/common/connection.py b/src/common/connection.py index edda989b6..d9998181b 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -248,9 +248,9 @@ class CommonConnection: raise NotImplementedError def _prepare_message(self, jid, msg, keyID, type_='chat', subject='', - chatstate=None, msg_id=None, composing_xep=None, resource=None, - user_nick=None, xhtml=None, session=None, forward_from=None, form_node=None, - label=None, original_message=None, delayed=None, callback=None): + chatstate=None, msg_id=None, resource=None, user_nick=None, xhtml=None, + session=None, forward_from=None, form_node=None, label=None, + original_message=None, delayed=None, callback=None): if not self.connection or self.connected < 2: return 1 try: @@ -299,35 +299,34 @@ class CommonConnection: self._message_encrypted_cb(output, type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, subject, chatstate, msg_id, - composing_xep, label, forward_from, delayed, - session, form_node, user_nick, keyID, - callback) + label, forward_from, delayed, session, + form_node, user_nick, keyID, callback) gajim.nec.push_incoming_event(GPGTrustKeyEvent(None, conn=self, callback=_on_always_trust)) else: self._message_encrypted_cb(output, type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, - subject, chatstate, msg_id, composing_xep, label, - forward_from, delayed, session, form_node, - user_nick, keyID, callback) + subject, chatstate, msg_id, label, forward_from, + delayed, session, form_node, user_nick, keyID, + callback) gajim.thread_interface(encrypt_thread, [msg, keyID, False], - _on_encrypted, []) + _on_encrypted, []) return self._message_encrypted_cb(('', error), type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, subject, - chatstate, msg_id, composing_xep, label, forward_from, delayed, - session, form_node, user_nick, keyID, callback) + chatstate, msg_id, label, forward_from, delayed, session, + form_node, user_nick, keyID, callback) self._on_continue_message(type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, subject, msgenc, keyID, chatstate, msg_id, - composing_xep, label, forward_from, delayed, session, form_node, - user_nick, callback) + label, forward_from, delayed, session, form_node, user_nick, + callback) def _message_encrypted_cb(self, output, type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, subject, chatstate, msg_id, - composing_xep, label, forward_from, delayed, session, form_node, user_nick, - keyID, callback): + label, forward_from, delayed, session, form_node, user_nick, keyID, + callback): msgenc, error = output if msgenc and not error: @@ -339,8 +338,8 @@ class CommonConnection: ' (' + msgtxt + ')' self._on_continue_message(type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, subject, msgenc, keyID, - chatstate, msg_id, composing_xep, label, forward_from, delayed, - session, form_node, user_nick, callback) + chatstate, msg_id, label, forward_from, delayed, session, + form_node, user_nick, callback) return # Encryption failed, do not send message tim = localtime() @@ -349,8 +348,7 @@ class CommonConnection: def _on_continue_message(self, type_, msg, msgtxt, original_message, fjid, resource, jid, xhtml, subject, msgenc, keyID, chatstate, msg_id, - composing_xep, label, forward_from, delayed, session, form_node, user_nick, - callback): + label, forward_from, delayed, session, form_node, user_nick, callback): if type_ == 'chat': msg_iq = common.xmpp.Message(to=fjid, body=msgtxt, typ=type_, xhtml=xhtml) @@ -386,27 +384,17 @@ class CommonConnection: contact = gajim.contacts.get_contact_with_highest_priority(self.name, jid) - # chatstates - if peer supports xep85 or xep22, send chatstates - # please note that the only valid tag inside a message containing a - # tag is the active event - if chatstate is not None and contact: - if ((composing_xep == 'XEP-0085' or not composing_xep) \ - and composing_xep != 'asked_once') or \ - contact.supports(common.xmpp.NS_CHATSTATES): - # XEP-0085 - msg_iq.setTag(chatstate, namespace=common.xmpp.NS_CHATSTATES) - if composing_xep in ('XEP-0022', 'asked_once') or \ - not composing_xep: - # XEP-0022 - chatstate_node = msg_iq.setTag('x', namespace=common.xmpp.NS_EVENT) - if chatstate is 'composing' or msgtxt: - chatstate_node.addChild(name='composing') + # chatstates - if peer supports xep85, send chatstates + # please note that the only valid tag inside a message containing a + # tag is the active event + if chatstate and contact and contact.supports(NS_CHATSTATES): + msg_iq.setTag(chatstate, namespace=NS_CHATSTATES) if forward_from: addresses = msg_iq.addChild('addresses', - namespace=common.xmpp.NS_ADDRESS) + namespace=common.xmpp.NS_ADDRESS) addresses.addChild('address', attrs = {'type': 'ofrom', - 'jid': forward_from}) + 'jid': forward_from}) # XEP-0203 if delayed: @@ -433,7 +421,7 @@ class CommonConnection: if callback: callback(jid, msg, keyID, forward_from, session, original_message, - subject, type_, msg_iq, xhtml) + subject, type_, msg_iq, xhtml) def log_message(self, jid, msg, forward_from, session, original_message, subject, type_, xhtml=None): @@ -717,9 +705,9 @@ class Connection(CommonConnection, ConnectionHandlers): self.privacy_rules_requested = False self.streamError = '' self.secret_hmac = str(random.random())[2:] - - self.sm = Smacks(self) # Stream Management - + + self.sm = Smacks(self) # Stream Management + gajim.ged.register_event_handler('privacy-list-received', ged.CORE, self._nec_privacy_list_received) gajim.ged.register_event_handler('agent-info-error-received', ged.CORE, @@ -1791,10 +1779,10 @@ class Connection(CommonConnection, ConnectionHandlers): self.connection.send(msg_iq) def send_message(self, jid, msg, keyID=None, type_='chat', subject='', - chatstate=None, msg_id=None, composing_xep=None, resource=None, - user_nick=None, xhtml=None, label=None, session=None, forward_from=None, - form_node=None, original_message=None, delayed=None, callback=None, - callback_args=[], now=False): + chatstate=None, msg_id=None, resource=None, user_nick=None, xhtml=None, + label=None, session=None, forward_from=None, form_node=None, + original_message=None, delayed=None, callback=None, callback_args=[], + now=False): def cb(jid, msg, keyID, forward_from, session, original_message, subject, type_, msg_iq, xhtml): @@ -1809,9 +1797,9 @@ class Connection(CommonConnection, ConnectionHandlers): subject, type_, xhtml) self._prepare_message(jid, msg, keyID, type_=type_, subject=subject, - chatstate=chatstate, msg_id=msg_id, composing_xep=composing_xep, - resource=resource, user_nick=user_nick, xhtml=xhtml, label=label, - session=session, forward_from=forward_from, form_node=form_node, + chatstate=chatstate, msg_id=msg_id, resource=resource, + user_nick=user_nick, xhtml=xhtml, label=label, session=session, + forward_from=forward_from, form_node=form_node, original_message=original_message, delayed=delayed, callback=cb) def _nec_message_outgoing(self, obj): @@ -1834,9 +1822,8 @@ class Connection(CommonConnection, ConnectionHandlers): self._prepare_message(obj.jid, obj.message, obj.keyID, type_=obj.type_, subject=obj.subject, chatstate=obj.chatstate, msg_id=obj.msg_id, - composing_xep=obj.composing_xep, resource=obj.resource, - user_nick=obj.user_nick, xhtml=obj.xhtml, label=obj.label, - session=obj.session, forward_from=obj.forward_from, + resource=obj.resource, user_nick=obj.user_nick, xhtml=obj.xhtml, + label=obj.label, session=obj.session, forward_from=obj.forward_from, form_node=obj.form_node, original_message=obj.original_message, delayed=obj.delayed, callback=cb) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index d44be1e30..482a2edae 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -907,8 +907,7 @@ class ConnectionHandlersBase: # reset chatstate if needed: # (when contact signs out or has errors) if obj.show in ('offline', 'error'): - obj.contact.our_chatstate = obj.contact.chatstate = \ - obj.contact.composing_xep = None + obj.contact.our_chatstate = obj.contact.chatstate = None # TODO: This causes problems when another # resource signs off! diff --git a/src/common/connection_handlers_events.py b/src/common/connection_handlers_events.py index 3e691b1b9..b7b8cb9d3 100644 --- a/src/common/connection_handlers_events.py +++ b/src/common/connection_handlers_events.py @@ -35,6 +35,7 @@ from common import exceptions from common.zeroconf import zeroconf from common.logger import LOG_DB_PATH from common.pep import SUPPORTED_PERSONAL_USER_EVENTS +from common.xmpp.protocol import NS_CHATSTATES import gtkgui_helpers @@ -74,28 +75,16 @@ class HelperEvent: Extract chatstate from a