aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2015-11-13 17:27:09 +0000
committerRyan Huber <rhuber@gmail.com>2015-11-13 17:27:09 +0000
commit8de3be3748533eceacfb4e3fe908d2d7cc8d3a99 (patch)
treefdf0694eeb9b7c367e0b2dcdaedf668ba7c25a8d
parent7315b08e11f64a8b8425fb673a6bc76f69887664 (diff)
downloadwee-slack-8de3be3748533eceacfb4e3fe908d2d7cc8d3a99.tar.gz
new render message function split out. still need to dry up
-rw-r--r--wee_slack.py59
1 files changed, 56 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 38ae049..3abbc36 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -633,16 +633,17 @@ class Channel(object):
if text is not None:
self.messages[message_index].change_text(text)
else:
- text = self.messages[message_index].message_json["text"]
+ text = render_message(self.messages[message_index].message_json)
+ #text = self.messages[message_index].message_json["text"]
#render reactions if we have any
- react = create_reaction_string(self.messages[message_index].message_json["reactions"])
+ #react = create_reaction_string(self.messages[message_index].message_json["reactions"])
#if there is only one message with this timestamp, modify it directly.
#we do this because time resolution in weechat is less than slack
int_time = int(float(ts))
if self.messages.count(str(int_time)) == 1:
- modify_buffer_line(self.channel_buffer, text + react, int_time)
+ modify_buffer_line(self.channel_buffer, text, int_time)
#otherwise redraw the whole buffer, which is expensive
else:
self.buffer_redraw()
@@ -1399,6 +1400,57 @@ def modify_buffer_line(buffer, new_line, time):
line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1)
return w.WEECHAT_RC_OK
+def render_message(message_json, cache=True):
+ try:
+ message_json = unwrap_message(message_json)
+
+ server = servers.find(message_json["myserver"])
+ channel = channels.find(message_json["channel"])
+
+ #do not process messages in unexpected channels
+ if not channel.active:
+ channel.open(False)
+ dbg("message came for closed channel {}".format(channel.name))
+ return
+
+ time = message_json['ts']
+ 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 = text.decode('utf-8')
+
+ text = unfurl_refs(text, ignore_alt_text=unfurl_ignore_alt_text)
+
+ if "attachments" in message_json:
+ text += u" --- {}".format(unwrap_attachments(message_json))
+ text = text.lstrip()
+ text = text.replace("\t", " ")
+ name = get_user(message_json, server)
+
+ text = text.encode('utf-8')
+ name = name.encode('utf-8')
+
+ if "reactions" in message_json:
+ text += create_reaction_string(message_json["reactions"])
+
+ w.prnt("", "rendered message")
+ return text
+
+
+
+
+ except Exception:
+ if channel and ("text" in message_json) and message_json['text'] is not None:
+ channel.buffer_prnt('unknown', message_json['text'])
+ dbg("cannot process message {}\n{}".format(message_json, traceback.format_exc()))
+
def process_message(message_json, cache=True):
global unfurl_ignore_alt_text
@@ -1455,6 +1507,7 @@ def process_message(message_json, cache=True):
append = ''
channel.change_message(message_json["message"]["ts"], text + append)
cache=False
+
elif "subtype" in message_json and message_json["subtype"] == "message_deleted":
append = "(deleted)"
text = ""