contact.chatstate becomes contact.our_chatstate

contact.chatstate is now contact's chatstate
This commit is contained in:
Yann Leboulanger 2005-11-22 00:28:36 +00:00
parent ca28ae33f3
commit 508d176d5a
2 changed files with 42 additions and 35 deletions

View file

@ -129,7 +129,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=5, keyID='', role='', affiliation='', ask='', resource='', priority=5, keyID='', role='', affiliation='',
chatstate=None): our_chatstate=None, chatstate=None):
self.jid = jid self.jid = jid
self.name = name self.name = name
self.groups = groups self.groups = groups
@ -149,7 +149,9 @@ class Contact:
# None if no info about peer # None if no info about peer
# False if peer does not support jep85 # False if peer does not support jep85
# 'ask' if we sent the first 'active' chatstate and are waiting for reply # 'ask' if we sent the first 'active' chatstate and are waiting for reply
# this holds what WE SEND to contact (the current chatstate) # this holds what WE SEND to contact (our current chatstate)
self.our_chatstate = our_chatstate
# this is contact's chatstate
self.chatstate = chatstate self.chatstate = chatstate
import roster_window import roster_window
@ -353,7 +355,7 @@ class Interface:
# reset chatstate if needed: # reset chatstate if needed:
# (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.chatstate = None contact1.our_chatstate = contact1.chatstate = None
self.roster.chg_contact_status(contact1, array[1], array[2], account) self.roster.chg_contact_status(contact1, array[1], array[2], account)
# play sound # play sound
if old_show < 2 and new_show > 1: if old_show < 2 and new_show > 1:
@ -402,7 +404,8 @@ 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, chatstate)) # ('MSG', account, (jid, msg, time, encrypted, msg_type, subject,
# chatstate))
jid = gajim.get_jid_without_resource(array[0]) jid = gajim.get_jid_without_resource(array[0])
resource = gajim.get_resource_from_jid(array[0]) resource = gajim.get_resource_from_jid(array[0])
msg_type = array[4] msg_type = array[4]
@ -439,17 +442,18 @@ class Interface:
if self.instances[account]['chats'].has_key(jid): if self.instances[account]['chats'].has_key(jid):
chat_win = self.instances[account]['chats'][jid] chat_win = self.instances[account]['chats'][jid]
if chatstate is not None: # he or she sent us reply, so he supports jep85 if chatstate is not None: # he or she sent us reply, so he supports jep85
if contact.chatstate == 'ask': # we were jep85 disco? contact.chatstate = chatstate
contact.chatstate = 'active' # no more if contact.our_chatstate == 'ask': # we were jep85 disco?
contact.our_chatstate = 'active' # no more
chat_win.handle_incoming_chatstate(account, jid, chatstate) chat_win.handle_incoming_chatstate(account, contact)
elif contact.chatstate != 'active': elif contact.chatstate != 'active':
# got no valid jep85 answer, peer does not support it # got no valid jep85 answer, peer does not support it
contact.chatstate = False contact.chatstate = False
else: elif contact and chatstate == 'active':
# Brand new message, incoming. # Brand new message, incoming.
if contact and chatstate == 'active': contact.our_chatstate = chatstate
contact.chatstate = chatstate contact.chatstate = chatstate
if not array[1]: #empty message text if not array[1]: #empty message text
return return

View file

