Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,14 @@ def render_message(self, message, channel_id=None):
attachment_widget = Attachment(
service_name=attachment.get('service_name'),
title=attachment.get('title'),
from_url=attachment.get('from_url'),
fields=attachment.get('fields'),
color=attachment.get('color'),
author_name=attachment.get('author_name'),
author_name=attachment.get('author_name') or attachment.get('author_subname'),
pretext=attachment.get('pretext'),
text=message_text,
attachment_text=attachment.get('text'),
ts=attachment.get('ts'),
footer=attachment.get('footer')
)
image_url = attachment.get('image_url')
Expand Down
33 changes: 28 additions & 5 deletions sclack/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .markdown import MarkdownText
from .store import Store
from sclack.utils.channel import is_group, is_channel, is_dm
from sclack.utils.message import format_date_time


MARK_READ_ALARM_PERIOD = 3
Expand All @@ -36,35 +37,57 @@ def __init__(self,
service_name=None,
title=None,
title_link=None,
from_url=None,
author_name=None,
pretext=None,
text=None,
fields=None,
attachment_text=None,
ts=None,
footer=None):
body = []
if not color:
color = 'CCCCCC'
color = '#{}'.format(shorten_hex(color))

self._image_index = 0
self.from_url = from_url

if service_name:
body.append(urwid.Text(('attachment_title', service_name)))
self._image_index = self._image_index + 1

if title:
body.append(urwid.Text(('attachment_title', title)))
body.append(urwid.Text(('attachment_title', title.strip())))
self._image_index = self._image_index + 1

if author_name:
body.append(urwid.Text(('attachment_title', author_name)))
self._image_index = self._image_index + 1

if pretext:
body.append(urwid.Text(MarkdownText(pretext).markup))
self._image_index = self._image_index + 1
if text:
body.append(urwid.Text(MarkdownText(text).markup))

text_display = attachment_text if attachment_text is not None else text
if text_display:
body.append(urwid.Text(MarkdownText(text_display.strip()).markup))

if fields:
body.append(Fields(fields))
if footer:
body.append(urwid.Text(MarkdownText(footer).markup))

if footer or ts:
footer_parts = []
if footer:
footer_parts.append(footer)
if ts:
footer_parts.append(format_date_time(ts))

footer_text = ' | '.join(footer_parts)
body.append(urwid.Text(MarkdownText(footer_text).markup))

self.pile = urwid.Pile(body)

super(Attachment, self).__init__(self.pile, color)

@property
Expand Down
19 changes: 19 additions & 0 deletions sclack/utils/message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from datetime import datetime


def format_date_time(ts):
"""
Format date time for message
:param ts:
:return:
"""
message_datetime = datetime.fromtimestamp(float(ts))
message_date = message_datetime.date()
today = datetime.today().date()

if message_date == today:
date_text = message_datetime.strftime('Today at %I:%M%p')
else:
date_text = message_datetime.strftime('%b %d, %Y at %I:%M%p')

return date_text