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

Commits:

5 changed files:

Changes:

  • gajim/chat_control.py
    ... ... @@ -1405,17 +1405,19 @@ def got_disconnected(self):
    1405 1405
             ChatControlBase.got_disconnected(self)
    
    1406 1406
             self.update_actions()
    
    1407 1407
     
    
    1408
    -    def update_status_display(self, name, uf_show, status):
    
    1408
    +    def _on_presence_received(self, event):
    
    1409
    +        uf_show = helpers.get_uf_show(event.show)
    
    1410
    +        name = self.contact.get_shown_name()
    
    1411
    +
    
    1409 1412
             self.update_ui()
    
    1410 1413
             self.parent_win.redraw_tab(self)
    
    1411 1414
     
    
    1412 1415
             if not app.settings.get('print_status_in_chats'):
    
    1413 1416
                 return
    
    1414 1417
     
    
    1415
    -        if status:
    
    1416
    -            status = '- %s' % status
    
    1418
    +        status = '- %s' % event.status if event.status else ''
    
    1417 1419
             status_line = _('%(name)s is now %(show)s %(status)s') % {
    
    1418
    -            'name': name, 'show': uf_show, 'status': status or ''}
    
    1420
    +            'name': name, 'show': uf_show, 'status': status}
    
    1419 1421
             self.add_status_message(status_line)
    
    1420 1422
     
    
    1421 1423
         def _info_bar_show_message(self):
    

  • gajim/common/modules/presence.py
    ... ... @@ -108,6 +108,7 @@ def _presence_received(self, _con, stanza, properties):
    108 108
                 show = 'offline'
    
    109 109
     
    
    110 110
             event_attrs = {
    
    111
    +            'account': self._account,
    
    111 112
                 'conn': self._con,
    
    112 113
                 'stanza': stanza,
    
    113 114
                 'prio': properties.priority,
    
    ... ... @@ -132,7 +133,6 @@ def _presence_received(self, _con, stanza, properties):
    132 133
     
    
    133 134
             event_ = NetworkEvent('presence-received', **event_attrs)
    
    134 135
     
    
    135
    -        # TODO: Refactor
    
    136 136
             self._update_contact(event_, properties)
    
    137 137
     
    
    138 138
             app.nec.push_incoming_event(event_)
    

  • gajim/gtk/chat_list.py
    ... ... @@ -141,6 +141,8 @@ def process_event(self, event):
    141 141
                               'mam-message-received',
    
    142 142
                               'gc-message-received'):
    
    143 143
                 self._on_message_received(event)
    
    144
    +        elif event.name == 'presence-received':
    
    145
    +            self._on_presence_received(event)
    
    144 146
             else:
    
    145 147
                 log.warning('Unhandled Event: %s', event.name)
    
    146 148
     
    
    ... ... @@ -153,6 +155,10 @@ def _on_message_received(self, event):
    153 155
     
    
    154 156
             self._add_unread(row, event.properties)
    
    155 157
     
    
    158
    +    def _on_presence_received(self, event):
    
    159
    +        row = self._chats.get((event.account, event.jid))
    
    160
    +        row.update_avatar()
    
    161
    +
    
    156 162
         @staticmethod
    
    157 163
         def _add_unread(row, properties):
    
    158 164
             if properties.is_carbon_message and properties.carbon.is_sent:
    
    ... ... @@ -189,33 +195,8 @@ def __init__(self, workspace_id, account, jid, type_):
    189 195
             if len(app.get_enabled_accounts_with_labels()) > 1:
    
    190 196
                 self._ui.account_identifier.show()
    
    191 197
     
    
    192
    -        contact = app.contacts.get_contact(account, jid)
    
    193
    -
    
    194
    -        scale = self.get_scale_factor()
    
    195
    -        if contact:
    
    196
    -            if contact.is_groupchat:
    
    197
    -                avatar = app.contacts.get_avatar(account,
    
    198
    -                                                jid,
    
    199
    -                                                AvatarSize.ROSTER,
    
    200
    -                                                scale)
    
    201
    -                con = app.connections[account]
    
    202
    -                name = get_groupchat_name(con, jid)
    
    203
    -            else:
    
    204
    -                avatar = app.contacts.get_avatar(account,
    
    205
    -                                                 contact.jid,
    
    206
    -                                                 AvatarSize.ROSTER,
    
    207
    -                                                 scale,
    
    208
    -                                                 contact.show)
    
    209
    -                name = contact.get_shown_name()
    
    210
    -        else:
    
    211
    -            avatar = app.contacts.get_avatar(account,
    
    212
    -                                             jid,
    
    213
    -                                             AvatarSize.ROSTER,
    
    214
    -                                             scale)
    
    215
    -            name = jid
    
    216
    -
    
    217
    -        self._ui.avatar_image.set_from_surface(avatar)
    
    218
    -        self._ui.name_label.set_text(name)
    
    198
    +        self.update_avatar()
    
    199
    +        self.update_name()
    
    219 200
     
    
    220 201
             # Get last chat message from archive
    
    221 202
             line = app.storage.archive.get_last_conversation_line(account, jid)
    
    ... ... @@ -244,6 +225,44 @@ def __init__(self, workspace_id, account, jid, type_):
    244 225
     
    
    245 226
             self.show_all()
    
    246 227
     
    
    228
    +    def update_avatar(self):
    
    229
    +        contact = app.contacts.get_contact(self.account, self.jid)
    
    230
    +
    
    231
    +        scale = self.get_scale_factor()
    
    232
    +        if contact:
    
    233
    +            if contact.is_groupchat:
    
    234
    +                avatar = app.contacts.get_avatar(self.account,
    
    235
    +                                                 self.jid,
    
    236
    +                                                 AvatarSize.ROSTER,
    
    237
    +                                                 scale)
    
    238
    +            else:
    
    239
    +                avatar = app.contacts.get_avatar(self.account,
    
    240
    +                                                 contact.jid,
    
    241
    +                                                 AvatarSize.ROSTER,
    
    242
    +                                                 scale,
    
    243
    +                                                 contact.show)
    
    244
    +        else:
    
    245
    +            avatar = app.contacts.get_avatar(self.account,
    
    246
    +                                             self.jid,
    
    247
    +                                             AvatarSize.ROSTER,
    
    248
    +                                             scale)
    
    249
    +
    
    250
    +        self._ui.avatar_image.set_from_surface(avatar)
    
    251
    +
    
    252
    +    def update_name(self):
    
    253
    +        contact = app.contacts.get_contact(self.account, self.jid)
    
    254
    +        if contact is None:
    
    255
    +            self._ui.name_label.set_text(self.jid)
    
    256
    +            return
    
    257
    +
    
    258
    +        if contact.is_groupchat:
    
    259
    +            client = app.get_client(self.account)
    
    260
    +            name = get_groupchat_name(client, self.jid)
    
    261
    +        else:
    
    262
    +            name = contact.get_shown_name()
    
    263
    +
    
    264
    +        self._ui.name_label.set_text(name)
    
    265
    +
    
    247 266
         @property
    
    248 267
         def unread_count(self):
    
    249 268
             return self._unread_count
    

  • gajim/gtk/chat_list_stack.py
    ... ... @@ -11,6 +11,7 @@
    11 11
         'message-received',
    
    12 12
         'mam-message-received',
    
    13 13
         'gc-message-received',
    
    14
    +    'presence-received',
    
    14 15
     ]
    
    15 16
     
    
    16 17
     
    
    ... ... @@ -162,4 +163,6 @@ def process_event(self, event):
    162 163
                 return
    
    163 164
     
    
    164 165
             chat_list = self._find_chat(event.account, event.jid)
    
    166
    +        if chat_list is None:
    
    167
    +            return
    
    165 168
             chat_list.process_event(event)

  • gajim/gtk/main.py
    ... ... @@ -67,6 +67,7 @@ def __init__(self):
    67 67
     
    
    68 68
             # pylint: disable=line-too-long
    
    69 69
             self.register_events([
    
    70
    +            ('presence-received', ged.GUI1, self._on_event),
    
    70 71
                 ('nickname-received', ged.GUI1, self._on_event),
    
    71 72
                 ('mood-received', ged.GUI1, self._on_event),
    
    72 73
                 ('activity-received', ged.GUI1, self._on_event),