Philipp Hörist pushed to branch mainwindow at gajim / gajim

Commits:

8 changed files:

Changes:

  • gajim/chat_control.py
    ... ... @@ -101,17 +101,10 @@ class ChatControl(ChatControlBase):
    101 101
         COMMAND_HOST = ChatCommands  # type: ClassVar[Type[CommandHost]]
    
    102 102
     
    
    103 103
         def __init__(self, parent_win, jid, acct, session, resource=None):
    
    104
    -
    
    105
    -        contact = app.get_client(acct).get_module('Contacts').get_contact(jid)
    
    106
    -        contact.connect('presence-update', self._on_presence_update)
    
    107
    -        contact.connect('chatstate-update', self._on_chatstate_update)
    
    108
    -        contact.connect('nickname-update', self._on_nickname_update)
    
    109
    -        contact.connect('avatar-update', self._on_avatar_update)
    
    110
    -
    
    111 104
             ChatControlBase.__init__(self,
    
    112 105
                                      parent_win,
    
    113 106
                                      'chat_control',
    
    114
    -                                 contact,
    
    107
    +                                 jid,
    
    115 108
                                      acct,
    
    116 109
                                      resource)
    
    117 110
     
    
    ... ... @@ -225,6 +218,14 @@ def __init__(self, parent_win, jid, acct, session, resource=None):
    225 218
             app.plugin_manager.gui_extension_point('chat_control', self)
    
    226 219
             self.update_actions()
    
    227 220
     
    
    221
    +    def _connect_contact_signals(self):
    
    222
    +        self.contact.multi_connect({
    
    223
    +            'presence-update': self._on_presence_update,
    
    224
    +            'chatstate-update': self._on_chatstate_update,
    
    225
    +            'nickname-update': self._on_nickname_update,
    
    226
    +            'avatar-update': self._on_avatar_update,
    
    227
    +        })
    
    228
    +
    
    228 229
         @property
    
    229 230
         def jid(self):
    
    230 231
             return self.contact.jid
    
    ... ... @@ -315,7 +316,7 @@ def update_actions(self):
    315 316
     
    
    316 317
             # Send file (Jingle)
    
    317 318
             jingle_support = self.contact.supports(Namespace.JINGLE_FILE_TRANSFER_5)
    
    318
    -        jingle_conditions = jingle_support and not self.contact.show.is_offline
    
    319
    +        jingle_conditions = jingle_support and self.contact.is_available
    
    319 320
             jingle = win.lookup_action('send-file-jingle-' + self.control_id)
    
    320 321
             jingle.set_enabled(online and jingle_conditions)
    
    321 322
     
    
    ... ... @@ -532,7 +533,7 @@ def _on_update_client_info(self, event):
    532 533
                 return
    
    533 534
             self.xml.phone_image.set_visible(contact.uses_phone)
    
    534 535
     
    
    535
    -    def _on_chatstate_update(self, _contact, _signal_name):
    
    536
    +    def _on_chatstate_update(self, *args):
    
    536 537
             self.draw_banner_text()
    
    537 538
     
    
    538 539
         def _on_nickname_update(self, _contact, _signal_name):
    

  • gajim/chat_control_base.py
    ... ... @@ -43,7 +43,6 @@
    43 43
     from gajim.common.i18n import _
    
    44 44
     from gajim.common.nec import EventHelper
    
    45 45
     from gajim.common.helpers import AdditionalDataDict
    
    46
    -from gajim.common.contacts import GC_Contact
    
    47 46
     from gajim.common.structs import OutgoingMessage
    
    48 47
     
    
    49 48
     from gajim import gtkgui_helpers
    
    ... ... @@ -99,7 +98,7 @@ class ChatControlBase(ChatCommandProcessor, CommandTools, EventHelper):
    99 98
     
    
    100 99
         _type = None  # type: ControlType
    
    101 100
     
    
    102
    -    def __init__(self, parent_win, widget_name, contact, acct,
    
    101
    +    def __init__(self, parent_win, widget_name, jid, acct,
    
    103 102
                      resource=None):
    
    104 103
             EventHelper.__init__(self)
    
    105 104
             # Undo needs this variable to know if space has been pressed.
    
    ... ... @@ -108,7 +107,13 @@ def __init__(self, parent_win, widget_name, contact, acct,
    108 107
     
    
    109 108
             self.handlers = {}
    
    110 109
             self.parent_win = parent_win
    
    110
    +
    
    111
    +        groupchat = self._type != ControlType.CHAT
    
    112
    +        contact = app.get_client(acct).get_module('Contacts').get_contact(
    
    113
    +            jid, groupchat=groupchat)
    
    111 114
             self.contact = contact
    
    115
    +        self._connect_contact_signals()
    
    116
    +
    
    112 117
             self.account = acct
    
    113 118
             self.resource = resource
    
    114 119
     
    
    ... ... @@ -267,6 +272,9 @@ def __init__(self, parent_win, widget_name, contact, acct,
    267 272
             # to properly use the super, because of the old code.
    
    268 273
             CommandTools.__init__(self)
    
    269 274
     
    
    275
    +    def _connect_contact_signals(self):
    
    276
    +        raise NotImplementedError
    
    277
    +
    
    270 278
         def process_event(self, event):
    
    271 279
             method_name = event.name.replace('-', '_')
    
    272 280
             method_name = f'_on_{method_name}'
    
    ... ... @@ -470,9 +478,7 @@ def setup_seclabel(self):
    470 478
             # text to show is in in first column of liststore
    
    471 479
             self.xml.label_selector.add_attribute(cell, 'text', 0)
    
    472 480
             con = app.connections[self.account]
    
    473
    -        jid = self.contact.jid
    
    474
    -        if self._type.is_privatechat:
    
    475
    -            jid = self.gc_contact.room_jid
    
    481
    +        jid = self.contact.jid.bare
    
    476 482
             if con.get_module('SecLabels').supported:
    
    477 483
                 con.get_module('SecLabels').request_catalog(jid)
    
    478 484
     
    
    ... ... @@ -480,9 +486,7 @@ def _sec_labels_received(self, event):
    480 486
             if event.account != self.account:
    
    481 487
                 return
    
    482 488
     
    
    483
    -        jid = self.contact.jid
    
    484
    -        if self._type.is_privatechat:
    
    485
    -            jid = self.gc_contact.room_jid
    
    489
    +        jid = self.contact.jid.bare
    
    486 490
     
    
    487 491
             if event.jid != jid:
    
    488 492
                 return
    
    ... ... @@ -971,9 +975,7 @@ def get_seclabel(self):
    971 975
                 return None
    
    972 976
     
    
    973 977
             con = app.connections[self.account]
    
    974
    -        jid = self.contact.jid
    
    975
    -        if self._type.is_privatechat:
    
    976
    -            jid = self.gc_contact.room_jid
    
    978
    +        jid = self.contact.jid.bare
    
    977 979
             catalog = con.get_module('SecLabels').get_catalog(jid)
    
    978 980
             labels, label_list = catalog.labels, catalog.get_label_names()
    
    979 981
             lname = label_list[idx]
    

  • gajim/common/modules/contacts.py
    ... ... @@ -393,6 +393,10 @@ def affiliation(self):
    393 393
         def role(self):
    
    394 394
             return self._presence.role
    
    395 395
     
    
    396
    +    @property
    
    397
    +    def chatstate(self):
    
    398
    +        return self._module('Chatstate').get_remote_chatstate(self._jid)
    
    399
    +
    
    396 400
         @property
    
    397 401
         def avatar_sha(self):
    
    398 402
             return self._client.get_module('VCardAvatars').get_avatar_sha(self._jid)
    

  • gajim/common/modules/vcard_avatars.py
    ... ... @@ -163,7 +163,8 @@ def _process_update(self, jid, state, avatar_sha, groupchat):
    163 163
                         self._request_vcard(jid, avatar_sha, 'contact')
    
    164 164
     
    
    165 165
         def _muc_update_received(self, properties):
    
    166
    -        contact = self._con.get_module('Contacts').get_contact(properties.jid)
    
    166
    +        contact = self._con.get_module('Contacts').get_contact(properties.jid,
    
    167
    +                                                               groupchat=True)
    
    167 168
             nick = properties.jid.resource
    
    168 169
     
    
    169 170
             if properties.avatar_state == AvatarState.EMPTY:
    

  • gajim/groupchat_control.py
    ... ... @@ -86,40 +86,12 @@ class GroupchatControl(ChatControlBase):
    86 86
         COMMAND_HOST = GroupChatCommands
    
    87 87
     
    
    88 88
         def __init__(self, parent_win, jid, muc_data, acct):
    
    89
    -
    
    90
    -        contact = app.get_client(acct).get_module('Contacts').get_contact(
    
    91
    -            jid, groupchat=True)
    
    92
    -        contact.multi_connect({
    
    93
    -            'avatar-update': self._on_avatar_update,
    
    94
    -            'user-joined': self._on_user_joined,
    
    95
    -            'user-left': self._on_user_left,
    
    96
    -            'user-affiliation-changed': self._on_user_affiliation_changed,
    
    97
    -            'user-role-changed': self._on_user_role_changed,
    
    98
    -            'user-status-show-changed': self._on_user_status_show_changed,
    
    99
    -            'user-nickname-changed': self._on_user_nickname_changed,
    
    100
    -            'room-kicked': self._on_room_kicked,
    
    101
    -            'room-destroyed': self._on_room_destroyed,
    
    102
    -            'room-config-finished': self._on_room_config_finished,
    
    103
    -            'room-config-failed': self._on_room_config_failed,
    
    104
    -            'room-config-changed': self._on_room_config_changed,
    
    105
    -            'room-password-required': self._on_room_password_required,
    
    106
    -            'room-creation-failed': self._on_room_creation_failed,
    
    107
    -            'room-presence-error': self._on_room_presence_error,
    
    108
    -            'room-voice-request': self._on_room_voice_request,
    
    109
    -            'room-captcha-challenge': self._on_room_captcha_challenge,
    
    110
    -            'room-captcha-error': self._on_room_captcha_error,
    
    111
    -            'room-subject': self._on_room_subject,
    
    112
    -            'room-joined': self._on_room_joined,
    
    113
    -            'room-join-failed': self._on_room_join_failed,
    
    114
    -        })
    
    115
    -
    
    116
    -        # contact.connect('user-avatar-update', self._on_user_avatar_update)
    
    117
    -
    
    118 89
             ChatControlBase.__init__(self,
    
    119 90
                                      parent_win,
    
    120 91
                                      'groupchat_control',
    
    121
    -                                 contact,
    
    92
    +                                 jid,
    
    122 93
                                      acct)
    
    94
    +
    
    123 95
             self.force_non_minimizable = False
    
    124 96
             self.is_anonymous = True
    
    125 97
     
    
    ... ... @@ -247,6 +219,31 @@ def __init__(self, parent_win, jid, muc_data, acct):
    247 219
             app.plugin_manager.gui_extension_point('groupchat_control', self)
    
    248 220
             self._restore_conversation()
    
    249 221
     
    
    222
    +    def _connect_contact_signals(self):
    
    223
    +        self.contact.multi_connect({
    
    224
    +            'avatar-update': self._on_avatar_update,
    
    225
    +            'user-joined': self._on_user_joined,
    
    226
    +            'user-left': self._on_user_left,
    
    227
    +            'user-affiliation-changed': self._on_user_affiliation_changed,
    
    228
    +            'user-role-changed': self._on_user_role_changed,
    
    229
    +            'user-status-show-changed': self._on_user_status_show_changed,
    
    230
    +            'user-nickname-changed': self._on_user_nickname_changed,
    
    231
    +            'room-kicked': self._on_room_kicked,
    
    232
    +            'room-destroyed': self._on_room_destroyed,
    
    233
    +            'room-config-finished': self._on_room_config_finished,
    
    234
    +            'room-config-failed': self._on_room_config_failed,
    
    235
    +            'room-config-changed': self._on_room_config_changed,
    
    236
    +            'room-password-required': self._on_room_password_required,
    
    237
    +            'room-creation-failed': self._on_room_creation_failed,
    
    238
    +            'room-presence-error': self._on_room_presence_error,
    
    239
    +            'room-voice-request': self._on_room_voice_request,
    
    240
    +            'room-captcha-challenge': self._on_room_captcha_challenge,
    
    241
    +            'room-captcha-error': self._on_room_captcha_error,
    
    242
    +            'room-subject': self._on_room_subject,
    
    243
    +            'room-joined': self._on_room_joined,
    
    244
    +            'room-join-failed': self._on_room_join_failed,
    
    245
    +        })
    
    246
    +
    
    250 247
         def _on_muc_state_changed(self, _muc_manager, _signal_name, state):
    
    251 248
             if state == MUCJoinedState.JOINED:
    
    252 249
                 self.roster.initial_draw()
    

  • gajim/gtk/chat_stack.py
    ... ... @@ -71,7 +71,7 @@ def add_group_chat(self, account, jid):
    71 71
     
    
    72 72
         def add_private_chat(self, account, jid):
    
    73 73
             mw = self.get_toplevel()
    
    74
    -        control = PrivateChatControl(mw, jid, None, account, None)
    
    74
    +        control = PrivateChatControl(mw, jid, account)
    
    75 75
             self._controls[(account, str(jid))] = control
    
    76 76
             self.add_named(control.widget, f'{account}:{jid}')
    
    77 77
             control.widget.show_all()
    

  • gajim/gtk/main.py
    ... ... @@ -487,6 +487,7 @@ def _load_chats(self):
    487 487
                 for account, jid, type_, pinned in open_chats:
    
    488 488
                     if account not in active_accounts:
    
    489 489
                         continue
    
    490
    +
    
    490 491
                     self.add_chat_for_workspace(workspace_id, account, jid, type_,
    
    491 492
                                                 pinned=pinned)
    
    492 493
     
    
    ... ... @@ -511,9 +512,13 @@ def _on_event(self, event):
    511 512
             if not self.chat_exists(event.account, event.jid):
    
    512 513
                 if event.name == 'message-received':
    
    513 514
                     if event.properties.is_muc_pm:
    
    514
    -                    self.add_private_chat(event.account, event.jid, 'pm')
    
    515
    +                    self.add_private_chat(event.account,
    
    516
    +                                          event.properties.jid,
    
    517
    +                                          'pm')
    
    515 518
                     else:
    
    516
    -                    self.add_chat(event.account, event.jid, 'contact')
    
    519
    +                    self.add_chat(event.account,
    
    520
    +                                  event.properties.jid,
    
    521
    +                                  'contact')
    
    517 522
                 else:
    
    518 523
                     # No chat is open, dont handle any gui events
    
    519 524
                     return
    

  • gajim/privatechat_control.py
    ... ... @@ -46,56 +46,48 @@ class PrivateChatControl(ChatControl):
    46 46
         # will be processed with this command host.
    
    47 47
         COMMAND_HOST = PrivateChatCommands
    
    48 48
     
    
    49
    -    def __init__(self, parent_win, gc_contact, contact, account, session):
    
    50
    -        room_jid = gc_contact.room_jid
    
    51
    -        self.room_ctrl = app.window.get_control(account, room_jid)
    
    52
    -        self.gc_contact = gc_contact
    
    53
    -        ChatControl.__init__(self, parent_win, contact, account, session)
    
    49
    +    def __init__(self, parent_win, jid, account):
    
    50
    +        client = app.get_client(account)
    
    51
    +        self._room_contact = client.get_module('Contacts').get_contact(jid.bare)
    
    52
    +        self._manager = client.get_module('MUC').get_manager()
    
    53
    +
    
    54
    +        ChatControl.__init__(self, parent_win, jid, account, None)
    
    54 55
     
    
    55
    -        # pylint: disable=line-too-long
    
    56 56
             # self.register_events([
    
    57 57
             #     ('update-gc-avatar', ged.GUI1, self._on_update_gc_avatar),
    
    58 58
             #     ('caps-update', ged.GUI1, self._on_caps_update),
    
    59
    -        #     ('muc-user-joined', ged.GUI1, self._on_user_joined),
    
    60
    -        #     ('muc-user-left', ged.GUI1, self._on_user_left),
    
    61
    -        #     ('muc-nickname-changed', ged.GUI1, self._on_nickname_changed),
    
    62
    -        #     ('muc-self-presence', ged.GUI1, self._on_self_presence),
    
    63
    -        #     ('muc-self-kicked', ged.GUI1, self._on_disconnected),
    
    64
    -        #     ('muc-user-status-show-changed', ged.GUI1, self._on_status_show_changed),
    
    65
    -        #     ('muc-destroyed', ged.GUI1, self._on_disconnected),
    
    66
    -        # ])
    
    67
    -        # pylint: enable=line-too-long
    
    68
    -
    
    69
    -    @property
    
    70
    -    def contact(self):
    
    71
    -        return self.gc_contact.as_contact()
    
    72 59
     
    
    73
    -    @contact.setter
    
    74
    -    def contact(self, _value):
    
    75
    -        # TODO: remove all code that sets the contact here
    
    76
    -        return
    
    60
    +    def _connect_contact_signals(self):
    
    61
    +        self.contact.multi_connect({
    
    62
    +            'user-avatar-update': self._on_user_avatar_update,
    
    63
    +            'user-joined': self._on_user_joined,
    
    64
    +            'user-left': self._on_user_left,
    
    65
    +            'user-status-show-changed': self._on_user_status_show_changed,
    
    66
    +            'user-nickname-changed': self._on_user_nickname_changed,
    
    67
    +            # 'room-kicked': self._on_room_kicked,
    
    68
    +            # 'room-destroyed': self._on_room_destroyed,
    
    69
    +            'room-joined': self._on_room_joined,
    
    70
    +            # 'room-left': self._on_room_left
    
    71
    +            'chatstate-update': self._on_chatstate_update,
    
    72
    +        })
    
    77 73
     
    
    78 74
         @property
    
    79 75
         def room_name(self):
    
    80
    -        if self.room_ctrl is not None:
    
    81
    -            return self.room_ctrl.room_name
    
    82
    -        return self.gc_contact.room_jid
    
    76
    +        return self._room_contact.name
    
    83 77
     
    
    84 78
         def get_our_nick(self):
    
    85
    -        return self.room_ctrl.nick
    
    86
    -
    
    87
    -    def _on_caps_update(self, event):
    
    88
    -        if event.fjid != self.gc_contact.get_full_jid():
    
    89
    -            return
    
    90
    -        self.update_contact()
    
    91
    -
    
    92
    -    def _on_nickname_changed(self, event):
    
    93
    -        if event.properties.new_jid != self.gc_contact.get_full_jid():
    
    94
    -            return
    
    95
    -
    
    96
    -        nick = event.properties.muc_nickname
    
    97
    -        new_nick = event.properties.muc_user.nick
    
    98
    -        if event.properties.is_muc_self_presence:
    
    79
    +        muc_data = self._manager.get(self._room_contact.jid)
    
    80
    +        return muc_data.nick
    
    81
    +
    
    82
    +    def _on_user_nickname_changed(self,
    
    83
    +                                  _contact,
    
    84
    +                                  _signal_name,
    
    85
    +                                  _user_contact,
    
    86
    +                                  properties):
    
    87
    +
    
    88
    +        nick = properties.muc_nickname
    
    89
    +        new_nick = properties.muc_user.nick
    
    90
    +        if properties.is_muc_self_presence:
    
    99 91
                 message = _('You are now known as %s') % new_nick
    
    100 92
             else:
    
    101 93
                 message = _('{nick} is now known '
    
    ... ... @@ -104,31 +96,23 @@ def _on_nickname_changed(self, event):
    104 96
             self.add_info_message(message)
    
    105 97
     
    
    106 98
             self.draw_banner()
    
    107
    -        app.interface.msg_win_mgr.change_key(str(event.properties.jid),
    
    108
    -                                             str(event.properties.new_jid),
    
    109
    -                                             self.account)
    
    110
    -
    
    111
    -        self.parent_win.redraw_tab(self)
    
    112 99
             self.update_ui()
    
    113 100
     
    
    114
    -    @event_filter(['account'])
    
    115
    -    def _on_status_show_changed(self, event):
    
    116
    -        if event.properties.jid != self.gc_contact.get_full_jid():
    
    117
    -            return
    
    118
    -
    
    119
    -        nick = event.properties.muc_nickname
    
    120
    -        status = event.properties.status
    
    101
    +    def _on_user_status_show_changed(self,
    
    102
    +                                     _contact,
    
    103
    +                                     _signal_name,
    
    104
    +                                     _user_contact,
    
    105
    +                                     properties):
    
    106
    +        nick = properties.muc_nickname
    
    107
    +        status = properties.status
    
    121 108
             status = '' if status is None else ' - %s' % status
    
    122
    -        show = helpers.get_uf_show(event.properties.show.value)
    
    109
    +        show = helpers.get_uf_show(properties.show.value)
    
    123 110
     
    
    124
    -        if not app.settings.get_group_chat_setting(self.account,
    
    125
    -                                                   self.gc_contact.room_jid,
    
    126
    -                                                   'print_status'):
    
    127
    -            self.parent_win.redraw_tab(self)
    
    111
    +        if not self._room_contact.settings.get('print_status'):
    
    128 112
                 self.update_ui()
    
    129 113
                 return
    
    130 114
     
    
    131
    -        if event.properties.is_muc_self_presence:
    
    115
    +        if properties.is_muc_self_presence:
    
    132 116
                 message = _('You are now {show}{status}').format(show=show,
    
    133 117
                                                                  status=status)
    
    134 118
     
    
    ... ... @@ -137,46 +121,24 @@ def _on_status_show_changed(self, event):
    137 121
                                                                    show=show,
    
    138 122
                                                                    status=status)
    
    139 123
             self.add_status_message(message)
    
    140
    -        self.parent_win.redraw_tab(self)
    
    141 124
             self.update_ui()
    
    142 125
     
    
    143
    -    @event_filter(['account'])
    
    144
    -    def _on_disconnected(self, event):
    
    145
    -        if event.properties.jid != self.gc_contact.get_full_jid():
    
    146
    -            return
    
    126
    +    # def _on_disconnected(self, event):
    
    127
    +    #     if event.properties.jid != self.gc_contact.get_full_jid():
    
    128
    +    #         return
    
    129
    +    #     self.got_disconnected()
    
    147 130
     
    
    131
    +    def _on_user_left(self, *args):
    
    148 132
             self.got_disconnected()
    
    149 133
     
    
    150
    -    @event_filter(['account'])
    
    151
    -    def _on_user_left(self, event):
    
    152
    -        if event.properties.jid != self.gc_contact.get_full_jid():
    
    153
    -            return
    
    154
    -
    
    155
    -        self.got_disconnected()
    
    156
    -
    
    157
    -    @event_filter(['account'])
    
    158
    -    def _on_user_joined(self, event):
    
    159
    -        if event.properties.jid != self.gc_contact.get_full_jid():
    
    160
    -            return
    
    161
    -
    
    162
    -        self.gc_contact = app.contacts.get_gc_contact(
    
    163
    -            self.account, self.gc_contact.room_jid, self.gc_contact.name)
    
    164
    -        self.parent_win.redraw_tab(self)
    
    134
    +    def _on_user_joined(self, *args):
    
    165 135
             self.got_connected()
    
    166 136
     
    
    167
    -    @event_filter(['account'])
    
    168
    -    def _on_self_presence(self, event):
    
    169
    -        if event.properties.jid != self.gc_contact.get_full_jid():
    
    137
    +    def _on_room_joined(self, *args):
    
    138
    +        if not self.contact.is_available:
    
    170 139
                 return
    
    171
    -
    
    172
    -        self.parent_win.redraw_tab(self)
    
    173 140
             self.got_connected()
    
    174 141
     
    
    175
    -    def _on_update_gc_avatar(self, event):
    
    176
    -        if event.contact != self.gc_contact:
    
    177
    -            return
    
    178
    -        self._update_avatar()
    
    179
    -
    
    180 142
         def send_message(self, message, xhtml=None, process_commands=True,
    
    181 143
                          attention=False):
    
    182 144
             """
    
    ... ... @@ -188,14 +150,13 @@ def send_message(self, message, xhtml=None, process_commands=True,
    188 150
     
    
    189 151
             # We need to make sure that we can still send through the room and that
    
    190 152
             # the recipient did not go away
    
    191
    -        if self.gc_contact.presence.is_unavailable:
    
    153
    +        if not self.contact.is_available:
    
    192 154
                 ErrorDialog(
    
    193 155
                     _('Sending private message failed'),
    
    194 156
                     #in second %s code replaces with nickname
    
    195 157
                     _('You are no longer in group chat "%(room)s" or '
    
    196 158
                       '"%(nick)s" has left.') % {
    
    197
    -                      'room': self.room_name, 'nick': self.gc_contact.name},
    
    198
    -                transient_for=self.parent_win.window)
    
    159
    +                      'room': self.room_name, 'nick': self.contact.name})
    
    199 160
                 return
    
    200 161
     
    
    201 162
             ChatControl.send_message(self, message,
    
    ... ... @@ -204,35 +165,16 @@ def send_message(self, message, xhtml=None, process_commands=True,
    204 165
                                      attention=attention)
    
    205 166
     
    
    206 167
         def update_ui(self):
    
    207
    -        if self.gc_contact.presence.is_unavailable:
    
    168
    +        if not self.contact.is_available:
    
    208 169
                 self.got_disconnected()
    
    209 170
             else:
    
    210 171
                 self.got_connected()
    
    211 172
     
    
    212
    -    def _update_avatar(self):
    
    213
    -        scale = self.parent_win.window.get_scale_factor()
    
    214
    -        surface = self.gc_contact.get_avatar(AvatarSize.CHAT,
    
    215
    -                                             scale,
    
    216
    -                                             self.gc_contact.show.value)
    
    217
    -
    
    218
    -        self.xml.avatar_image.set_from_surface(surface)
    
    219
    -
    
    220
    -    def get_tab_image(self):
    
    221
    -        if self.gc_contact.presence.is_unavailable:
    
    222
    -            show = 'offline'
    
    223
    -        else:
    
    224
    -            show = self.gc_contact.show.value
    
    225
    -        scale = self.parent_win.window.get_scale_factor()
    
    226
    -        return self.gc_contact.get_avatar(AvatarSize.ROSTER,
    
    227
    -                                          scale,
    
    228
    -                                          show)
    
    229
    -
    
    230
    -    def update_contact(self):
    
    231
    -        self.contact = self.gc_contact.as_contact()
    
    173
    +    def _on_user_avatar_update(self, *args):
    
    174
    +        self._update_avatar()
    
    232 175
     
    
    233 176
         def got_disconnected(self):
    
    234 177
             ChatControl.got_disconnected(self)
    
    235
    -        self.parent_win.redraw_tab(self)
    
    236 178
             ChatControl.update_ui(self)
    
    237 179
     
    
    238 180
         def got_connected(self):