diff options
-rw-r--r-- | _pytest/test_unwrap_attachments.py | 35 | ||||
-rw-r--r-- | wee_slack.py | 14 |
2 files changed, 49 insertions, 0 deletions
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py index 3c8ac8b..5f76e57 100644 --- a/_pytest/test_unwrap_attachments.py +++ b/_pytest/test_unwrap_attachments.py @@ -177,6 +177,41 @@ import pytest }, { 'input_message': {'attachments': [{ + 'text': 'Some message', + 'footer': 'Thread in #general' + }]}, + 'input_text_before': "", + 'output': "\n".join([ + "Some message", + "Thread in #general", + ]), + }, + { + 'input_message': {'attachments': [{ + 'ts': 1584986782, + 'text': 'Some message', + 'footer': 'Thread in #general' + }]}, + 'input_text_before': "", + 'output': "\n".join([ + "Some message", + "Thread in #general | Mar 23, 2020", + ]), + }, + { + 'input_message': {'attachments': [{ + 'ts': '1584986782.261400', + 'text': 'Some message', + 'footer': 'Thread in #general' + }]}, + 'input_text_before': "", + 'output': "\n".join([ + "Some message", + "Thread in #general | Mar 23, 2020", + ]), + }, + { + 'input_message': {'attachments': [{ 'title': 'Title', 'fields': [{ 'title': 'First field title', diff --git a/wee_slack.py b/wee_slack.py index a230b3b..6e129d4 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3484,6 +3484,20 @@ def unwrap_attachments(message_json, text_before): t.append('%s %s' % (f['title'], f['value'],)) else: t.append(f['value']) + + footer = attachment.get("footer") + if footer: + ts = attachment.get("ts") + if ts: + ts_int = ts if type(ts) == int else SlackTS(ts).major + time_string = '' + if date.today() - date.fromtimestamp(ts_int) <= timedelta(days=1): + time_string = ' at {time}' + timestamp_formatted = resolve_ref('!date^{}^{{date_short_pretty}}{}' + .format(ts_int, time_string)).capitalize() + footer += ' | {}'.format(timestamp_formatted) + t.append(footer) + fallback = attachment.get("fallback") if t == [] and fallback and not link_shown: t.append(fallback) |