diff options
author | Tollef Fog Heen <tfheen@err.no> | 2015-11-27 06:44:29 +0100 |
---|---|---|
committer | Tollef Fog Heen <tfheen@err.no> | 2015-11-27 06:44:29 +0100 |
commit | 0062c91760aea1d946766f41708ba36cceedeb44 (patch) | |
tree | 7061310b1bf0c983238039a7808b1b1d986e7eb2 | |
parent | 84c1abd3f7234e7aef28ada3a65f6e1bc3b1101f (diff) | |
download | wee-slack-0062c91760aea1d946766f41708ba36cceedeb44.tar.gz |
Fix up formatting of messages with attachments
Previously, all messages would have "---" as the start, even if there
was no leading text. Make it so the dashes are only added if necessary.
-rw-r--r-- | wee_slack.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py index 7b7114a..338a4fc 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1531,7 +1531,8 @@ def render_message(message_json, force=False): text = unfurl_refs(text, ignore_alt_text=unfurl_ignore_alt_text) - text += unwrap_attachments(message_json) + text_before = (len(text) > 0) + text += unfurl_refs(unwrap_attachments(message_json, text_before), ignore_alt_text=unfurl_ignore_alt_text) text = text.lstrip() text = text.replace("\t", " ") @@ -1602,7 +1603,8 @@ def process_message_changed(message_json): else: message_json["fallback"] = m["fallback"] - m["text"] += unwrap_attachments(message_json) + text_before = (len(m['text']) > 0) + m["text"] += unwrap_attachments(message_json, text_before) channel = channels.find(message_json["channel"]) if "edited" in m: m["text"] += " (edited)" @@ -1614,14 +1616,18 @@ def process_message_deleted(message_json): channel.change_message(message_json["deleted_ts"], "(deleted)") -def unwrap_attachments(message_json): +def unwrap_attachments(message_json, text_before): + attachment_text = '' if "attachments" in message_json: - attachment_text = u' --- ' + if text_before: + attachment_text = u' --- ' for attachment in message_json["attachments"]: + t = [] + if "from_url" in attachment and text_before is False: + t.append(attachment['from_url']) if "fallback" in attachment: - attachment_text += attachment["fallback"] - else: - attachment_text = '' + t.append(attachment["fallback"]) + attachment_text += ": ".join(t) return attachment_text |