예제 #1
0
    def _update_single_information(self, account):
        '''set the data of the conversation to the data of the account'''
        contact = self.session.contacts.safe_get(account)

        if contact.media == '':
            message = MarkupParser.escape(contact.message)
        else:
            message = MarkupParser.escape(contact.media)

        nick = MarkupParser.escape(contact.display_name)

        self.update_single_information(nick, message, account)
예제 #2
0
    def _update_single_information(self, account):
        """set the data of the conversation to the data of the account"""
        contact = self.session.contacts.get(account)

        if contact:
            message = MarkupParser.escape(contact.message)
            nick = MarkupParser.escape(contact.display_name)
        else:
            message = ""
            nick = account

        self.update_single_information(nick, message, account)
예제 #3
0
    def _update_single_information(self, account):
        '''set the data of the conversation to the data of the account'''
        contact = self.session.contacts.safe_get(account)

        if contact.media == '':
            message = MarkupParser.escape(contact.message)
        else:
            message = MarkupParser.escape(contact.media)

        nick = MarkupParser.escape(contact.display_name)

        self.update_single_information(nick, message, account)
예제 #4
0
    def _on_message(self, cid, account, message, cedict=None):
        '''called when a message is received'''
        conversation = self.conversations.get(float(cid), None)

        if conversation is None:
            (exists, conversation) = self.new_conversation(cid, [account])

        contact = self.session.contacts.get(account)
        if contact:
            nick = contact.display_name
        else:
            nick = account

        if message.type == e3.Message.TYPE_MESSAGE:
            (is_raw, consecutive, outgoing, first, last) = \
                conversation.formatter.format(contact)

            middle = MarkupParser.escape(message.body)
            if not is_raw:
                middle = self.format_from_message(message)

            conversation.output.append(first + middle + last, cedict,self.session.config.b_allow_auto_scroll)
            conversation.play_send()

        elif message.type == e3.Message.TYPE_NUDGE:
            conversation.output.append(
                conversation.formatter.format_information(
                    '%s just sent you a nudge!' % (nick,)),self.session.config.b_allow_auto_scroll)
            conversation.play_nudge()

        if message.type != e3.Message.TYPE_TYPING:
            self.set_message_waiting(conversation, True)
예제 #5
0
    def _pre_process_message(self, contact, message, incomming, cedict, cepath, tstamp=None, mtype=None, cstyle=None):
        '''Create a new gui.Message and calculates if it's first message
        '''
        msg = gui.Message.from_contact(contact,
                message, self.first, incomming, tstamp, mtype = mtype, mstyle=cstyle)

        if self.session.config.b_show_emoticons:
            msg.message = MarkupParser.replace_emotes(MarkupParser.escape(msg.message),
                        cedict, cepath, msg.sender)

        msg.message = MarkupParser.urlify(msg.message)

        b_nick_check = bool(self.last_incoming_nickname != msg.display_name)
        if b_nick_check:
            self.last_incoming_nickname = msg.display_name

        if msg.incoming:
            if self.last_incoming is None:
                self.last_incoming = False

            msg.first = not self.last_incoming

            if self.last_incoming_account != msg.sender or b_nick_check:
                msg.first = True
        else:
            if self.last_incoming is None:
                self.last_incoming = True

            msg.first = self.last_incoming

        return msg
예제 #6
0
파일: utils.py 프로젝트: Otacon/emesene
def add_style_to_message(text, stl, escape=True):
    '''add the style in a xhtml like syntax to text'''
    style_start = ''
    style_end = ''
    style = 'color: #' + stl.color.to_hex() + ';'

    if stl.bold:
        style_start = style_start + '<b>'
        style_end = '</b>' + style_end

    if stl.italic:
        style_start = style_start + '<i>'
        style_end = '</i>' + style_end

    if stl.underline:
        style_start = style_start + '<u>'
        style_end = '</u>' + style_end

    if stl.strike:
        style_start = style_start + '<s>'
        style_end = '</s>' + style_end

    if stl.font:
        style += 'font-family: ' + stl.font

    style_start += '<span style="%s; ">' % (style, )
    style_end = '</span>' + style_end

    if escape:
        text = MarkupParser.escape(text)

    return style_start + text + style_end
예제 #7
0
    def _on_send_message(self, text, cedict=None):
        '''method called when the user press enter on the input text'''
        self.session.send_message(self.cid, text, self.cstyle)
        nick = self.session.contacts.me.display_name

        (is_raw, consecutive, outgoing, first, last) = \
            self.formatter.format(self.session.contacts.me)

        if is_raw:
            middle = MarkupParser.escape(text)
        else:
            middle = MarkupParser.escape(text)
            middle = e3.common.add_style_to_message(middle, self.cstyle, False)

        all = first + middle + last
        self.output.append(all, cedict,self.session.config.b_allow_auto_scroll)
        self.play_type()
예제 #8
0
    def on_contact_left(self, account):
        '''called when a contact leaves the conversation'''
        if len(self.members) > 1 and account in self.members:
            self.members.remove(account)
            self.update_data()
            contact = self.session.contacts.safe_get(account)
            message = e3.base.Message(e3.base.Message.TYPE_MESSAGE, \
            _('%s has left the conversation') % (MarkupParser.escape(contact.display_name)), \
            account)
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)
예제 #9
0
    def on_contact_left(self, account):
        '''called when a contact leaves the conversation'''
        if len(self.members) > 1 and account in self.members:
            self.members.remove(account)
            self.update_data()
            contact = self.session.contacts.safe_get(account)
            message = e3.base.Message(e3.base.Message.TYPE_MESSAGE, \
            _('%s has left the conversation') % (MarkupParser.escape(contact.display_name)), \
            account)
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)
예제 #10
0
    def on_contact_joined(self, account):
        '''called when a contact joins the conversation'''
        if account not in self.members:
            self.members.append(account)
            contact = self.session.contacts.safe_get(account)
            if len(self.members) > 1:
                message = e3.base.Message(e3.base.Message.TYPE_MESSAGE, \
                _('%s has joined the conversation') % (MarkupParser.escape(contact.display_name)), \
                account)
                msg = gui.Message.from_information(contact, message)

                self.output.information(msg)
                self.conv_status.post_process_message(msg)

        self.update_data()
예제 #11
0
    def on_contact_joined(self, account):
        '''called when a contact joins the conversation'''
        if account not in self.members:
            self.members.append(account)
            contact = self.session.contacts.safe_get(account)
            if len(self.members) > 1:
                message = e3.base.Message(e3.base.Message.TYPE_MESSAGE, \
                _('%s has joined the conversation') % (MarkupParser.escape(contact.display_name)), \
                account)
                msg = gui.Message.from_information(contact, message)

                self.output.information(msg)
                self.conv_status.post_process_message(msg)

        self.update_data()
예제 #12
0
    def on_receive_message(self, message, account, received_custom_emoticons):
        '''method called when a message arrives to the conversation'''
        for callback in self.session.cb_gui_recv_message.sorted():
            callback(message)

        contact = self.session.contacts.safe_get(account)

        if message.type == e3.Message.TYPE_MESSAGE or \
           message.type == e3.Message.TYPE_FLNMSG:

            if self.session.config.b_override_text_color:
                message.style.color = \
                e3.base.Color.from_hex(self.session.config.override_text_color)

            user_emcache = self.caches.get_emoticon_cache(account)

            #XXX: when we send messages from the web iface we get those here, so show them propertly
            if contact.account == self.session.contacts.me.account:
                self.output_message(message, None)
                return

            self.input_message(message, contact,
                               received_custom_emoticons, user_emcache.path)

            self.play_type()

        elif message.type == e3.Message.TYPE_NUDGE:
            message.body = _('%s just sent you a nudge!') % (MarkupParser.escape(contact.display_name),)
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)

            self.play_nudge()

        elif message.type == e3.Message.TYPE_INFO:
            msg = gui.Message.from_information(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)

        elif message.type == e3.Message.TYPE_PICTURE:
            msg = gui.Message.from_contact(contact, message)

            self.output.information(msg)
            self.conv_status.post_process_message(msg)

        self.conv_status.update_status()
예제 #13
0
    def pre_process_message(self,
                            contact,
                            message,
                            incomming,
                            cedict,
                            cepath,
                            tstamp=None,
                            mtype=None,
                            cstyle=None):
        '''Create a new gui.Message
        '''
        msg = gui.Message.from_contact(contact,
                                       message,
                                       self.first,
                                       incomming,
                                       tstamp,
                                       mtype=mtype,
                                       mstyle=cstyle)

        msg.message = MarkupParser.escape(msg.message)
        if self.config.b_show_emoticons:
            msg.message = MarkupParser.replace_emotes(msg.message, cedict,
                                                      cepath, msg.sender)

        msg.message = MarkupParser.urlify(msg.message)

        b_nick_check = bool(self.last_incoming_nickname != msg.display_name)
        if b_nick_check:
            self.last_incoming_nickname = msg.display_name

        if msg.incoming:
            if self.last_incoming is None:
                self.last_incoming = False

            msg.first = not self.last_incoming

            if self.last_incoming_account != msg.sender or b_nick_check:
                msg.first = True
        else:
            if self.last_incoming is None:
                self.last_incoming = True

            msg.first = self.last_incoming

        return msg
예제 #14
0
    def format(self, contact, message_type=None):
        '''format the message according to the template'''
        if message_type is None:
            message_type=e3.Message.TYPE_MESSAGE

        outgoing = False
        consecutive = False

        if self.contact.account == contact.account:
            outgoing = True

        if self.last_message_sender and \
            self.last_message_sender.account == contact.account:
            consecutive = True

        timestamp = time.time()
        self.last_message_sender = contact
        self.last_message_time = timestamp

        if message_type == e3.Message.TYPE_MESSAGE:
            if consecutive:
                if outgoing:
                    template = self.consecutive_outgoing
                else:
                    template = self.consecutive_incoming
            else:
                if outgoing:
                    template = self.outgoing
                else:
                    template = self.incoming
        if message_type == e3.Message.TYPE_NUDGE:
            template = self.nudge
            self.last_message_sender = None

        formated_time = time.strftime('%c', time.gmtime(timestamp))

        template = template.replace('%NICK%',
            MarkupParser.escape(contact.nick))
        template = template.replace('%ALIAS%',
            MarkupParser.escape(contact.alias))
        template = template.replace('%ACCOUNT%',
            MarkupParser.escape(contact.account))
        template = template.replace('%DISPLAYNAME%',
            MarkupParser.escape(contact.display_name))
        template = template.replace('%TIME%',
            MarkupParser.escape(formated_time))
        template = template.replace('%STATUS%',
            MarkupParser.escape(e3.status.STATUS[contact.status]))
        template = template.replace('%PERSONALMESSAGE%',
            MarkupParser.escape(contact.message))
        template = template.replace('%NL%', self.new_line)

        is_raw = False

        if '%MESSAGE%' in template:
            (first, last) = template.split('%MESSAGE%')
        elif '%RAWMESSAGE%' in template:
            (first, last) = template.split('%RAWMESSAGE%')
            is_raw = True
        else:
            first = template
            last = ''

        return (is_raw, consecutive, outgoing, first, last)