aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_pytest/test_unwrap_attachments.py24
-rw-r--r--wee_slack.py13
2 files changed, 34 insertions, 3 deletions
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py
index 1c5fa86..3c8ac8b 100644
--- a/_pytest/test_unwrap_attachments.py
+++ b/_pytest/test_unwrap_attachments.py
@@ -153,6 +153,30 @@ import pytest
},
{
'input_message': {'attachments': [{
+ 'fallback': 'Fallback',
+ 'title_link': 'http://link',
+ }]},
+ 'input_text_before': "http://link",
+ 'output': "",
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'fallback': 'Fallback',
+ 'from_url': 'http://link',
+ }]},
+ 'input_text_before': "http://link",
+ 'output': "",
+ },
+ {
+ 'input_message': {'attachments': [{
+ 'fallback': 'Fallback',
+ 'image_url': 'http://link',
+ }]},
+ 'input_text_before': "http://link",
+ 'output': "",
+ },
+ {
+ 'input_message': {'attachments': [{
'title': 'Title',
'fields': [{
'title': 'First field title',
diff --git a/wee_slack.py b/wee_slack.py
index 7424872..a230b3b 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -3445,10 +3445,12 @@ def unwrap_attachments(message_json, text_before):
prepend_title_text = attachment['author_name'] + ": "
if 'pretext' in attachment:
t.append(attachment['pretext'])
+ link_shown = False
title = attachment.get('title')
title_link = attachment.get('title_link', '')
- if title_link in text_before or title_link in text_before_unescaped:
+ if title_link and (title_link in text_before or title_link in text_before_unescaped):
title_link = ''
+ link_shown = True
if title and title_link:
t.append('%s%s (%s)' % (prepend_title_text, title, title_link,))
prepend_title_text = ''
@@ -3459,6 +3461,8 @@ def unwrap_attachments(message_json, text_before):
if (from_url not in text_before and from_url not in text_before_unescaped
and from_url != title_link):
t.append(from_url)
+ elif from_url:
+ link_shown = True
atext = attachment.get("text")
if atext:
@@ -3470,6 +3474,8 @@ def unwrap_attachments(message_json, text_before):
if (image_url not in text_before and image_url not in text_before_unescaped
and image_url != from_url and image_url != title_link):
t.append(image_url)
+ elif image_url:
+ link_shown = True
fields = attachment.get("fields")
if fields:
@@ -3479,9 +3485,10 @@ def unwrap_attachments(message_json, text_before):
else:
t.append(f['value'])
fallback = attachment.get("fallback")
- if t == [] and fallback:
+ if t == [] and fallback and not link_shown:
t.append(fallback)
- attachment_texts.append("\n".join([x.strip() for x in t if x]))
+ if t:
+ attachment_texts.append("\n".join([x.strip() for x in t if x]))
return "\n".join(attachment_texts)