[misc] repare sending composing chatstates using xep instead of xep.

Fix #3241.
This commit is contained in:
Julien Pivotto 2007-06-16 21:31:19 +00:00
parent 3606de3b67
commit c92145c3b9
7 changed files with 41 additions and 41 deletions

View File

@ -502,7 +502,7 @@ class ChatControlBase(MessageControl):
return False return False
def send_message(self, message, keyID = '', type = 'chat', chatstate = None, def send_message(self, message, keyID = '', type = 'chat', chatstate = None,
msg_id = None, composing_jep = None, resource = None): msg_id = None, composing_xep = None, resource = None):
'''Send the given message to the active tab. Doesn't return None if error '''Send the given message to the active tab. Doesn't return None if error
''' '''
if not message or message == '\n': if not message or message == '\n':
@ -512,7 +512,7 @@ class ChatControlBase(MessageControl):
if not self._process_command(message): if not self._process_command(message):
ret = MessageControl.send_message(self, message, keyID, type = type, ret = MessageControl.send_message(self, message, keyID, type = type,
chatstate = chatstate, msg_id = msg_id, chatstate = chatstate, msg_id = msg_id,
composing_jep = composing_jep, resource = resource, composing_xep = composing_xep, resource = resource,
user_nick = self.user_nick) user_nick = self.user_nick)
if ret: if ret:
return ret return ret
@ -1117,12 +1117,12 @@ class ChatControl(ChatControlBase):
if cs and st in ('composing_only', 'all'): if cs and st in ('composing_only', 'all'):
if contact.show == 'offline': if contact.show == 'offline':
chatstate = '' chatstate = ''
elif contact.composing_jep == 'JEP-0085': elif contact.composing_xep == 'XEP-0085':
if st == 'all' or cs == 'composing': if st == 'all' or cs == 'composing':
chatstate = helpers.get_uf_chatstate(cs) chatstate = helpers.get_uf_chatstate(cs)
else: else:
chatstate = '' chatstate = ''
elif contact.composing_jep == 'JEP-0022': elif contact.composing_xep == 'XEP-0022':
if cs in ('composing', 'paused'): if cs in ('composing', 'paused'):
# only print composing, paused # only print composing, paused
chatstate = helpers.get_uf_chatstate(cs) chatstate = helpers.get_uf_chatstate(cs)
@ -1255,10 +1255,10 @@ class ChatControl(ChatControlBase):
chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \ chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \
'disabled' 'disabled'
composing_jep = contact.composing_jep composing_xep = contact.composing_xep
chatstate_to_send = None chatstate_to_send = None
if chatstates_on and contact is not None: if chatstates_on and contact is not None:
if composing_jep is None: if composing_xep is None:
# no info about peer # no info about peer
# send active to discover chat state capabilities # send active to discover chat state capabilities
# this is here (and not in send_chatstate) # this is here (and not in send_chatstate)
@ -1267,13 +1267,13 @@ class ChatControl(ChatControlBase):
if contact.our_chatstate: if contact.our_chatstate:
# We already asked for xep 85, don't ask it twice # We already asked for xep 85, don't ask it twice
composing_jep = 'asked_once' composing_xep = 'asked_once'
chatstate_to_send = 'active' chatstate_to_send = 'active'
contact.our_chatstate = 'ask' # pseudo state contact.our_chatstate = 'ask' # pseudo state
# if peer supports jep85 and we are not 'ask', send 'active' # if peer supports jep85 and we are not 'ask', send 'active'
# NOTE: first active and 'ask' is set in gajim.py # NOTE: first active and 'ask' is set in gajim.py
elif composing_jep is not False: elif composing_xep is not False:
#send active chatstate on every message (as JEP says) #send active chatstate on every message (as JEP says)
chatstate_to_send = 'active' chatstate_to_send = 'active'
contact.our_chatstate = 'active' contact.our_chatstate = 'active'
@ -1283,7 +1283,7 @@ class ChatControl(ChatControlBase):
self._schedule_activity_timers() self._schedule_activity_timers()
if not ChatControlBase.send_message(self, message, keyID, type = 'chat', if not ChatControlBase.send_message(self, message, keyID, type = 'chat',
chatstate = chatstate_to_send, composing_jep = composing_jep): chatstate = chatstate_to_send, composing_xep = composing_xep):
self.print_conversation(message, self.contact.jid, self.print_conversation(message, self.contact.jid,
encrypted = encrypted) encrypted = encrypted)
@ -1579,7 +1579,7 @@ class ChatControl(ChatControlBase):
if contact.show == 'offline': if contact.show == 'offline':
return return
if contact.composing_jep is False: # jid cannot do jep85 nor jep22 if contact.composing_xep is False: # jid cannot do xep85 nor xep22
return return
# if the new state we wanna send (state) equals # if the new state we wanna send (state) equals
@ -1587,7 +1587,7 @@ class ChatControl(ChatControlBase):
if contact.our_chatstate == state: if contact.our_chatstate == state:
return return
if contact.composing_jep is None: if contact.composing_xep is None:
# we don't know anything about jid, so return # we don't know anything about jid, so return
# NOTE: # NOTE:
# send 'active', set current state to 'ask' and return is done # send 'active', set current state to 'ask' and return is done
@ -1601,7 +1601,7 @@ class ChatControl(ChatControlBase):
# in JEP22, when we already sent stop composing # in JEP22, when we already sent stop composing
# notification on paused, don't resend it # notification on paused, don't resend it
if contact.composing_jep == 'JEP-0022' and \ if contact.composing_xep == 'XEP-0022' and \
contact.our_chatstate in ('paused', 'active', 'inactive') and \ contact.our_chatstate in ('paused', 'active', 'inactive') and \
state is not 'composing': # not composing == in (active, inactive, gone) state is not 'composing': # not composing == in (active, inactive, gone)
contact.our_chatstate = 'active' contact.our_chatstate = 'active'
@ -1623,7 +1623,7 @@ class ChatControl(ChatControlBase):
self.reset_kbd_mouse_timeout_vars() 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) msg_id = contact.msg_id, composing_xep = contact.composing_xep)
contact.our_chatstate = state contact.our_chatstate = state
if contact.our_chatstate == 'active': if contact.our_chatstate == 'active':
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()

