diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-04-11 14:17:53 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-06-02 23:09:20 +0200 |
commit | 9aa307857867266b887bfa46be2f9328fd478824 (patch) | |
tree | 520876d295201436214b0c1b078c36a9f99ac3e1 | |
parent | db735c1772aff262813c75004d1cd2d698997a13 (diff) | |
download | wee-slack-9aa307857867266b887bfa46be2f9328fd478824.tar.gz |
Render "by invitation from" before reactions
-rw-r--r-- | _pytest/test_process_message.py | 2 | ||||
-rw-r--r-- | wee_slack.py | 68 |
2 files changed, 31 insertions, 39 deletions
diff --git a/_pytest/test_process_message.py b/_pytest/test_process_message.py index 225b971..eff81d4 100644 --- a/_pytest/test_process_message.py +++ b/_pytest/test_process_message.py @@ -2,7 +2,7 @@ from __future__ import print_function, unicode_literals import json -from wee_slack import render, SlackTS +from wee_slack import SlackTS def test_process_message(realish_eventrouter, team, user_alice): diff --git a/wee_slack.py b/wee_slack.py index a318f4e..94a260c 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2293,20 +2293,49 @@ class SlackMessage(object): w.buffer_set(self.thread_channel.channel_buffer, "display", "1") def render(self, force=False): - text = render(self.message_json, self.team, force) + # If we already have a rendered version in the object, just return that. + if not force and self.message_json.get("_rendered_text"): + return self.message_json["_rendered_text"] + + if "fallback" in self.message_json: + text = self.message_json["fallback"] + elif self.message_json.get("text"): + text = self.message_json["text"] + else: + text = "" + + if self.message_json.get('mrkdwn', True): + text = render_formatting(text) + + text = unfurl_refs(text) + if (self.message_json.get('subtype') == 'me_message' and not self.message_json['text'].startswith(self.sender)): text = "{} {}".format(self.sender, text) + if (self.message_json.get('subtype') in ('channel_join', 'group_join') and self.message_json.get('inviter')): inviter_id = self.message_json.get('inviter') inviter_nick = unfurl_refs("<@{}>".format(inviter_id)) text += " by invitation from {}".format(inviter_nick) + + if "edited" in self.message_json: + text += "{}{}{}".format( + w.color(config.color_edited_suffix), ' (edited)', w.color("reset")) + + text += unfurl_refs(unwrap_attachments(self.message_json, text)) + text += unfurl_refs(unwrap_files(self.message_json, text)) + text = unhtmlescape(text.lstrip().replace("\t", " ")) + + text += create_reaction_string(self.message_json.get("reactions", "")) + if len(self.submessages) > 0: text += " {}[ Thread: {} Replies: {} ]".format( w.color(config.color_thread_suffix), self.hash or self.ts, len(self.submessages)) + + self.message_json["_rendered_text"] = text return text def change_text(self, new_text): @@ -3047,43 +3076,6 @@ def render_formatting(text): return text -def render(message_json, team, force=False): - # If we already have a rendered version in the object, just return that. - if not force and message_json.get("_rendered_text", ""): - return message_json["_rendered_text"] - else: - # server = servers.find(message_json["_server"]) - - if "fallback" in message_json: - text = message_json["fallback"] - elif "text" in message_json: - if message_json['text'] is not None: - text = message_json["text"] - else: - text = "" - else: - text = "" - - text = unfurl_refs(text) - - if "edited" in message_json: - text += "{}{}{}".format( - w.color(config.color_edited_suffix), ' (edited)', w.color("reset")) - - 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): - text = render_formatting(text) - - text += create_reaction_string(message_json.get("reactions", "")) - message_json["_rendered_text"] = text - return text - - def linkify_text(message, team): # The get_username_map function is a bit heavy, but this whole # function is only called on message send.. |