def _on_event(self, conv_event): """Create notification for new messages.""" conv = self._conv_list.get(conv_event.conversation_id) user = conv.get_user(conv_event.user_id) # Ignore non-messages or messages sent by yourself. if (not user.is_self and isinstance(conv_event, hangups.ChatMessageEvent)): # We have to escape angle brackets because freedesktop.org # notifications support markup. cmd = [ arg.format( sender_name=NOTIFY_ESCAPER(user.full_name), msg_text=NOTIFY_ESCAPER(conv_event.text), replaces_id=self._replaces_id, convo_name=NOTIFY_ESCAPER(get_conv_name(conv)), ) for arg in NOTIFY_CMD ] # Run the notification and parse out the replaces_id. Since the # command is a list of arguments, and we're not using a shell, this # should be safe. logger.info('Creating notification with command: {}'.format(cmd)) try: output = subprocess.check_output( cmd, stderr=subprocess.STDOUT).decode() except (subprocess.CalledProcessError, FileNotFoundError) as e: logger.warning('Notification command failed: {}'.format(e)) return try: self._replaces_id = RESULT_RE.match(output).groups()[0] except (AttributeError, IndexError) as e: logger.warning('Failed to parse notification command ' 'result: {}'.format(e))
def _on_event(self, conv_event): """Create notification for new messages.""" conv = self._conv_list.get(conv_event.conversation_id) user = conv.get_user(conv_event.user_id) # Ignore non-messages or messages sent by yourself. if (not user.is_self and isinstance(conv_event, hangups.ChatMessageEvent)): # We have to escape angle brackets because freedesktop.org # notifications support markup. cmd = [arg.format( sender_name=NOTIFY_ESCAPER(user.full_name), msg_text=NOTIFY_ESCAPER(conv_event.text), replaces_id=self._replaces_id, convo_name=NOTIFY_ESCAPER(get_conv_name(conv)), ) for arg in NOTIFY_CMD] # Run the notification and parse out the replaces_id. Since the # command is a list of arguments, and we're not using a shell, this # should be safe. logger.info('Creating notification with command: {}'.format(cmd)) try: output = subprocess.check_output( cmd, stderr=subprocess.STDOUT ).decode() except (subprocess.CalledProcessError, FileNotFoundError) as e: logger.warning('Notification command failed: {}'.format(e)) return try: self._replaces_id = RESULT_RE.match(output).groups()[0] except (AttributeError, IndexError) as e: logger.warning('Failed to parse notification command ' 'result: {}'.format(e))
def __init__(self, conversation_list, on_select): # Build buttons for selecting conversations ordered by most recently # modified first. convs = sorted(conversation_list.get_all(), reverse=True, key=lambda c: c.last_modified) on_press = lambda button, conv_id: on_select(conv_id) buttons = [urwid.Button(get_conv_name(conv), on_press=on_press, user_data=conv.id_) for conv in convs] listbox = urwid.ListBox(urwid.SimpleFocusListWalker(buttons)) widget = urwid.Padding(listbox, left=2, right=2) super().__init__(widget)
def _set_title(self): """Update this conversation's tab title.""" title = get_conv_name(self._conversation, truncate=True) if self._num_unread > 0: title += ' ({})'.format(self._num_unread) self._set_title_cb(self, title)