View File

@ -807,7 +807,7 @@ class Connection(ConnectionHandlers):
self.connection.send(msg_iq) self.connection.send(msg_iq)
def send_message(self, jid, msg, keyID, type = 'chat', subject='', def send_message(self, jid, msg, keyID, type = 'chat', subject='',
chatstate = None, msg_id = None, composing_jep = None, resource = None, chatstate = None, msg_id = None, composing_xep = None, resource = None,
user_nick = None, xhtml = None): user_nick = None, xhtml = None):
if not self.connection: if not self.connection:
return 1 return 1
@ -861,12 +861,12 @@ class Connection(ConnectionHandlers):
# please note that the only valid tag inside a message containing a <body> # please note that the only valid tag inside a message containing a <body>
# tag is the active event # tag is the active event
if chatstate is not None: if chatstate is not None:
if (composing_jep == 'JEP-0085' or not composing_jep) and \ if (composing_xep == 'XEP-0085' or not composing_xep) and \
composing_jep != 'asked_once': composing_xep != 'asked_once':
# JEP-0085 # XEP-0085
msg_iq.setTag(chatstate, namespace = common.xmpp.NS_CHATSTATES) msg_iq.setTag(chatstate, namespace = common.xmpp.NS_CHATSTATES)
if composing_jep in ('JEP-0022', 'asked_once') or not composing_jep: if composing_xep in ('XEP-0022', 'asked_once') or not composing_xep:
# JEP-0022 # XEP-0022
chatstate_node = msg_iq.setTag('x', chatstate_node = msg_iq.setTag('x',
namespace = common.xmpp.NS_EVENT) namespace = common.xmpp.NS_EVENT)
if not msgtxt: # when no <body>, add <id> if not msgtxt: # when no <body>, add <id>

View File

