nick was utf8, room_jid was unicode so we had a problem. it is fixed [stills Tracebacks because of TODO: use gc_contacts in common/gaim.py]

This commit is contained in:
Nikos Kouremenos 2005-07-22 14:30:35 +00:00
parent 45ead83fad
commit b5fe60112d
6 changed files with 69 additions and 37 deletions

View File

@ -61,15 +61,52 @@ sleeper_state = {} # whether we pass auto away / xa or not
#'autoxa': autoxa and use sleeper
def get_fjid_from_nick(room_jid, nick):
# fake jid is the jid for a contact in a room
# gaim@conference.jabber.org/nick
fjid = room_jid + '/' + nick
return fjid
def get_nick_from_jid(jid):
pos = jid.find('@')
return jid[:pos]
def get_nick_from_fjid(jid):
# fake jid is the jid for a contact in a room
# gaim@conference.jabber.org/nick/nick-continued
return jid.split('/', 1)[1]
def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid '''
return contacts[account][jid]
#print contacts
if jid in contacts[account]:
contacts_instances = contacts[account][jid]
return contacts_instances
def get_first_contact_instance_from_jid(account, jid):
return contacts[account][jid][0]
if jid in contacts[account]:
contact = contacts[account][jid][0]
else: # it's fake jid
nick = get_nick_from_fjid(jid)
if nick in gc_contacts[room_jid]:
contact = gc_contacts[room_jid][nick] # always only one instance
return contact
def get_contact_name_from_jid(account, jid):
return contacts[account][jid][0].name
def get_jid_without_resource(jid):
return jid.split('/')[0]
def construct_fjid(room_jid, nick):
''' nick is in utf8 (taken from treeview); room_jid is in unicode'''
return room_jid + '/' + unicode(nick, 'utf-8')
def get_resource_from_jid(jid):
return jid.split('/', 1)[1] # abc@doremi.org/res/res-continued
'''\
[15:34:28] <asterix> we should add contact.fake_jid I think
[15:34:46] <asterix> so if we know real jid, it wil be in contact.jid, or we look in contact.fake_jid
[15:32:54] <asterix> they can have resource if we know the real jid
[15:33:07] <asterix> and that resource is in contact.resource
'''

View File

@ -51,24 +51,6 @@ def get_sorted_keys(adict):
keys.sort()
return keys
def get_fjid_from_nick(room_jid, nick):
# fake jid is the jid for a contact in a room
# gaim@conference.jabber.org/nick
fjid = room_jid + '/' + nick
return fjid
def get_nick_from_jid(jid):
pos = jid.find('@')
return jid[:pos]
def get_nick_from_fjid(jid):
# fake jid is the jid for a contact in a room
# gaim@conference.jabber.org/nick/nick-continued
return jid.split('/', 1)[1]
def get_resource_from_jid(jid):
return jid.split('/', 1)[1] # abc@doremi.org/res/res-continued
def to_one_line(msg):
msg = msg.replace('\\', '\\\\')
msg = msg.replace('\n', '\\n')
@ -93,3 +75,16 @@ def from_one_line(msg):
# s14
# 'test\ntest\\ntest'
return msg
def get_uf_chatstate(chatstate):
'''removes chatstate jargon and returns user friendly messages'''
if chatstate == 'active':
return _('is paying attention to the conversation')
elif chatstate == 'inactive':
return _('is doing something else')
elif chatstate == 'composing':
return _('is composing a message...')
elif chatstate == 'paused':
return _('paused composing a message...')
elif chatstate == 'gone':
return _('closed the chat window or tab')

View File

@ -180,7 +180,7 @@ class Interface:
def handle_event_roster(self, account, data):
#('ROSTER', account, array)
self.roster.mklists(data, account)
self.roster.fill_contacts_and_groups_dicts(data, account)
self.roster.draw_roster()
if self.remote and self.remote.is_enabled():
self.remote.raise_signal('Roster', (account, data))

View File

@ -658,7 +658,7 @@ class GroupchatWindow(chat.Chat):
def ban(self, widget, room_jid, jid):
"""ban a user"""
# to ban we know the real jid. so jid is not fakejid
nick = helpers.get_nick_from_jid(jid)
nick = gajim.get_nick_from_jid(jid)
# ask for reason
instance = dialogs.InputDialog(_('Banning %s') % nick,
_('You may specify a reason below:'))
@ -704,7 +704,7 @@ class GroupchatWindow(chat.Chat):
jid = c.jid
fjid = c.jid + '/' + c.resource
else:
fjid = room_jid + '/' + nick
fjid = gajim.construct_fjid(room_jid, nick)
jid = fjid
if self.plugin.windows[self.account]['infos'].has_key(jid):
self.plugin.windows[self.account]['infos'][jid].window.present()
@ -723,9 +723,9 @@ class GroupchatWindow(chat.Chat):
'''opens a chat window and msg is not None sends private message to a
contact in a room'''
if nick is None:
nick = model.get_value(iter, 1)
nick = model[iter][1]
room_jid = self.get_active_jid()
fjid = room_jid + '/' + nick # 'fake' jid
fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid
if not self.plugin.windows[self.account]['chats'].has_key(fjid):
show = self.contacts[room_jid][nick].show
u = Contact(jid = fjid, name = nick, groups = ['none'], show = show,
@ -772,7 +772,7 @@ class GroupchatWindow(chat.Chat):
def mk_menu(self, room_jid, event, iter):
"""Make user's popup menu"""
model = self.list_treeview[room_jid].get_model()
nick = model.get_value(iter, 1)
nick = model[iter][1]
c = self.contacts[room_jid][nick]
jid = c.jid
target_affiliation = c.affiliation
@ -999,8 +999,8 @@ class GroupchatWindow(chat.Chat):
model = widget.get_model()
iter = model.get_iter(path)
if len(path) == 2:
nick = model.get_value(iter, 1)
fjid = room_jid + '/' + nick
nick = model[iter][1]
fjid = gajim.construct_fjid(room_jid, nick)
if not self.plugin.windows[self.account]['chats'].has_key(fjid):
show = self.contacts[room_jid][nick].show
u = Contact(jid = fjid, name = nick, groups = ['none'],
@ -1019,7 +1019,7 @@ class GroupchatWindow(chat.Chat):
model = widget.get_model()
iter = model.get_iter(path)
nick = model.get_value(iter, 1)
nick = model[iter][1]
if not nick in self.contacts[room_jid]: #it's a group
if x < 20: # first cell in 1st column (the arrow SINGLE clicked)
if (widget.row_expanded(path)):
@ -1045,8 +1045,8 @@ class GroupchatWindow(chat.Chat):
widget.expand_row(path, False)
else: # We want to send a private message
room_jid = self.get_active_jid()
nick = model.get_value(iter, 1)
fjid = room_jid + '/' + nick
nick = model[iter][1]
fjid = gajim.construct_fjid(room_jid, nick)
if not self.plugin.windows[self.account]['chats'].has_key(fjid):
show = self.contacts[room_jid][nick].show
u = Contact(jid = fjid, name = nick, groups = ['none'], show = show,

View File

@ -546,7 +546,7 @@ class RosterWindow:
for jid in gajim.contacts[acct].keys():
self.add_contact_to_roster(jid, acct)
def mklists(self, array, account):
def fill_contacts_and_groups_dicts(self, array, account):
'''fill gajim.contacts and gajim.groups'''
if not gajim.contacts.has_key(account):
gajim.contacts[account] = {}
@ -575,13 +575,13 @@ class RosterWindow:
'attached_gpg_keys').split()
if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid = ji, name = name, groups = array[jid]['groups'],
contact1 = Contact(jid = ji, name = name, groups = array[jid]['groups'],
show = show, status = status, sub = array[jid]['subscription'],
ask = array[jid]['ask'], resource = resource, keyID = keyID)
# when we draw the roster, we avoid having the same contact
# more than once (eg. we avoid showing it twice with 2 resources)
gajim.contacts[account][ji] = [user1]
# more than once (f.e. we avoid showing it twice when 2 resources)
gajim.contacts[account][ji] = [contact1]
for g in array[jid]['groups'] :
if g in gajim.groups[account].keys():
continue

View File

@ -144,9 +144,9 @@ class TabbedChatWindow(chat.Chat):
# % (name, fulljid)
if chatstate:
chatstate = helpers.get_uf_chatstate(chatstate)
label_text = \
'<span weight="heavy" size="x-large">%s</span> (chat state: %s)' \
% (name, chatstate)
'<span weight="heavy" size="x-large">%s</span> %s' % (name, chatstate)
else:
label_text = '<span weight="heavy" size="x-large">%s</span>' % name