when we get a message from a contact and we have a window with this resource, print it there. see #1697

This commit is contained in:
Yann Leboulanger 2006-03-15 08:40:19 +00:00
parent af3f46bdb4
commit db7766ea7e
2 changed files with 55 additions and 36 deletions

View File

@ -214,7 +214,7 @@ class Interface:
title = data[1] title = data[1]
prompt = data[2] prompt = data[2]
proposed_nick = data[3] proposed_nick = data[3]
gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, account) gc_control = self.msg_win_mgr.get_control(room_jid, account)
if gc_control: # user may close the window before we are here if gc_control: # user may close the window before we are here
gc_control.show_change_nick_input_dialog(title, prompt, proposed_nick) gc_control.show_change_nick_input_dialog(title, prompt, proposed_nick)
@ -256,7 +256,7 @@ class Interface:
(jid_from, file_props)) (jid_from, file_props))
conn.disconnect_transfer(file_props) conn.disconnect_transfer(file_props)
return return
ctrl = gajim.interface.msg_win_mgr.get_control(jid_from, account) ctrl = self.msg_win_mgr.get_control(jid_from, account)
if ctrl and ctrl.type_id == message_control.TYPE_GC: if ctrl and ctrl.type_id == message_control.TYPE_GC:
ctrl.print_conversation('Error %s: %s' % (array[2], array[1])) ctrl.print_conversation('Error %s: %s' % (array[2], array[1]))
@ -281,7 +281,7 @@ class Interface:
model[self.roster.status_message_menuitem_iter][3] = True model[self.roster.status_message_menuitem_iter][3] = True
# Inform all controls for this account of the connection state change # Inform all controls for this account of the connection state change
for ctrl in gajim.interface.msg_win_mgr.get_controls( for ctrl in self.msg_win_mgr.get_controls(
type = message_control.TYPE_GC): type = message_control.TYPE_GC):
if ctrl.account == account: if ctrl.account == account:
if status == 'offline': if status == 'offline':
@ -470,6 +470,7 @@ class Interface:
# chatstate)) # 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])
fjid = jid + '/' + resource
msg_type = array[4] msg_type = array[4]
chatstate = array[6] chatstate = array[6]
msg_id = array[7] msg_id = array[7]
@ -485,11 +486,11 @@ class Interface:
elif gajim.connections[account].connected in (2, 3): # we're online or chat elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True show_notification = True
chat_control = gajim.interface.msg_win_mgr.get_control(jid, account) chat_control = self.msg_win_mgr.get_control(jid, account)
if chat_control and chat_control.type_id == message_control.TYPE_GC: if chat_control and chat_control.type_id == message_control.TYPE_GC:
# it's a Private Message # it's a Private Message
fjid = array[0] fjid = array[0]
if not gajim.interface.msg_win_mgr.has_window(fjid, account) and \ if not self.msg_win_mgr.has_window(fjid, account) and \
not gajim.awaiting_events[account].has_key(fjid): not gajim.awaiting_events[account].has_key(fjid):
if show_notification: if show_notification:
room_jid, nick = gajim.get_room_and_nick_from_fjid(fjid) room_jid, nick = gajim.get_room_and_nick_from_fjid(fjid)
@ -509,6 +510,11 @@ class Interface:
not gajim.contacts.get_contact(account, jid): not gajim.contacts.get_contact(account, jid):
return return
# Look for a chat control that has the given resource, or default to one
# without resource
ctrl = self.msg_win_mgr.get_control(fjid, account)
if ctrl:
chat_control = ctrl
# Handle chat states # Handle chat states
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact: if contact:
@ -534,8 +540,7 @@ class Interface:
return return
first = False first = False
if not gajim.interface.msg_win_mgr.has_window(jid, account) and \ if not chat_control and not gajim.awaiting_events[account].has_key(jid):
not gajim.awaiting_events[account].has_key(jid):
first = True first = True
if gajim.config.get('notify_on_new_message'): if gajim.config.get('notify_on_new_message'):
show_notification = False show_notification = False
@ -576,12 +581,12 @@ class Interface:
fjid = array[0] fjid = array[0]
jids = fjid.split('/', 1) jids = fjid.split('/', 1)
jid = jids[0] jid = jids[0]
gcs = gajim.interface.msg_win_mgr.get_controls(message_control.TYPE_GC) gcs = self.msg_win_mgr.get_controls(message_control.TYPE_GC)
for gc_control in gcs: for gc_control in gcs:
if jid == gc_control.contact.jid: if jid == gc_control.contact.jid:
if len(jids) > 1: # it's a pm if len(jids) > 1: # it's a pm
nick = jids[1] nick = jids[1]
if not gajim.interface.msg_win_mgr.get_control(fjid, account): if not self.msg_win_mgr.get_control(fjid, account):
tv = gc_control.list_treeview tv = gc_control.list_treeview
model = tv.get_model() model = tv.get_model()
i = gc_control.get_contact_iter(nick) i = gc_control.get_contact_iter(nick)
@ -593,7 +598,7 @@ class Interface:
name = nick, show = show) name = nick, show = show)
c = gajim.contacts.contact_from_gc_contct(c) c = gajim.contacts.contact_from_gc_contct(c)
self.roster.new_chat(c, account, private_chat = True) self.roster.new_chat(c, account, private_chat = True)
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account) ctrl = self.msg_win_mgr.get_control(fjid, account)
ctrl.print_conversation('Error %s: %s' % (array[1], array[2]), ctrl.print_conversation('Error %s: %s' % (array[1], array[2]),
'status') 'status')
return return
@ -750,19 +755,19 @@ class Interface:
# show avatar in chat # show avatar in chat
win = None win = None
ctrl = None ctrl = None
if resource and gajim.interface.msg_win_mgr.has_window( if resource and self.msg_win_mgr.has_window(
jid + '/' + resource, account): jid + '/' + resource, account):
win = gajim.interface.msg_win_mgr.get_window(jid + '/' + resource, win = self.msg_win_mgr.get_window(jid + '/' + resource,
account) account)
ctrl = win.get_control(jid + '/' + resource, account) ctrl = win.get_control(jid + '/' + resource, account)
elif gajim.interface.msg_win_mgr.has_window(jid, account): elif self.msg_win_mgr.has_window(jid, account):
win = gajim.interface.msg_win_mgr.get_window(jid, account) win = self.msg_win_mgr.get_window(jid, account)
ctrl = win.get_control(jid, account) ctrl = win.get_control(jid, account)
if win and ctrl.type_id != message_control.TYPE_GC: if win and ctrl.type_id != message_control.TYPE_GC:
ctrl.show_avatar() ctrl.show_avatar()
# Show avatar in roster or gc_roster # Show avatar in roster or gc_roster
gc_ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) gc_ctrl = self.msg_win_mgr.get_control(jid, account)
if gc_ctrl and gc_ctrl.type_id == message_control.TYPE_GC: if gc_ctrl and gc_ctrl.type_id == message_control.TYPE_GC:
gc_ctrl.draw_avatar(resource) gc_ctrl.draw_avatar(resource)
else: else:
@ -813,8 +818,8 @@ class Interface:
show = array[1] show = array[1]
status = array[2] status = array[2]
# print status in chat window and update status/GPG image # print status in chat window and update status/GPG image
if gajim.interface.msg_win_mgr.has_window(fjid, account): if self.msg_win_mgr.has_window(fjid, account):
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account) ctrl = self.msg_win_mgr.get_control(fjid, account)
contact = ctrl.contact contact = ctrl.contact
contact.show = show contact.show = show
contact.status = status contact.status = status
@ -825,12 +830,12 @@ class Interface:
ctrl.draw_banner() ctrl.draw_banner()
# Get the window and control for the updated status, this may be a PrivateChatControl # Get the window and control for the updated status, this may be a PrivateChatControl
control = gajim.interface.msg_win_mgr.get_control(room_jid, account) control = self.msg_win_mgr.get_control(room_jid, account)
if control: if control:
control.chg_contact_status(nick, show, status, array[4], array[5], array[6], control.chg_contact_status(nick, show, status, array[4], array[5], array[6],
array[7], array[8], array[9], array[10]) array[7], array[8], array[9], array[10])
# Find any PM chat through this room, and tell it to update. # Find any PM chat through this room, and tell it to update.
pm_control = gajim.interface.msg_win_mgr.get_control(fjid, account) pm_control = self.msg_win_mgr.get_control(fjid, account)
if pm_control: if pm_control:
pm_control.parent_win.redraw_tab(pm_control) pm_control.parent_win.redraw_tab(pm_control)
if self.remote_ctrl: if self.remote_ctrl:
@ -840,7 +845,7 @@ class Interface:
# ('GC_MSG', account, (jid, msg, time)) # ('GC_MSG', account, (jid, msg, time))
jids = array[0].split('/', 1) jids = array[0].split('/', 1)
room_jid = jids[0] room_jid = jids[0]
gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, account) gc_control = self.msg_win_mgr.get_control(room_jid, account)
if not gc_control: if not gc_control:
return return
if len(jids) == 1: if len(jids) == 1:
@ -857,7 +862,7 @@ class Interface:
#('GC_SUBJECT', account, (jid, subject, body)) #('GC_SUBJECT', account, (jid, subject, body))
jids = array[0].split('/', 1) jids = array[0].split('/', 1)
jid = jids[0] jid = jids[0]
gc_control = gajim.interface.msg_win_mgr.get_control(jid, account) gc_control = self.msg_win_mgr.get_control(jid, account)
if not gc_control: if not gc_control:
return return
gc_control.set_subject(array[1]) gc_control.set_subject(array[1])
@ -1209,7 +1214,7 @@ class Interface:
'''SIGNED_IN event is emitted when we sign in, so handle it''' '''SIGNED_IN event is emitted when we sign in, so handle it'''
# join already open groupchats # join already open groupchats
self.roster.actions_menu_needs_rebuild = True self.roster.actions_menu_needs_rebuild = True
for gc_control in gajim.interface.msg_win_mgr.get_controls(message_control.TYPE_GC): for gc_control in self.msg_win_mgr.get_controls(message_control.TYPE_GC):
if account != gc_control.account: if account != gc_control.account:
continue continue
room_jid = gc_control.room_jid room_jid = gc_control.room_jid
@ -1494,19 +1499,19 @@ class Interface:
def handle_event(self, account, jid, typ): def handle_event(self, account, jid, typ):
w = None w = None
if typ == message_control.TYPE_GC: if typ == message_control.TYPE_GC:
w = gajim.interface.msg_win_mgr.get_window(jid, account) w = self.msg_win_mgr.get_window(jid, account)
elif typ == message_control.TYPE_CHAT: elif typ == message_control.TYPE_CHAT:
if gajim.interface.msg_win_mgr.has_window(jid, account): if self.msg_win_mgr.has_window(jid, account):
w = gajim.interface.msg_win_mgr.get_window(jid, account) w = self.msg_win_mgr.get_window(jid, account)
else: else:
contact = gajim.contacts.get_first_contact_from_jid(account, jid) contact = gajim.contacts.get_first_contact_from_jid(account, jid)
self.roster.new_chat(contact, account) self.roster.new_chat(contact, account)
w = gajim.interface.msg_win_mgr.get_window(jid, account) w = self.msg_win_mgr.get_window(jid, account)
ctrl = w.get_control ctrl = w.get_control
gajim.last_message_time[account][jid] = 0 # long time ago gajim.last_message_time[account][jid] = 0 # long time ago
elif typ == message_control.TYPE_PM: elif typ == message_control.TYPE_PM:
if gajim.interface.msg_win_mgr.has_window(jid, account): if self.msg_win_mgr.has_window(jid, account):
w = gajim.interface.msg_win_mgr.get_window(jid, account) w = self.msg_win_mgr.get_window(jid, account)
else: else:
room_jid, nick = jid.split('/', 1) room_jid, nick = jid.split('/', 1)
gc_contact = gajim.contacts.get_gc_contact(account, room_jid, gc_contact = gajim.contacts.get_gc_contact(account, room_jid,
@ -1519,7 +1524,7 @@ class Interface:
name = nick, show = show) name = nick, show = show)
c = gajim.contacts.contact_from_gc_contact(gc_contact) c = gajim.contacts.contact_from_gc_contact(gc_contact)
self.roster.new_chat(c, account, private_chat = True) self.roster.new_chat(c, account, private_chat = True)
w = gajim.interface.msg_win_mgr.get_window(jid, account) w = self.msg_win_mgr.get_window(jid, account)
elif typ in ('normal', 'file-request', 'file-request-error', elif typ in ('normal', 'file-request', 'file-request-error',
'file-send-error', 'file-error', 'file-stopped', 'file-completed'): 'file-send-error', 'file-error', 'file-stopped', 'file-completed'):
# Get the first single message event # Get the first single message event

View File

@ -1936,7 +1936,16 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
def on_message(self, jid, msg, tim, account, encrypted = False, def on_message(self, jid, msg, tim, account, encrypted = False,
msg_type = '', subject = None, resource = ''): msg_type = '', subject = None, resource = ''):
'''when we receive a message''' '''when we receive a message'''
contact = gajim.contacts.get_contact_with_highest_priority(account, jid) contact = None
# Try to catch the contact with correct resource
if resource:
fjid = jid + '/' + resource
contact = gajim.contacts.get_contact(account, jid, resource)
# Default to highest prio
if not contact:
fjid = jid
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
if not contact: if not contact:
keyID = '' keyID = ''
attached_keys = gajim.config.get_per('accounts', account, attached_keys = gajim.config.get_per('accounts', account,
@ -1961,7 +1970,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
# Do we have a queue? # Do we have a queue?
qs = gajim.awaiting_events[account] qs = gajim.awaiting_events[account]
no_queue = True no_queue = True
if qs.has_key(jid): if qs.has_key(fjid):
no_queue = False no_queue = False
popup = False popup = False
if autopopup and (autopopupaway or gajim.connections[account].connected \ if autopopup and (autopopupaway or gajim.connections[account].connected \
@ -1975,25 +1984,30 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
return return
# We print if window is opened and it's not a single message # We print if window is opened and it's not a single message
if gajim.interface.msg_win_mgr.has_window(jid, account) and msg_type != 'normal': # Look for a chat control that has the given resource, or default to one
# without resource
ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account)
if not ctrl:
gajim.interface.msg_win_mgr.get_control(jid, account)
if ctrl and msg_type != 'normal':
typ = '' typ = ''
if msg_type == 'error': if msg_type == 'error':
typ = 'status' typ = 'status'
ctrl = gajim.interface.msg_win_mgr.get_control(jid, account)
ctrl.print_conversation(msg, typ, tim = tim, encrypted = encrypted, ctrl.print_conversation(msg, typ, tim = tim, encrypted = encrypted,
subject = subject) subject = subject)
return return
# We save it in a queue # We save it in a queue
if no_queue: if no_queue:
qs[jid] = [] qs[fjid] = []
kind = 'chat' kind = 'chat'
if msg_type == 'normal': if msg_type == 'normal':
kind = 'normal' kind = 'normal'
qs[jid].append((kind, (msg, subject, msg_type, tim, encrypted, resource))) qs[fjid].append((kind, (msg, subject, msg_type, tim, encrypted,
resource)))
self.nb_unread += 1 self.nb_unread += 1
if popup: if popup:
if not gajim.interface.msg_win_mgr.has_window(jid, account): if not ctrl:
self.new_chat(contact, account) self.new_chat(contact, account)
if path: if path:
self.tree.expand_row(path[0:1], False) self.tree.expand_row(path[0:1], False)