we now have contact.chatstate !

This commit is contained in:
Nikos Kouremenos 2005-07-22 00:34:08 +00:00
parent 549b10369e
commit 9fc1516522
5 changed files with 48 additions and 38 deletions

View File

@ -901,7 +901,8 @@ class Connection:
# chatstates - if peer supports jep85, send chatstates # chatstates - if peer supports jep85, send chatstates
# please note that the only valid tag inside a message containing a <body> tag is the active event # please note that the only valid tag inside a message containing a <body> tag is the active event
if chatstate is not None: if chatstate is not None:
msg_iq.setTag(chatstate, {}, namespace='http://jabber.org/protocol/chatstates') msg_iq.setTag(chatstate, {},
namespace = 'http://jabber.org/protocol/chatstates')
self.to_be_sent.append(msg_iq) self.to_be_sent.append(msg_iq)
gajim.logger.write('outgoing', msg, jid) gajim.logger.write('outgoing', msg, jid)

View File

@ -63,13 +63,13 @@ sleeper_state = {} # whether we pass auto away / xa or not
def get_contact_instances_from_jid(account, jid): def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid ''' ''' we may have two or more resources on that jid '''
contact_instances = gajim.contacts[account][jid] return contacts[account][jid]
return contact_instances
def get_first_contact_instance_from_jid(account, jid): def get_first_contact_instance_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid) return contacts[account][jid][0]
return contact_instances[0]
def get_contact_name_from_jid(account, jid): def get_contact_name_from_jid(account, jid):
contact_instances = get_contact_instances_from_jid(account, jid) return contacts[account][jid][0].name
return contact_instances[0].name
def get_jid_without_resource(jid):
return jid.split('/')[0]

View File

@ -58,7 +58,7 @@ def get_fjid_from_nick(room_jid, nick):
return fjid return fjid
def get_nick_from_jid(jid): def get_nick_from_jid(jid):
pos = jid.rfind('/') pos = jid.find('@')
return jid[:pos] return jid[:pos]
def get_nick_from_fjid(jid): def get_nick_from_fjid(jid):

View File

@ -91,8 +91,9 @@ except ImportError:
class Contact: 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):
self.jid = jid self.jid = jid
self.name = name self.name = name
self.groups = groups self.groups = groups
@ -106,6 +107,14 @@ class Contact:
self.role = role self.role = role
self.affiliation = affiliation self.affiliation = affiliation
# please read jep-85 http://www.jabber.org/jeps/jep-0085.html
# we keep track of jep85 support by the peer by three extra states:
# None, False and 'ask'
# None if no info about peer
# False if peer does not support jep85
# 'ask' if we sent the first 'active' chatstate and are waiting for reply
self.chatstate = chatstate
import roster_window import roster_window
import systray import systray
import dialogs import dialogs
@ -347,8 +356,8 @@ class Interface:
self.remote.raise_signal('GCPresence', (account, array)) self.remote.raise_signal('GCPresence', (account, array))
def handle_event_msg(self, account, array): def handle_event_msg(self, account, array):
#('MSG', account, (contact, msg, time, encrypted, msg_type, subject, chatstate)) #('MSG', account, (jid, msg, time, encrypted, msg_type, subject, chatstate))
jid = array[0].split('/')[0] jid = gajim.get_jid_without_resource(array[0])
msg_type = array[4] msg_type = array[4]
chatstate = array[6] chatstate = array[6]
if jid.find('@') <= 0: if jid.find('@') <= 0:
@ -379,16 +388,17 @@ class Interface:
if self.windows[account]['chats'].has_key(jid): if self.windows[account]['chats'].has_key(jid):
chat_win = self.windows[account]['chats'][jid] chat_win = self.windows[account]['chats'][jid]
contact = gajim.get_first_contact_instance_from_jid(account, jid)
if chatstate is not None: # he sent us reply, so he supports jep85 if chatstate is not None: # he sent us reply, so he supports jep85
if chat_win.chatstates[jid] == 'ask': # we were jep85 disco? if contact.chatstate == 'ask': # we were jep85 disco?
chat_win.chatstates[jid] = 'active' # no more contact.chatstate = 'active' # no more
chat_win.handle_incoming_chatstate(account, jid, chatstate) chat_win.handle_incoming_chatstate(account, jid, chatstate)
else: else:
# got no valid jep85 answer, peer does not support it # got no valid jep85 answer, peer does not support it
chat_win.chatstates[jid] = False contact.chatstate = False
if not array[1]: #empty message if not array[1]: #empty message text
return return
first = False first = False
@ -491,10 +501,10 @@ class Interface:
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid = jid, name = jid.split('@')[0], contact1 = Contact(jid = jid, name = jid.split('@')[0],
groups = [_('General')], show = 'online', status = 'online', groups = [_('General')], show = 'online', status = 'online',
ask = 'to', resource = array[1], keyID = keyID) ask = 'to', resource = array[1], keyID = keyID)
gajim.contacts[account][jid] = [user1] gajim.contacts[account][jid] = [contact1]
self.roster.add_contact_to_roster(jid, account) self.roster.add_contact_to_roster(jid, account)
dialogs.InformationDialog(_('Authorization accepted'), dialogs.InformationDialog(_('Authorization accepted'),
_('The contact "%s" has authorized you to see his status.') _('The contact "%s" has authorized you to see his status.')

View File

@ -454,13 +454,6 @@ class TabbedChatWindow(chat.Chat):
''' sends our chatstate as STANDLONE chat state message (eg. no body) ''' sends our chatstate as STANDLONE chat state message (eg. no body)
to the current tab only if new chatstate is different to the current tab only if new chatstate is different
from the previous one''' from the previous one'''
# please read jep-85 http://www.jabber.org/jeps/jep-0085.html
# we keep track of jep85 support by the peer by three extra states:
# None, False and 'ask'
# None if no info about peer
# False if peer does not support jep85
# 'ask' if we sent the first 'active' chatstate and are waiting for reply
# JEP 85 does not allow resending the same chatstate # JEP 85 does not allow resending the same chatstate
# this function checks for that and just returns so it's safe to call it # this function checks for that and just returns so it's safe to call it
# with same state. # with same state.
@ -476,16 +469,17 @@ class TabbedChatWindow(chat.Chat):
return return
jid = self.get_active_jid() jid = self.get_active_jid()
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
if self.chatstates[jid] == False: # jid cannot do jep85 if contact.chatstate is False: # jid cannot do jep85
return return
# if current state equals previous state, return # if current state equals previous state, return
if self.chatstates[jid] == state: if contact.chatstate == state:
return return
if self.chatstates[jid] is None: if contact.chatstate is None:
# we don't know anything about jid, # 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
# in send_message because we need REAL message (with <body>) # in send_message because we need REAL message (with <body>)
@ -493,20 +487,20 @@ class TabbedChatWindow(chat.Chat):
# until we know peer supports jep85 # until we know peer supports jep85
return return
if self.chatstates[jid] == 'ask': if contact.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 self.chatstates[jid] == 'composing': if state == 'paused' and not contact.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
# if we're inactive prevent composing (JEP violation) # if we're inactive prevent composing (JEP violation)
if self.chatstates[jid] == 'inactive' and state == 'composing': if contact.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
self.chatstates[jid] = state contact.chatstate = state
gajim.connections[self.account].send_message(jid, None, None, gajim.connections[self.account].send_message(jid, None, None,
chatstate = state) chatstate = state)
@ -514,10 +508,13 @@ class TabbedChatWindow(chat.Chat):
"""Send the given message to the active tab""" """Send the given message to the active tab"""
if not message: if not message:
return return
jid = self.get_active_jid() jid = self.get_active_jid()
contact = gajim.get_first_contact_instance_from_jid(self.account, jid)
conversation_textview = self.xmls[jid].get_widget('conversation_textview') conversation_textview = self.xmls[jid].get_widget('conversation_textview')
message_textview = self.xmls[jid].get_widget('message_textview') message_textview = self.xmls[jid].get_widget('message_textview')
message_buffer = message_textview.get_buffer() message_buffer = message_textview.get_buffer()
if message != '' or message != '\n': if message != '' or message != '\n':
self.save_sent_message(jid, message) self.save_sent_message(jid, message)
if message == '/clear': if message == '/clear':
@ -534,21 +531,23 @@ class TabbedChatWindow(chat.Chat):
keyID = self.contacts[jid].keyID keyID = self.contacts[jid].keyID
encrypted = True encrypted = True
notif_on = gajim.config.get('send_receive_chat_state_notifications') chatstates_on = gajim.config.get(
'send_receive_chat_state_notifications')
chatstate_to_send = None chatstate_to_send = None
if notif_on: # if we have them one
if self.chatstates[jid] is None: if chatstates_on: # if we have them one
if contact.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'
self.chatstates[jid] = 'ask' # pseudo state contact.chatstate = 'ask' # pseudo state
# if peer supports jep85, send 'active' # if peer supports jep85, send 'active'
elif self.chatstates[jid] != False: elif contact.chatstate 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'