aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2018-01-10 21:48:01 +0100
committerGitHub <noreply@github.com>2018-01-10 21:48:01 +0100
commitfe7832f2453469fe4978b095561d6b7fce07cab8 (patch)
tree0cc185af3f381d31d40f0f0e741f5d33693bcf3c /wee_slack.py
parent81d1270e3a8d50e680dfd8bfb7c23890b846c05f (diff)
parent867d6134f9ef0d66deb5f5b4da63d5d5a538810a (diff)
downloadwee-slack-fe7832f2453469fe4978b095561d6b7fce07cab8.tar.gz
Merge pull request #438 from trygveaa/attachment-tests-and-minor-fixes
Attachment tests and minor fixes
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 0948031..8854e18 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2667,11 +2667,12 @@ def unhtmlescape(text):
def unwrap_attachments(message_json, text_before):
- attachment_text = ''
+ text_before_unescaped = unhtmlescape(text_before)
+ attachment_texts = []
a = message_json.get("attachments", None)
if a:
if text_before:
- attachment_text = '\n'
+ attachment_texts.append('')
for attachment in a:
# Attachments should be rendered roughly like:
#
@@ -2687,7 +2688,7 @@ def unwrap_attachments(message_json, text_before):
t.append(attachment['pretext'])
title = attachment.get('title', None)
title_link = attachment.get('title_link', '')
- if title_link in text_before:
+ if title_link in text_before_unescaped:
title_link = ''
if title and title_link:
t.append('%s%s (%s)' % (prepend_title_text, title, title_link,))
@@ -2696,7 +2697,7 @@ def unwrap_attachments(message_json, text_before):
t.append('%s%s' % (prepend_title_text, title,))
prepend_title_text = ''
from_url = attachment.get('from_url', '')
- if from_url not in text_before:
+ if from_url not in text_before_unescaped and from_url != title_link:
t.append(from_url)
atext = attachment.get("text", None)
@@ -2714,8 +2715,8 @@ def unwrap_attachments(message_json, text_before):
fallback = attachment.get("fallback", None)
if t == [] and fallback:
t.append(fallback)
- attachment_text += "\n".join([x.strip() for x in t if x])
- return attachment_text
+ attachment_texts.append("\n".join([x.strip() for x in t if x]))
+ return "\n".join(attachment_texts)
def resolve_ref(ref):