@ -20,7 +20,7 @@ class Contact:
'''Information concerning each contact''' '''Information concerning each contact'''
def __init__(self, jid='', name='', groups=[], show='', status='', sub='', def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=0, keyID='', our_chatstate=None, ask='', resource='', priority=0, keyID='', our_chatstate=None,
chatstate=None, last_status_time=None, msg_id = None, composing_jep = None): chatstate=None, last_status_time=None, msg_id = None, composing_xep = None):
self.jid = jid self.jid = jid
self.name = name self.name = name
self.contact_name = '' # nick choosen by contact self.contact_name = '' # nick choosen by contact
@ -43,9 +43,9 @@ class Contact:
self.our_chatstate = our_chatstate self.our_chatstate = our_chatstate
self.msg_id = msg_id self.msg_id = msg_id
# tell which JEP we're using for composing state # tell which JEP we're using for composing state
# None = have to ask, JEP-0022 = use this jep, # None = have to ask, XEP-0022 = use this jep,
# JEP-0085 = use this jep, False = no composing support # XEP-0085 = use this jep, False = no composing support
self.composing_jep = composing_jep self.composing_xep = composing_xep
# this is contact's chatstate # this is contact's chatstate
self.chatstate = chatstate self.chatstate = chatstate
self.last_status_time = last_status_time self.last_status_time = last_status_time
@ -149,10 +149,10 @@ class Contacts:
def create_contact(self, jid='', name='', groups=[], show='', status='', def create_contact(self, jid='', name='', groups=[], show='', status='',
sub='', ask='', resource='', priority=0, keyID='', our_chatstate=None, sub='', ask='', resource='', priority=0, keyID='', our_chatstate=None,
chatstate=None, last_status_time=None, composing_jep=None): chatstate=None, last_status_time=None, composing_xep=None):
return Contact(jid, name, groups, show, status, sub, ask, resource, return Contact(jid, name, groups, show, status, sub, ask, resource,
priority, keyID, our_chatstate, chatstate, last_status_time, priority, keyID, our_chatstate, chatstate, last_status_time,
composing_jep) composing_xep)
def copy_contact(self, contact): def copy_contact(self, contact):
return self.create_contact(jid = contact.jid, name = contact.name, return self.create_contact(jid = contact.jid, name = contact.name,

View File

@ -663,23 +663,23 @@ class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream):
invite = None invite = None
delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None
msg_id = None msg_id = None
composing_jep = None composing_xep = None
xtags = msg.getTags('x') xtags = msg.getTags('x')
# chatstates - look for chatstate tags in a message if not delayed # chatstates - look for chatstate tags in a message if not delayed
if not delayed: if not delayed:
composing_jep = False composing_xep = False
children = msg.getChildren() children = msg.getChildren()
for child in children: for child in children:
if child.getNamespace() == 'http://jabber.org/protocol/chatstates': if child.getNamespace() == 'http://jabber.org/protocol/chatstates':
chatstate = child.getName() chatstate = child.getName()
composing_jep = 'JEP-0085' composing_xep = 'XEP-0085'
break break
# No JEP-0085 support, fallback to JEP-0022 # No JEP-0085 support, fallback to JEP-0022
if not chatstate: if not chatstate:
chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT) chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT)
if chatstate_child: if chatstate_child:
chatstate = 'active' chatstate = 'active'
composing_jep = 'JEP-0022' composing_xep = 'XEP-0022'
if not msgtxt and chatstate_child.getTag('composing'): if not msgtxt and chatstate_child.getTag('composing'):
chatstate = 'composing' chatstate = 'composing'
# JEP-0172 User Nickname # JEP-0172 User Nickname
@ -715,14 +715,14 @@ class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream):
msg_id = gajim.logger.write('chat_msg_recv', frm, msgtxt, tim = tim, msg_id = gajim.logger.write('chat_msg_recv', frm, msgtxt, tim = tim,
subject = subject) subject = subject)
self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject, self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, subject,
chatstate, msg_id, composing_jep, user_nick, msghtml)) chatstate, msg_id, composing_xep, user_nick, msghtml))
elif mtype == 'normal': # it's single message elif mtype == 'normal': # it's single message
if self.name not in no_log_for and jid not in no_log_for and msgtxt: if self.name not in no_log_for and jid not in no_log_for and msgtxt:
gajim.logger.write('single_msg_recv', frm, msgtxt, tim = tim, gajim.logger.write('single_msg_recv', frm, msgtxt, tim = tim,
subject = subject) subject = subject)
if invite: if invite:
self.dispatch('MSG', (frm, msgtxt, tim, encrypted, 'normal', self.dispatch('MSG', (frm, msgtxt, tim, encrypted, 'normal',
subject, chatstate, msg_id, composing_jep, user_nick)) subject, chatstate, msg_id, composing_xep, user_nick))
# END messageCB # END messageCB
def parse_data_form(self, node): def parse_data_form(self, node):

View File

