1111from .markdown import MarkdownText
1212from .store import Store
1313from sclack .utils .channel import is_group , is_channel , is_dm
14+ from sclack .utils .message import format_date_time
1415
1516
1617MARK_READ_ALARM_PERIOD = 3
@@ -36,35 +37,57 @@ def __init__(self,
3637 service_name = None ,
3738 title = None ,
3839 title_link = None ,
40+ from_url = None ,
3941 author_name = None ,
4042 pretext = None ,
4143 text = None ,
4244 fields = None ,
45+ attachment_text = None ,
46+ ts = None ,
4347 footer = None ):
4448 body = []
4549 if not color :
4650 color = 'CCCCCC'
4751 color = '#{}' .format (shorten_hex (color ))
52+
4853 self ._image_index = 0
54+ self .from_url = from_url
55+
4956 if service_name :
5057 body .append (urwid .Text (('attachment_title' , service_name )))
5158 self ._image_index = self ._image_index + 1
59+
5260 if title :
53- body .append (urwid .Text (('attachment_title' , title )))
61+ body .append (urwid .Text (('attachment_title' , title . strip () )))
5462 self ._image_index = self ._image_index + 1
63+
5564 if author_name :
5665 body .append (urwid .Text (('attachment_title' , author_name )))
5766 self ._image_index = self ._image_index + 1
67+
5868 if pretext :
5969 body .append (urwid .Text (MarkdownText (pretext ).markup ))
6070 self ._image_index = self ._image_index + 1
61- if text :
62- body .append (urwid .Text (MarkdownText (text ).markup ))
71+
72+ text_display = attachment_text if attachment_text is not None else text
73+ if text_display :
74+ body .append (urwid .Text (MarkdownText (text_display .strip ()).markup ))
75+
6376 if fields :
6477 body .append (Fields (fields ))
65- if footer :
66- body .append (urwid .Text (MarkdownText (footer ).markup ))
78+
79+ if footer or ts :
80+ footer_parts = []
81+ if footer :
82+ footer_parts .append (footer )
83+ if ts :
84+ footer_parts .append (format_date_time (ts ))
85+
86+ footer_text = ' | ' .join (footer_parts )
87+ body .append (urwid .Text (MarkdownText (footer_text ).markup ))
88+
6789 self .pile = urwid .Pile (body )
90+
6891 super (Attachment , self ).__init__ (self .pile , color )
6992
7093 @property
0 commit comments