show transport nickname if there is one and user hasn't set a nickname. fixes #3094

This commit is contained in:
Yann Leboulanger 2007-05-12 20:30:26 +00:00
parent 31101e5049
commit 1674110503
3 changed files with 16 additions and 5 deletions

View File

@ -1569,6 +1569,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
user_nick = prs.getTagData('nick')
if not user_nick:
user_nick = ''
contact_nickname = None
transport_auto_auth = False
xtags = prs.getTags('x')
for x in xtags:
@ -1581,6 +1582,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
sigTag = x
elif namespace == common.xmpp.NS_VCARD_UPDATE:
avatar_sha = x.getTagData('photo')
contact_nickname = x.getTagData('nickname')
elif namespace == common.xmpp.NS_DELAY:
# JEP-0091
tim = prs.getTimestamp()
@ -1620,7 +1622,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
errcode = prs.getErrorCode()
if errcode == '502': # Internal Timeout:
self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource,
prio, keyID, timestamp))
prio, keyID, timestamp, None))
elif errcode == '401': # password required to join
self.dispatch('ERROR', (_('Unable to join group chat'),
_('A password is required to join this group chat.')))
@ -1716,7 +1718,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
self.connection.send(p)
if who.find("@") <= 0 or transport_auto_auth:
self.dispatch('NOTIFY', (jid_stripped, 'offline', 'offline',
resource, prio, keyID, timestamp))
resource, prio, keyID, timestamp, None))
if transport_auto_auth:
self.automatically_added.append(jid_stripped)
self.request_subscription(jid_stripped, name = user_nick)
@ -1767,7 +1769,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
errcode = prs.getErrorCode()
if errcode == '502': # Internal Timeout:
self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource,
prio, keyID, timestamp))
prio, keyID, timestamp, None))
else: # print in the window the error
self.dispatch('ERROR_ANSWER', ('', jid_stripped,
errmsg, errcode))
@ -1788,7 +1790,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
not in no_log_for and jid_stripped not in no_log_for:
gajim.logger.write('status', jid_stripped, status, show)
self.dispatch('NOTIFY', (jid_stripped, show, status, resource, prio,
keyID, timestamp))
keyID, timestamp, contact_nickname))
# END presenceCB
def _StanzaArrivedCB(self, con, obj):

View File

@ -23,6 +23,7 @@ class Contact:
chatstate=None, last_status_time=None, msg_id = None, composing_jep = None):
self.jid = jid
self.name = name
self.contact_name = '' # nick choosen by contact
self.groups = groups
self.show = show
self.status = status
@ -57,6 +58,8 @@ class Contact:
def get_shown_name(self):
if self.name:
return self.name
if self.contact_name:
return self.contact_name
return self.jid.split('@')[0]
def is_hidden_from_roster(self):

View File

@ -505,7 +505,7 @@ class Interface:
def handle_event_notify(self, account, array):
# 'NOTIFY' (account, (jid, status, status message, resource, priority,
# keyID, timestamp))
# keyID, timestamp, contact_nickname))
# if we're here it means contact changed show
statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
'invisible']
@ -517,6 +517,7 @@ class Interface:
status_message = array[2]
jid = array[0].split('/')[0]
keyID = array[5]
contact_nickname = array[7]
attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split()
if jid in attached_keys:
@ -545,6 +546,10 @@ class Interface:
if contact1:
if contact1.show in statuss:
old_show = statuss.index(contact1.show)
if contact_nickname is not None and \
contact1.contact_name != contact_nickname:
contact1.contact_name = contact_nickname
self.roster.draw_contact(jid, account)
if old_show == new_show and contact1.status == status_message and \
contact1.priority == priority: # no change
return
@ -599,6 +604,7 @@ class Interface:
elif not gajim.block_signed_in_notifications[account]:
# We're connected since more that 30 seconds
contact1.last_status_time = time.localtime()
contact1.contact_nickname = contact_nickname
if gajim.jid_is_transport(jid):
# It must be an agent
if ji in jid_list: