diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 00d1774ff..567ee305d 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -148,11 +148,17 @@ class PrivateChatControl(ChatControl): self.gc_contact = gc_contact ChatControl.__init__(self, parent_win, contact, account, session) self.TYPE_ID = 'pm' + gajim.ged.register_event_handler('caps-received', ged.GUI1, + self._nec_caps_received) + gajim.ged.register_event_handler('gc-presence-received', ged.GUI1, + self._nec_gc_presence_received) def shutdown(self): super(PrivateChatControl, self).shutdown() gajim.ged.remove_event_handler('caps-received', ged.GUI1, self._nec_caps_received) + gajim.ged.remove_event_handler('gc-presence-received', ged.GUI1, + self._nec_gc_presence_received) def _nec_caps_received(self, obj): if obj.conn.name != self.account or \ @@ -160,6 +166,48 @@ class PrivateChatControl(ChatControl): return self.update_contact() + def _nec_gc_presence_received(self, obj): + if obj.conn.name != self.account: + return + if obj.fjid != self.full_jid: + return + if '303' in obj.status_code: + self.print_conversation(_('%(nick)s is now known as ' + '%(new_nick)s') % {'nick': obj.nick, 'new_nick': obj.new_nick}, + 'status') + gc_c = gajim.contacts.get_gc_contact(obj.conn.name, obj.room_jid, + obj.new_nick) + c = gc_c.as_contact() + self.gc_contact = gc_c + self.contact = c + if self.session: + # stop e2e + if self.session.enable_encryption: + thread_id = self.session.thread_id + self.session.terminate_e2e() + obj.conn.delete_session(obj.fjid, thread_id) + self.no_autonegotiation = False + self.draw_banner() + old_jid = obj.room_jid + '/' + obj.nick + new_jid = obj.room_jid + '/' + obj.new_nick + gajim.interface.msg_win_mgr.change_key(old_jid, new_jid, + obj.conn.name) + else: + self.contact.show = obj.show + self.contact.status = obj.status + self.gc_contact.show = obj.show + self.gc_contact.status = obj.status + uf_show = helpers.get_uf_show(obj.show) + self.print_conversation(_('%(nick)s is now %(status)s') % { + 'nick': obj.nick, 'status': uf_show}, 'status') + if obj.status: + self.print_conversation(' (', 'status', simple=True) + self.print_conversation('%s' % (obj.status), 'status', + simple=True) + self.print_conversation(')', 'status', simple=True) + self.parent_win.redraw_tab(self) + self.update_ui() + def send_message(self, message, xhtml=None, process_commands=True): """ Call this method to send the message diff --git a/src/gui_interface.py b/src/gui_interface.py index b94c69fef..b2f31e6c4 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -638,84 +638,6 @@ class Interface: if self.roster.tooltip.id and self.roster.tooltip.win: self.roster.tooltip.update_last_time(last_time) - def handle_event_gc_notify(self, account, array): - #'GC_NOTIFY' (account, (room_jid, show, status, nick, - # role, affiliation, jid, reason, actor, statusCode, newNick, - # avatar_sha)) - nick = array[3] - if not nick: - return - room_jid = array[0] - fjid = room_jid + '/' + nick - show = array[1] - status = array[2] - conn = gajim.connections[account] - - # Get the window and control for the updated status, this may be a - # PrivateChatControl - control = self.msg_win_mgr.get_gc_control(room_jid, account) - - if not control and \ - room_jid in self.minimized_controls[account]: - control = self.minimized_controls[account][room_jid] - - if not control or (control and \ - control.type_id != message_control.TYPE_GC): - return - - control.chg_contact_status(nick, show, status, array[4], array[5], - array[6], array[7], array[8], array[9], array[10], array[11]) - - contact = gajim.contacts.get_contact_with_highest_priority(account, - room_jid) - if contact: - self.roster.draw_contact(room_jid, account) - - # print status in chat window and update status/GPG image - ctrl = self.msg_win_mgr.get_control(fjid, account) - if ctrl: - statusCode = array[9] - if '303' in statusCode: - new_nick = array[10] - ctrl.print_conversation(_('%(nick)s is now known as ' - '%(new_nick)s') % {'nick': nick, 'new_nick': new_nick}, - 'status') - gc_c = gajim.contacts.get_gc_contact(account, room_jid, - new_nick) - c = gc_c.as_contact() - ctrl.gc_contact = gc_c - ctrl.contact = c - if ctrl.session: - # stop e2e - if ctrl.session.enable_encryption: - thread_id = ctrl.session.thread_id - ctrl.session.terminate_e2e() - conn.delete_session(fjid, thread_id) - ctrl.no_autonegotiation = False - ctrl.draw_banner() - old_jid = room_jid + '/' + nick - new_jid = room_jid + '/' + new_nick - self.msg_win_mgr.change_key(old_jid, new_jid, account) - else: - contact = ctrl.contact - contact.show = show - contact.status = status - gc_contact = ctrl.gc_contact - gc_contact.show = show - gc_contact.status = status - uf_show = helpers.get_uf_show(show) - ctrl.print_conversation(_('%(nick)s is now %(status)s') % { - 'nick': nick, 'status': uf_show}, 'status') - if status: - ctrl.print_conversation(' (', 'status', simple=True) - ctrl.print_conversation('%s' % (status), 'status', - simple=True) - ctrl.print_conversation(')', 'status', simple=True) - ctrl.parent_win.redraw_tab(ctrl) - ctrl.update_ui() - if self.remote_ctrl: - self.remote_ctrl.raise_signal('GCPresence', (account, array)) - def handle_event_gc_subject(self, account, array): #('GC_SUBJECT', account, (jid, subject, body, has_timestamp)) jids = array[0].split('/', 1) @@ -1707,7 +1629,6 @@ class Interface: 'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items], 'MYVCARD': [self.handle_event_myvcard], 'VCARD': [self.handle_event_vcard], - 'GC_NOTIFY': [self.handle_event_gc_notify], 'GC_SUBJECT': [self.handle_event_gc_subject], 'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change], 'FILE_REQUEST': [self.handle_event_file_request], diff --git a/src/roster_window.py b/src/roster_window.py index 2725ddf7f..eeb18db5b 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -2451,6 +2451,18 @@ class RosterWindow: self.chg_contact_status(obj.contact, obj.show, obj.status, account) + def _nec_gc_presence_received(self, obj): + account = obj.conn.name + if obj.room_jid in gajim.interface.minimized_controls[account]: + gc_ctrl = gajim.interface.minimized_controls[account][obj.room_jid] + else: + return + + contact = gajim.contacts.get_contact_with_highest_priority(account, + obj.room_jid) + if contact: + self.draw_contact(obj.room_jid, account) + def _nec_roster_received(self, obj): self.fill_contacts_and_groups_dicts(obj.roster, obj.conn.name) self.add_account_contacts(obj.conn.name) @@ -6219,6 +6231,8 @@ class RosterWindow: gajim.ged.register_event_handler('presence-received', ged.GUI1, self._nec_presence_received) + gajim.ged.register_event_handler('gc-presence-received', ged.GUI1, + self._nec_gc_presence_received) gajim.ged.register_event_handler('roster-received', ged.GUI1, self._nec_roster_received) gajim.ged.register_event_handler('anonymous-auth', ged.GUI1,