Example #1
0
def test_poezio_colors_to_html():
    base = "<body xmlns='http://www.w3.org/1999/xhtml'><p>"
    end = "</p></body>"
    text = '\x191}coucou'
    assert poezio_colors_to_html(text) == base + '<span style="color: red;">coucou</span>' + end

    text = '\x19bcoucou\x19o toto \x194}titi'
    assert poezio_colors_to_html(text) == base + '<span style="font-weight: bold;">coucou</span> toto <span style="color: blue;">titi</span>' + end

    text = '\x19icoucou'
    assert poezio_colors_to_html(text) == base + '<span style="font-style: italic;">coucou</span>' + end
Example #2
0
def test_poezio_colors_to_html():
    base = "<body xmlns='http://www.w3.org/1999/xhtml'><p>"
    end = "</p></body>"
    text = '\x191}coucou'
    assert poezio_colors_to_html(
        text) == base + '<span style="color: red;">coucou</span>' + end

    text = '\x19bcoucou\x19o toto \x194}titi'
    assert poezio_colors_to_html(
        text
    ) == base + '<span style="font-weight: bold;">coucou</span> toto <span style="color: blue;">titi</span>' + end
Example #3
0
    def command_say(self, line, attention=False, correct=False):
        msg = self.core.xmpp.make_message(self.get_dest_jid())
        msg['type'] = 'chat'
        msg['body'] = line
        if not self.nick_sent:
            msg['nick'] = self.core.own_nick
            self.nick_sent = True
        # trigger the event BEFORE looking for colors.
        # and before displaying the message in the window
        # This lets a plugin insert \x19xxx} colors, that will
        # be converted in xhtml.
        self.core.events.trigger('conversation_say', msg, self)
        if not msg['body']:
            self.cancel_paused_delay()
            self.text_win.refresh()
            self.input.refresh()
            return
        replaced = False
        if correct or msg['replace']['id']:
            msg['replace']['id'] = self.last_sent_message['id']
            if config.get_by_tabname('group_corrections', self.name):
                try:
                    self.modify_message(msg['body'], self.last_sent_message['id'], msg['id'], jid=self.core.xmpp.boundjid,
                            nickname=self.core.own_nick)
                    replaced = True
                except CorrectionError:
                    log.error('Unable to correct a message', exc_info=True)
        else:
            del msg['replace']
        if msg['body'].find('\x19') != -1:
            msg.enable('html')
            msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
            msg['body'] = xhtml.clean_text(msg['body'])
        if (config.get_by_tabname('send_chat_states', self.general_jid) and
                self.remote_wants_chatstates is not False):
            needed = 'inactive' if self.inactive else 'active'
            msg['chat_state'] = needed
        if attention and self.remote_supports_attention:
            msg['attention'] = True
        self.core.events.trigger('conversation_say_after', msg, self)
        if not msg['body']:
            self.cancel_paused_delay()
            self.text_win.refresh()
            self.input.refresh()
            return
        if not replaced:
            self.add_message(msg['body'],
                    nickname=self.core.own_nick,
                    nick_color=get_theme().COLOR_OWN_NICK,
                    identifier=msg['id'],
                    jid=self.core.xmpp.boundjid,
                    typ=1)

        self.last_sent_message = msg
        if self.remote_supports_receipts:
            msg._add_receipt = True
        msg.send()
        self.cancel_paused_delay()
        self.text_win.refresh()
        self.input.refresh()
    def command_say(self, line, attention=False, correct=False):
        msg = self.core.xmpp.make_message(self.get_dest_jid())
        msg['type'] = 'chat'
        msg['body'] = line
        if not self.nick_sent:
            msg['nick'] = self.core.own_nick
            self.nick_sent = True
        # trigger the event BEFORE looking for colors.
        # and before displaying the message in the window
        # This lets a plugin insert \x19xxx} colors, that will
        # be converted in xhtml.
        self.core.events.trigger('conversation_say', msg, self)
        if not msg['body']:
            self.cancel_paused_delay()
            self.text_win.refresh()
            self.input.refresh()
            return
        replaced = False
        if correct or msg['replace']['id']:
            msg['replace']['id'] = self.last_sent_message['id']
            if config.get_by_tabname('group_corrections', self.name):
                try:
                    self.modify_message(msg['body'], self.last_sent_message['id'], msg['id'], jid=self.core.xmpp.boundjid,
                            nickname=self.core.own_nick)
                    replaced = True
                except:
                    log.error('Unable to correct a message', exc_info=True)
        else:
            del msg['replace']
        if msg['body'].find('\x19') != -1:
            msg.enable('html')
            msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
            msg['body'] = xhtml.clean_text(msg['body'])
        if (config.get_by_tabname('send_chat_states', self.general_jid) and
                self.remote_wants_chatstates is not False):
            needed = 'inactive' if self.inactive else 'active'
            msg['chat_state'] = needed
        if attention and self.remote_supports_attention:
            msg['attention'] = True
        self.core.events.trigger('conversation_say_after', msg, self)
        if not msg['body']:
            self.cancel_paused_delay()
            self.text_win.refresh()
            self.input.refresh()
            return
        if not replaced:
            self.add_message(msg['body'],
                    nickname=self.core.own_nick,
                    nick_color=get_theme().COLOR_OWN_NICK,
                    identifier=msg['id'],
                    jid=self.core.xmpp.boundjid,
                    typ=1)

        self.last_sent_message = msg
        if self.remote_supports_receipts:
            msg._add_receipt = True
        msg.send()
        self.cancel_paused_delay()
        self.text_win.refresh()
        self.input.refresh()
Example #5
0
    def command_say(self,
                    line: str,
                    attention: bool = False,
                    correct: bool = False) -> None:
        if not self.on:
            return
        our_jid = JID(self.jid.bare)
        our_jid.resource = self.own_nick
        msg = self.core.xmpp.make_message(
            mto=self.jid.full,
            mfrom=our_jid,
        )
        msg['type'] = 'chat'
        msg['body'] = line
        x = ET.Element('{%s}x' % NS_MUC_USER)
        msg.append(x)
        # trigger the event BEFORE looking for colors.
        # This lets a plugin insert \x19xxx} colors, that will
        # be converted in xhtml.
        self.core.events.trigger('private_say', msg, self)
        if not msg['body']:
            return
        if correct or msg['replace']['id']:
            msg['replace']['id'] = self.last_sent_message['id']
        else:
            del msg['replace']

        if msg['body'].find('\x19') != -1:
            msg.enable('html')
            msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
            msg['body'] = xhtml.clean_text(msg['body'])
        if config.get_by_tabname('send_chat_states', self.general_jid):
            needed = 'inactive' if self.inactive else 'active'
            msg['chat_state'] = needed
        if attention:
            msg['attention'] = True
        self.core.events.trigger('private_say_after', msg, self)
        if not msg['body']:
            return
        self.set_last_sent_message(msg, correct=correct)
        self.core.handler.on_groupchat_private_message(msg, sent=True)
        msg._add_receipt = True
        msg.send()
        self.cancel_paused_delay()
Example #6
0
 def command_say(self, line, attention=False, correct=False):
     msg = self.core.xmpp.make_message(mto=self.get_dest_jid(),
                                       mfrom=self.core.xmpp.boundjid)
     msg['type'] = 'chat'
     msg['body'] = line
     if not self.nick_sent:
         msg['nick'] = self.core.own_nick
         self.nick_sent = True
     # trigger the event BEFORE looking for colors.
     # and before displaying the message in the window
     # This lets a plugin insert \x19xxx} colors, that will
     # be converted in xhtml.
     self.core.events.trigger('conversation_say', msg, self)
     if not msg['body']:
         return
     replaced = False
     if correct or msg['replace']['id']:
         msg['replace']['id'] = self.last_sent_message['id']
     else:
         del msg['replace']
     if msg['body'].find('\x19') != -1:
         msg.enable('html')
         msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
         msg['body'] = xhtml.clean_text(msg['body'])
     if config.get_by_tabname('send_chat_states', self.general_jid):
         needed = 'inactive' if self.inactive else 'active'
         msg['chat_state'] = needed
     if attention:
         msg['attention'] = True
     self.core.events.trigger('conversation_say_after', msg, self)
     if not msg['body']:
         return
     self.last_sent_message = msg
     self.core.handler.on_normal_message(msg)
     msg._add_receipt = True
     msg.send()
     self.cancel_paused_delay()
Example #7
0
    def command_say(self, line, attention=False, correct=False):
        if not self.on:
            return
        echo_message = JID(self.name).resource != self.own_nick
        msg = self.core.xmpp.make_message(self.name)
        msg['type'] = 'chat'
        msg['body'] = line
        # trigger the event BEFORE looking for colors.
        # This lets a plugin insert \x19xxx} colors, that will
        # be converted in xhtml.
        self.core.events.trigger('private_say', msg, self)
        if not msg['body']:
            self.cancel_paused_delay()
            self.text_win.refresh()
            self.input.refresh()
            return
        user = self.parent_muc.get_user_by_name(self.own_nick)
        replaced = False
        if correct or msg['replace']['id']:
            msg['replace']['id'] = self.last_sent_message['id']
            if (config.get_by_tabname('group_corrections', self.name)
                    and echo_message):
                try:
                    self.modify_message(
                        msg['body'],
                        self.last_sent_message['id'],
                        msg['id'],
                        user=user,
                        jid=self.core.xmpp.boundjid,
                        nickname=self.own_nick)
                    replaced = True
                except:
                    log.error('Unable to correct a message', exc_info=True)
        else:
            del msg['replace']

        if msg['body'].find('\x19') != -1:
            msg.enable('html')
            msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body'])
            msg['body'] = xhtml.clean_text(msg['body'])
        if config.get_by_tabname('send_chat_states', self.general_jid):
            needed = 'inactive' if self.inactive else 'active'
            msg['chat_state'] = needed
        if attention:
            msg['attention'] = True
        self.core.events.trigger('private_say_after', msg, self)
        if not msg['body']:
            self.cancel_paused_delay()
            self.text_win.refresh()
            self.input.refresh()
            return
        if not replaced and echo_message:
            self.add_message(
                msg['body'],
                nickname=self.own_nick or self.core.own_nick,
                forced_user=user,
                nick_color=get_theme().COLOR_OWN_NICK,
                identifier=msg['id'],
                jid=self.core.xmpp.boundjid,
                typ=1)

        self.last_sent_message = msg
        msg._add_receipt = True
        msg.send()
        self.cancel_paused_delay()
        self.text_win.refresh()
        self.input.refresh()