diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-09-20 23:51:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-20 23:51:00 +0200 |
commit | 2f43d1b6466c74e8774e2833214f847eb559f15a (patch) | |
tree | 8aabf737eaabfebab9fdfa01fbb34254ee113c3b | |
parent | 3f6b50f4eb8f737ec11dbbcef0af4a5844b41ce8 (diff) | |
parent | 0345ba1d91490fb7b030154f7dcac9ffdbe87798 (diff) | |
download | wee-slack-2f43d1b6466c74e8774e2833214f847eb559f15a.tar.gz |
Merge pull request #387 from dbarrosop/unwrap_attachments
When expanding attachments avoid rendering same link multiple times
-rw-r--r-- | wee_slack.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py index 7681912..90b56ac 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2321,8 +2321,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: @@ -2501,8 +2500,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 = unhtmlescape(text.replace("\t", " ")) @@ -2621,14 +2619,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: |