예제 #1
0
    def render_messages(self, messages, channel_id=None):
        _messages = []
        previous_date = self.store.state.last_date
        last_read_datetime = datetime.fromtimestamp(float(self.store.state.channel.get('last_read', '0')))
        today = datetime.today().date()
        for message in messages:
            message_datetime = datetime.fromtimestamp(float(message['ts']))
            message_date = message_datetime.date()
            date_text = None
            unread_text = None
            if not previous_date or previous_date != message_date:
                previous_date = message_date
                self.store.state.last_date = previous_date
                if message_date == today:
                    date_text = 'Today'
                else:
                    date_text = message_date.strftime('%A, %B %d')

            # New messages badge
            if (message_datetime > last_read_datetime and not self.store.state.did_render_new_messages
                and (self.store.state.channel.get('unread_count_display', 0) > 0)):
                self.store.state.did_render_new_messages = True
                unread_text = 'new messages'
            if unread_text is not None:
                _messages.append(NewMessagesDivider(unread_text, date=date_text))
            elif date_text is not None:
                _messages.append(TextDivider(('history_date', date_text), 'center'))

            message = self.render_message(message, channel_id)

            if message is not None:
                _messages.append(message)

        return _messages
예제 #2
0
파일: app.py 프로젝트: mitas/sclack
    def render_messages(self, messages, channel_id=None):
        _messages = []
        previous_date = self.store.state.last_date
        last_read_datetime = datetime.fromtimestamp(
            float(self.store.state.channel.get('last_read', '0')))
        today = datetime.today().date()

        # If we are viewing a thread, add a dummy 'message' to indicate this
        # to the user.
        if self.showing_thread:
            _messages.append(
                self.render_message({
                    'text': "VIEWING THREAD",
                    'ts': '0',
                    'subtype': SCLACK_SUBTYPE,
                }))

        for message in messages:
            message_datetime = datetime.fromtimestamp(float(message['ts']))
            message_date = message_datetime.date()
            date_text = None
            unread_text = None
            if not previous_date or previous_date != message_date:
                previous_date = message_date
                self.store.state.last_date = previous_date
                if message_date == today:
                    date_text = 'Today'
                else:
                    date_text = message_date.strftime('%A, %B %d')

            # New messages badge
            if (message_datetime > last_read_datetime
                    and not self.store.state.did_render_new_messages and
                (self.store.state.channel.get('unread_count_display', 0) > 0)):
                self.store.state.did_render_new_messages = True
                unread_text = 'new messages'
            if unread_text is not None:
                _messages.append(
                    NewMessagesDivider(unread_text, date=date_text))
            elif date_text is not None:
                _messages.append(
                    TextDivider(('history_date', date_text), 'center'))

            message = self.render_message(message, channel_id)

            if message is not None:
                _messages.append(message)

        return _messages