aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2018-08-10 17:23:09 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2018-08-10 20:44:14 +0200
commitcd742e1b8fa9544e7dc960efa47ea0d524763e41 (patch)
treef0e9e96865db3295706ddb8164d698639086dda1 /wee_slack.py
parentaa2b279f84f0faaf30d22947ec2ef634de6a24aa (diff)
downloadwee-slack-cd742e1b8fa9544e7dc960efa47ea0d524763e41.tar.gz
Render files after message instead of changing message text
Instead of changing the message text, append the files belonging to the message when we render the message. This is the same as we do with attachments. This fixes the issue where the files would not be shown anymore if a message is changed. The rendering format of the files is changed to match the way we render refs.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py
index ffc7249..6439ba1 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2113,14 +2113,6 @@ class SlackMessage(object):
message_json['text']
)
- if message_json.get('upload'):
- parts = [message_json['text']]
- for f in message_json.get('files', []):
- parts.append("({}) - {}".format(
- f.get('title'),
- f.get('url_private')))
- message_json['text'] = ' | '.join(p for p in parts if p)
-
def __hash__(self):
return hash(self.ts)
@@ -2791,6 +2783,8 @@ def render(message_json, team, channel, force=False):
text += unfurl_refs(unwrap_attachments(message_json, text))
+ text += unfurl_refs(unwrap_files(message_json, text))
+
text = text.lstrip()
text = unhtmlescape(text.replace("\t", " "))
if message_json.get('mrkdwn', True):
@@ -2960,6 +2954,14 @@ def unwrap_attachments(message_json, text_before):
return "\n".join(attachment_texts)
+def unwrap_files(message_json, text_before):
+ files_texts = ['{} ({})'.format(f['url_private'], f['title'])
+ for f in message_json.get('files', [])]
+ if text_before:
+ files_texts.insert(0, '')
+ return "\n".join(files_texts)
+
+
def resolve_ref(ref):
# TODO: This hack to use eventrouter needs to go
# this resolver should probably move to the slackteam or eventrouter itself