aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Barroso <dbarrosop@dravetech.com>2017-07-08 12:48:16 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-09-20 23:45:41 +0200
commit0345ba1d91490fb7b030154f7dcac9ffdbe87798 (patch)
tree30a7aaa132cfc137851db236339274e7bcfafc81
parent7bf0ea6a4eedc0c98152b3b13f1394676a39d4dd (diff)
downloadwee-slack-0345ba1d91490fb7b030154f7dcac9ffdbe87798.tar.gz
When unfurling attachments avoid rendering same link multiple times
-rw-r--r--wee_slack.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 7ba1995..e4157bb 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2281,8 +2281,7 @@ def subprocess_message_changed(message_json, eventrouter, channel, team):
else:
message_json["fallback"] = m["fallback"]
- text_before = (len(new_message['text']) > 0)
- new_message["text"] += unwrap_attachments(message_json, text_before)
+ new_message["text"] += unwrap_attachments(message_json, new_message["text"])
if "edited" in new_message:
channel.change_message(new_message["ts"], new_message["text"], ' (edited)')
else:
@@ -2450,8 +2449,7 @@ def render(message_json, team, channel, force=False):
text = unfurl_refs(text, ignore_alt_text=config.unfurl_ignore_alt_text)
- text_before = (len(text) > 0)
- text += unfurl_refs(unwrap_attachments(message_json, text_before), ignore_alt_text=config.unfurl_ignore_alt_text)
+ text += unfurl_refs(unwrap_attachments(message_json, text), ignore_alt_text=config.unfurl_ignore_alt_text)
text = text.lstrip()
text = text.replace("\t", " ")
@@ -2558,14 +2556,18 @@ def unwrap_attachments(message_json, text_before):
if 'pretext' in attachment:
t.append(attachment['pretext'])
title = attachment.get('title', None)
- title_link = attachment.get('title_link', None)
+ title_link = attachment.get('title_link', '')
+ if title_link in text_before:
+ title_link = ''
if title and title_link:
t.append('%s%s (%s)' % (prepend_title_text, title, title_link,))
prepend_title_text = ''
elif title and not title_link:
- t.append(prepend_title_text + title)
+ t.append('%s%s' % (prepend_title_text, title,))
prepend_title_text = ''
- t.append(attachment.get("from_url", ""))
+ from_url = attachment.get('from_url', '')
+ if from_url not in text_before:
+ t.append(from_url)
atext = attachment.get("text", None)
if atext: