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

Commits:

3 changed files:

Changes:

  • gajim/common/connection_handlers_events.py
    ... ... @@ -1114,27 +1114,23 @@ class NotificationEvent(nec.NetworkIncomingEvent):
    1114 1114
             else:
    
    1115 1115
                 # We don't want message preview, do_preview = False
    
    1116 1116
                 self.popup_text = ''
    
    1117
    +
    
    1117 1118
             if msg_obj.mtype == 'normal': # single message
    
    1118 1119
                 self.popup_msg_type = 'normal'
    
    1119 1120
                 self.popup_event_type = _('New Single Message')
    
    1120
    -            self.popup_title = _('New Single Message from %(nickname)s') % \
    
    1121
    -                {'nickname': nick}
    
    1122 1121
             elif msg_obj.mtype == 'pm':
    
    1123 1122
                 self.popup_msg_type = 'pm'
    
    1124 1123
                 self.popup_event_type = _('New Private Message')
    
    1125
    -            self.popup_title = _('New Private Message from group chat %s') % \
    
    1126
    -                msg_obj.jid
    
    1127
    -            if self.popup_text:
    
    1128
    -                self.popup_text = _('%(nickname)s: %(message)s') % \
    
    1129
    -                    {'nickname': nick, 'message': self.popup_text}
    
    1130
    -            else:
    
    1131
    -                self.popup_text = _('Messaged by %(nickname)s') % \
    
    1132
    -                    {'nickname': nick}
    
    1133 1124
             else: # chat message
    
    1134 1125
                 self.popup_msg_type = 'chat'
    
    1135 1126
                 self.popup_event_type = _('New Message')
    
    1136
    -            self.popup_title = _('New Message from %(nickname)s') % \
    
    1137
    -                {'nickname': nick}
    
    1127
    +
    
    1128
    +        num_unread = len(app.events.get_events(self.conn.name, self.jid,
    
    1129
    +            ['printed_' + self.popup_msg_type, self.popup_msg_type]))
    
    1130
    +        self.popup_title = i18n.ngettext(
    
    1131
    +            'New message from %(nickname)s',
    
    1132
    +            '%(n_msgs)i unread messages from %(nickname)s',
    
    1133
    +            num_unread) % {'nickname': nick, 'n_msgs': num_unread}
    
    1138 1134
     
    
    1139 1135
             if app.config.get('notify_on_new_message'):
    
    1140 1136
                 if self.first_unread or (app.config.get('autopopup_chat_opened') \
    

  • gajim/gui_interface.py
    ... ... @@ -658,9 +658,11 @@ class Interface:
    658 658
     
    
    659 659
             if helpers.allow_showing_notification(obj.account):
    
    660 660
                 event_type = _('Groupchat Invitation')
    
    661
    +            text = _('Your are invited to {room} by {user}').format(
    
    662
    +                room=obj.room_jid, user=str(obj.from_))
    
    661 663
                 app.notification.popup(
    
    662
    -                event_type, str(obj.from_), obj.account, 'gc-invitation',
    
    663
    -                'gajim-gc_invitation', event_type, obj.room_jid)
    
    664
    +                event_type, obj.room_jid, obj.account, 'gc-invitation',
    
    665
    +                'gajim-gc_invitation', event_type, text)
    
    664 666
     
    
    665 667
         def forget_gpg_passphrase(self, keyid):
    
    666 668
             if keyid in self.gpg_passphrase:
    

  • gajim/notify.py
    ... ... @@ -74,6 +74,9 @@ class Notification:
    74 74
         def __init__(self):
    
    75 75
             app.ged.register_event_handler(
    
    76 76
                 'notification', ged.GUI2, self._nec_notification)
    
    77
    +        app.ged.register_event_handler(
    
    78
    +            'our-show', ged.GUI2, self._nec_our_status)
    
    79
    +        app.events.event_removed_subscribe(self._on_event_removed)
    
    77 80
     
    
    78 81
         def _nec_notification(self, obj):
    
    79 82
             if obj.do_popup:
    
    ... ... @@ -95,6 +98,18 @@ class Notification:
    95 98
                 except Exception:
    
    96 99
                     pass
    
    97 100
     
    
    101
    +    def _on_event_removed(self, event_list):
    
    102
    +        for event in event_list:
    
    103
    +            if event.type_ == 'gc-invitation':
    
    104
    +                self.withdraw('gc-invitation', event.account, event.room_jid)
    
    105
    +            if event.type_ in ('normal', 'printed_chat', 'chat',
    
    106
    +            'printed_pm', 'pm'):
    
    107
    +                self.withdraw('new-message', event.account, event.jid)
    
    108
    +
    
    109
    +    def _nec_our_status(self, obj):
    
    110
    +        if app.account_is_connected(obj.conn.name):
    
    111
    +            self.withdraw('connection-failed', obj.conn.name)
    
    112
    +
    
    98 113
         def _get_icon_name(self, obj):
    
    99 114
             if obj.notif_type == 'msg':
    
    100 115
                 if obj.base_event.mtype == 'pm':
    
    ... ... @@ -153,13 +168,28 @@ class Notification:
    153 168
                 #Button in notification
    
    154 169
                 notification.add_button_with_target(_('Open'), action, variant_dict)
    
    155 170
                 notification.set_default_action_and_target(action, variant_dict)
    
    156
    -            if event_type in (_('New Message'), _('New Single Message'),
    
    171
    +
    
    172
    +            # Only one notification per JID
    
    173
    +            if event_type in (_('Contact Signed In'), _('Contact Signed Out'),
    
    174
    +            _('Contact Changed Status')):
    
    175
    +                notif_id = self._id('contact-status-changed', account, jid)
    
    176
    +            elif event_type == _('Groupchat Invitation'):
    
    177
    +                notif_id = self._id('gc-invitation', account, jid)
    
    178
    +            elif event_type == _('Connection Failed'):
    
    179
    +                notif_id = self._id('connection-failed', account)
    
    180
    +            elif event_type in (_('New Message'), _('New Single Message'),
    
    157 181
                 _('New Private Message')):
    
    158
    -                # Only one notification per JID
    
    159
    -                notif_id = jid
    
    182
    +                notif_id = self._id('new-message', account, jid)
    
    183
    +
    
    160 184
             notification.set_priority(Gio.NotificationPriority.NORMAL)
    
    161 185
             app.app.send_notification(notif_id, notification)
    
    162 186
     
    
    187
    +    def withdraw(self, *args):
    
    188
    +        if sys.platform != 'win32':
    
    189
    +            app.app.withdraw_notification(self._id(*args))
    
    190
    +
    
    191
    +    def _id(self, *args):
    
    192
    +        return ','.join(args)
    
    163 193
     
    
    164 194
     class PopupNotificationWindow:
    
    165 195
         def __init__(self, event_type, jid, account, msg_type='',