Ejemplo n.º 1
0
 def on_muc_msg(self, message, tab):
     fro = message['from'].bare
     # Prevent old messages to be notified
     # find_delayed_tag(message) returns (True, the datetime) or
     # (False, None)
     if not common.find_delayed_tag(message)[0]:
         self.do_notify(message, fro)
Ejemplo n.º 2
0
 def on_muc_msg(self, message, tab):
     fro = message['from'].bare
     # Prevent old messages to be notified
     # find_delayed_tag(message) returns (True, the datetime) or
     # (False, None)
     if not common.find_delayed_tag(message)[0]:
         self.do_notify(message, fro)
Ejemplo n.º 3
0
def on_groupchat_message(self, message):
    """
    Triggered whenever a message is received from a multi-user chat room.
    """
    if message['subject']:
        return
    room_from = message['from'].bare

    if message['type'] == 'error': # Check if it's an error
        return self.room_error(message, room_from)

    tab = self.get_tab_by_name(room_from, tabs.MucTab)
    if not tab:
        self.information(_("message received for a non-existing room: %s") % (room_from))
        muc.leave_groupchat(self.xmpp, room_from, self.own_nick, msg='')
        return

    nick_from = message['mucnick']
    user = tab.get_user_by_name(nick_from)
    if user and user in tab.ignores:
        return

    self.events.trigger('muc_msg', message, tab)
    use_xhtml = config.get('enable_xhtml_im')
    tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images')
    extract_images = config.get('extract_inline_images')
    body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
                                              tmp_dir=tmp_dir,
                                              extract_images=extract_images)
    if not body:
        return

    old_state = tab.state
    delayed, date = common.find_delayed_tag(message)
    replaced_id = message['replace']['id']
    replaced = False
    if replaced_id is not '' and config.get_by_tabname('group_corrections',
                                                       message['from'].bare):
        try:
            if tab.modify_message(body, replaced_id, message['id'], time=date,
                    nickname=nick_from, user=user):
                self.events.trigger('highlight', message, tab)
            replaced = True
        except CorrectionError:
            log.debug('Unable to correct a message', exc_info=True)
    if not replaced and tab.add_message(body, date, nick_from, history=delayed, identifier=message['id'], jid=message['from'], typ=1):
        self.events.trigger('highlight', message, tab)

    if message['from'].resource == tab.own_nick:
        tab.last_sent_message = message

    if tab is self.current_tab():
        tab.text_win.refresh()
        tab.info_header.refresh(tab, tab.text_win)
        tab.input.refresh()
        self.doupdate()
    elif tab.state != old_state:
        self.refresh_tab_win()
        current = self.current_tab()
        if hasattr(current, 'input') and current.input:
            current.input.refresh()
        self.doupdate()

    if 'message' in config.get('beep_on').split():
        if (not config.get_by_tabname('disable_beep', room_from)
                and self.own_nick != message['from'].resource):
            curses.beep()
Ejemplo n.º 4
0
def on_normal_message(self, message):
    """
    When receiving "normal" messages (not a private message from a
    muc participant)
    """
    if message['type'] == 'error':
        return self.information(self.get_error_message(message, deprecated=True), 'Error')
    elif message['type'] == 'headline' and message['body']:
        return self.information('%s says: %s' % (message['from'], message['body']), 'Headline')

    use_xhtml = config.get('enable_xhtml_im')
    tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images')
    extract_images = config.get('extract_inline_images')
    body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
                                              tmp_dir=tmp_dir,
                                              extract_images=extract_images)
    if not body:
        return

    remote_nick = ''
    # normal message, we are the recipient
    if message['to'].bare == self.xmpp.boundjid.bare:
        conv_jid = message['from']
        jid = conv_jid
        color = get_theme().COLOR_REMOTE_USER
        # check for a name
        if conv_jid.bare in roster:
            remote_nick = roster[conv_jid.bare].name
        # check for a received nick
        if not remote_nick and config.get('enable_user_nick'):
            if message.xml.find('{http://jabber.org/protocol/nick}nick') is not None:
                remote_nick = message['nick']['nick']
        if not remote_nick:
            remote_nick = conv_jid.user
            if not remote_nick:
                remote_nick = conv_jid.full
        own = False
    # we wrote the message (happens with carbons)
    elif message['from'].bare == self.xmpp.boundjid.bare:
        conv_jid = message['to']
        jid = self.xmpp.boundjid
        color = get_theme().COLOR_OWN_NICK
        remote_nick = self.own_nick
        own = True
    # we are not part of that message, drop it
    else:
        return

    conversation = self.get_conversation_by_jid(conv_jid, create=True)
    if isinstance(conversation, tabs.DynamicConversationTab) and conv_jid.resource:
        conversation.lock(conv_jid.resource)

    if not own and not conversation.nick:
        conversation.nick = remote_nick
    elif not own: # keep a fixed nick during the whole conversation
        remote_nick = conversation.nick

    self.events.trigger('conversation_msg', message, conversation)
    if not message['body']:
        return
    body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml,
                                              tmp_dir=tmp_dir,
                                              extract_images=extract_images)
    delayed, date = common.find_delayed_tag(message)

    def try_modify():
        replaced_id = message['replace']['id']
        if replaced_id and config.get_by_tabname('group_corrections',
                                                 conv_jid.bare):
            try:
                conversation.modify_message(body, replaced_id, message['id'], jid=jid,
                        nickname=remote_nick)
                return True
            except CorrectionError:
                log.debug('Unable to correct a message', exc_info=True)
        return False

    if not try_modify():
        conversation.add_message(body, date,
                nickname=remote_nick,
                nick_color=color,
                history=delayed,
                identifier=message['id'],
                jid=jid,
                typ=1)

    if conversation.remote_wants_chatstates is None and not delayed:
        if message['chat_state']:
            conversation.remote_wants_chatstates = True
        else:
            conversation.remote_wants_chatstates = False
    if 'private' in config.get('beep_on').split():
        if not config.get_by_tabname('disable_beep', conv_jid.bare):
            curses.beep()
    if self.current_tab() is not conversation:
        conversation.state = 'private'
        self.refresh_tab_win()
    else:
        self.refresh_window()