@ -348,7 +348,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
return STATUS_LIST[self.connected] return STATUS_LIST[self.connected]
def send_message(self, jid, msg, keyID, type = 'chat', subject='', def send_message(self, jid, msg, keyID, type = 'chat', subject='',
chatstate = None, msg_id = None, composing_jep = None, resource = None, chatstate = None, msg_id = None, composing_xep = None, resource = None,
user_nick = None): user_nick = None):
fjid = jid fjid = jid
@ -396,10 +396,10 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
# please note that the only valid tag inside a message containing a <body> # please note that the only valid tag inside a message containing a <body>
# tag is the active event # tag is the active event
if chatstate is not None: if chatstate is not None:
if composing_jep == 'JEP-0085' or not composing_jep: if composing_xep == 'XEP-0085' or not composing_xep:
# JEP-0085 # JEP-0085
msg_iq.setTag(chatstate, namespace = common.xmpp.NS_CHATSTATES) msg_iq.setTag(chatstate, namespace = common.xmpp.NS_CHATSTATES)
if composing_jep == 'JEP-0022' or not composing_jep: if composing_xep == 'XEP-0022' or not composing_xep:
# JEP-0022 # JEP-0022
chatstate_node = msg_iq.setTag('x', namespace = common.xmpp.NS_EVENT) chatstate_node = msg_iq.setTag('x', namespace = common.xmpp.NS_EVENT)
if not msgtxt: # when no <body>, add <id> if not msgtxt: # when no <body>, add <id>

View File

@ -641,7 +641,7 @@ class Interface:
# (when contact signs out or has errors) # (when contact signs out or has errors)
if array[1] in ('offline', 'error'): if array[1] in ('offline', 'error'):
contact1.our_chatstate = contact1.chatstate = \ contact1.our_chatstate = contact1.chatstate = \
contact1.composing_jep = None contact1.composing_xep = None
gajim.connections[account].remove_transfers_for_contact(contact1) gajim.connections[account].remove_transfers_for_contact(contact1)
self.roster.chg_contact_status(contact1, array[1], status_message, self.roster.chg_contact_status(contact1, array[1], status_message,
account) account)
@ -670,7 +670,7 @@ class Interface:
def handle_event_msg(self, account, array): def handle_event_msg(self, account, array):
# 'MSG' (account, (jid, msg, time, encrypted, msg_type, subject, # 'MSG' (account, (jid, msg, time, encrypted, msg_type, subject,
# chatstate, msg_id, composing_jep, user_nick, xhtml)) # chatstate, msg_id, composing_xep, user_nick, xhtml))
# user_nick is JEP-0172 # user_nick is JEP-0172
full_jid_with_resource = array[0] full_jid_with_resource = array[0]
@ -683,7 +683,7 @@ class Interface:
subject = array[5] subject = array[5]
chatstate = array[6] chatstate = array[6]
msg_id = array[7] msg_id = array[7]
composing_jep = array[8] composing_xep = array[8]
xhtml = array[10] xhtml = array[10]
if gajim.config.get('ignore_incoming_xhtml'): if gajim.config.get('ignore_incoming_xhtml'):
xhtml = None xhtml = None
@ -727,8 +727,8 @@ class Interface:
if contact and isinstance(contact, list): if contact and isinstance(contact, list):
contact = contact[0] contact = contact[0]
if contact: if contact:
if contact.composing_jep != 'JEP-0085': # We cache xep85 support if contact.composing_xep != 'XEP-0085': # We cache xep85 support
contact.composing_jep = composing_jep contact.composing_xep = composing_xep
if chat_control and chat_control.type_id == message_control.TYPE_CHAT: if chat_control and chat_control.type_id == message_control.TYPE_CHAT:
if chatstate is not None: if chatstate is not None:
# other peer sent us reply, so he supports jep85 or jep22 # other peer sent us reply, so he supports jep85 or jep22

View File

@ -111,7 +111,7 @@ class MessageControl:
return len(gajim.events.get_events(self.account, self.contact.jid)) return len(gajim.events.get_events(self.account, self.contact.jid))
def send_message(self, message, keyID = '', type = 'chat', def send_message(self, message, keyID = '', type = 'chat',
chatstate = None, msg_id = None, composing_jep = None, resource = None, chatstate = None, msg_id = None, composing_xep = None, resource = None,
user_nick = None): user_nick = None):
'''Send the given message to the active tab. Doesn't return None if error '''Send the given message to the active tab. Doesn't return None if error
''' '''
@ -119,5 +119,5 @@ class MessageControl:
# Send and update history # Send and update history
return gajim.connections[self.account].send_message(jid, message, keyID, return gajim.connections[self.account].send_message(jid, message, keyID,
type = type, chatstate = chatstate, msg_id = msg_id, type = type, chatstate = chatstate, msg_id = msg_id,
composing_jep = composing_jep, resource = self.resource, composing_xep = composing_xep, resource = self.resource,
user_nick = user_nick) user_nick = user_nick)