@ -254,13 +254,13 @@ class TabbedChatWindow(chat.Chat):
st = gajim.config.get('chat_state_notifications') st = gajim.config.get('chat_state_notifications')
if chatstate and st in ('composing_only', 'all'): if contact.chatstate and st in ('composing_only', 'all'):
if st == 'all': if st == 'all':
chatstate = helpers.get_uf_chatstate(chatstate) chatstate = helpers.get_uf_chatstate(contact.chatstate)
else: # 'composing_only' else: # 'composing_only'
if chatstate in ('composing', 'paused'): if chatstate in ('composing', 'paused'):
# only print composing, paused # only print composing, paused
chatstate = helpers.get_uf_chatstate(chatstate) chatstate = helpers.get_uf_chatstate(contact.chatstate)
else: else:
chatstate = '' chatstate = ''
label_text = \ label_text = \
@ -389,6 +389,7 @@ class TabbedChatWindow(chat.Chat):
for jid in self.xmls: for jid in self.xmls:
self.send_chatstate('gone', jid) self.send_chatstate('gone', jid)
self.contacts[jid].chatstate = None self.contacts[jid].chatstate = None
self.contacts[jid].our_chatstate = None
#clean gajim.interface.instances[self.account]['chats'] #clean gajim.interface.instances[self.account]['chats']
chat.Chat.on_window_destroy(self, widget, 'chats') chat.Chat.on_window_destroy(self, widget, 'chats')
@ -435,6 +436,7 @@ class TabbedChatWindow(chat.Chat):
# chatstates - tab is destroyed, send gone and reset # chatstates - tab is destroyed, send gone and reset
self.send_chatstate('gone', jid) self.send_chatstate('gone', jid)
self.contacts[jid].chatstate = None self.contacts[jid].chatstate = None
self.contacts[jid].our_chatstate = None
chat.Chat.remove_tab(self, jid, 'chats') chat.Chat.remove_tab(self, jid, 'chats')
del self.contacts[jid] del self.contacts[jid]
@ -487,12 +489,11 @@ class TabbedChatWindow(chat.Chat):
self.possible_inactive_timeout_id[contact.jid] = gobject.timeout_add( self.possible_inactive_timeout_id[contact.jid] = gobject.timeout_add(
30000, self.check_for_possible_inactive_chatstate, contact.jid) 30000, self.check_for_possible_inactive_chatstate, contact.jid)
def handle_incoming_chatstate(self, account, jid, chatstate): def handle_incoming_chatstate(self, account, contact):
''' handle incoming chatstate that jid SENT TO us ''' ''' handle incoming chatstate that jid SENT TO us '''
contact = gajim.get_first_contact_instance_from_jid(account, jid) self.draw_name_banner(contact, contact.chatstate)
self.draw_name_banner(contact, chatstate)
# update chatstate in tab for this chat # update chatstate in tab for this chat
self.redraw_tab(contact.jid, chatstate) self.redraw_tab(contact.jid, contact.chatstate)
def check_for_possible_paused_chatstate(self, jid): def check_for_possible_paused_chatstate(self, jid):
''' did we move mouse of that window or write something in message ''' did we move mouse of that window or write something in message
@ -500,14 +501,15 @@ class TabbedChatWindow(chat.Chat):
in the last 5 seconds? in the last 5 seconds?
if yes we go active for mouse, composing for kbd if yes we go active for mouse, composing for kbd
if no we go paused if we were previously composing ''' if no we go paused if we were previously composing '''
print 'check for pause'
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
if jid not in self.xmls or contact is None: if jid not in self.xmls or contact is None:
# the tab with jid is no longer open or contact left # the tab with jid is no longer open or contact left
# stop timer # stop timer
return False # stop looping return False # stop looping
current_state = contact.chatstate current_state = contact.our_chatstate
print 'current_state', current_state
if current_state is False: # jid doesn't support chatstates if current_state is False: # jid doesn't support chatstates
return False # stop looping return False # stop looping
@ -533,12 +535,13 @@ class TabbedChatWindow(chat.Chat):
in the last 30 seconds? in the last 30 seconds?
if yes we go active if yes we go active
if no we go inactive ''' if no we go inactive '''
print 'check for inactive'
contact = gajim.get_first_contact_instance_from_jid(self.account, jid) contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
if jid not in self.xmls or contact is None: if jid not in self.xmls or contact is None:
# the tab with jid is no longer open or contact left # the tab with jid is no longer open or contact left
return False # stop looping return False # stop looping
current_state = contact.chatstate current_state = contact.our_chatstate
if current_state is False: # jid doesn't support chatstates if current_state is False: # jid doesn't support chatstates
return False # stop looping return False # stop looping
@ -672,15 +675,15 @@ class TabbedChatWindow(chat.Chat):
if contact.show == 'offline': if contact.show == 'offline':
return return
if contact.chatstate is False: # jid cannot do jep85 if contact.our_chatstate is False: # jid cannot do jep85
return return
# if the new state we wanna send (state) equals # if the new state we wanna send (state) equals
# the current state (contact.chastate) then return # the current state (contact.our_chatstate) then return
if contact.chatstate == state: if contact.our_chatstate == state:
return return
if contact.chatstate is None: if contact.our_chatstate 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
@ -689,27 +692,27 @@ class TabbedChatWindow(chat.Chat):
# 'active' until we know peer supports jep85 # 'active' until we know peer supports jep85
return return
if contact.chatstate == 'ask': if contact.our_chatstate == 'ask':
return return
# prevent going paused if we we were not composing (JEP violation) # prevent going paused if we we were not composing (JEP violation)
if state == 'paused' and not contact.chatstate == 'composing': if state == 'paused' and not contact.our_chatstate == 'composing':
gajim.connections[self.account].send_message(jid, None, None, gajim.connections[self.account].send_message(jid, None, None,
chatstate = 'active') # go active before chatstate = 'active') # go active before
contact.chatstate = 'active' contact.our_chatstate = 'active'
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
# if we're inactive prevent composing (JEP violation) # if we're inactive prevent composing (JEP violation)
if contact.chatstate == 'inactive' and state == 'composing': if contact.our_chatstate == 'inactive' and state == 'composing':
gajim.connections[self.account].send_message(jid, None, None, gajim.connections[self.account].send_message(jid, None, None,
chatstate = 'active') # go active before chatstate = 'active') # go active before
contact.chatstate = 'active' contact.our_chatstate = 'active'
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
gajim.connections[self.account].send_message(jid, None, None, gajim.connections[self.account].send_message(jid, None, None,
chatstate = state) chatstate = state)
contact.chatstate = state contact.our_chatstate = state
if contact.chatstate == 'active': if contact.our_chatstate == 'active':
self.reset_kbd_mouse_timeout_vars() self.reset_kbd_mouse_timeout_vars()
def send_message(self, message): def send_message(self, message):
@ -754,21 +757,21 @@ class TabbedChatWindow(chat.Chat):
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 contact.chatstate is None: if contact.our_chatstate 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)
# because we want it sent with REAL message # because we want it sent with REAL message
# (not standlone) eg. one that has body # (not standlone) eg. one that has body
chatstate_to_send = 'active' chatstate_to_send = 'active'
contact.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 contact.chatstate not in (False, 'ask'): elif contact.our_chatstate not in (False, 'ask'):
#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.chatstate = 'active' contact.our_chatstate = 'active'
# refresh timers # refresh timers
# avoid sending composing in less than 5 seconds # avoid sending composing in less than 5 seconds