aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosip Janzic <josip@jjanzic.com>2018-10-21 18:34:12 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2018-10-21 18:34:12 +0200
commit1d831400e4d23b3a184ba2974b80032c8c0a94b4 (patch)
tree91e9ecc465b521caad4061b0c86aec6c4080db4c
parent469535e355b396153654ebef589db8e268ebccc7 (diff)
downloadwee-slack-1d831400e4d23b3a184ba2974b80032c8c0a94b4.tar.gz
Add option to show thread messages in parent channel (#616)
Closes #546
-rw-r--r--wee_slack.py72
1 files changed, 40 insertions, 32 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 9847f8d..b4c7d24 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -208,7 +208,7 @@ class ProxyWrapper(object):
self.proxy_user = ""
self.proxy_password = ""
self.has_proxy = False
-
+
if self.proxy_name:
self.proxy_string = "weechat.proxy.{}".format(self.proxy_name)
self.proxy_type = w.config_string(weechat.config_get("{}.type".format(self.proxy_string)))
@@ -220,21 +220,21 @@ class ProxyWrapper(object):
self.has_proxy = True
else:
w.prnt("", "\nWarning: weechat.network.proxy_curl is set to {} type (name : {}, conf string : {}). Only HTTP proxy is supported.\n\n".format(self.proxy_type, self.proxy_name, self.proxy_string))
-
+
def curl(self):
if not self.has_proxy:
return ""
-
+
if self.proxy_user and self.proxy_password:
user = "{}:{}@".format(self.proxy_user, self.proxy_password)
else:
user = ""
-
+
if self.proxy_port:
port = ":{}".format(self.proxy_port)
else:
port = ""
-
+
return "--proxy {}{}{}".format(user, self.proxy_address, port)
@@ -1535,7 +1535,7 @@ class SlackChannel(object):
m.message_json.update(message_json)
if text:
m.change_text(text)
- new_text = m.render(force=True)
+ new_text = self.render(m, force=True)
modify_buffer_line(self.channel_buffer, new_text, ts.major, ts.minor)
def edit_nth_previous_message(self, n, old, new, flags):
@@ -1742,6 +1742,17 @@ class SlackChannel(object):
self.hashed_messages[shorthash] = message
message.hash = shorthash
+ def render(self, message, force=False):
+ text = message.render(force)
+ if isinstance(message, SlackThreadMessage):
+ return '{}[{}]{} {}'.format(
+ w.color(config.thread_suffix_color),
+ message.parent_message.hash or message.parent_message.ts,
+ w.color('reset'),
+ text)
+
+ return text
+
class SlackDMChannel(SlackChannel):
"""
@@ -1985,15 +1996,7 @@ class SlackThreadChannel(object):
def get_history(self):
self.got_history = True
for message in self.parent_message.submessages:
-
- # message = SlackMessage(message_json, team, channel)
- text = message.render()
- # print text
-
- # try:
- # channel.unread_count += 1
- # except:
- # channel.unread_count = 1
+ text = self.render(message)
self.buffer_prnt(message.sender, text, message.ts)
def send_message(self, message, subtype=None):
@@ -2038,7 +2041,7 @@ class SlackThreadChannel(object):
w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True))
time_format = w.config_string(w.config_get("weechat.look.buffer_time_format"))
parent_time = time.localtime(SlackTS(self.parent_message.ts).major)
- topic = '{} {} | {}'.format(time.strftime(time_format, parent_time), self.parent_message.sender, self.parent_message.render() )
+ topic = '{} {} | {}'.format(time.strftime(time_format, parent_time), self.parent_message.sender, self.render(self.parent_message) )
w.buffer_set(self.channel_buffer, "title", topic)
# self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
@@ -2066,6 +2069,9 @@ class SlackThreadChannel(object):
# if update_remote and not eventrouter.shutting_down:
self.active = False
+ def render(self, message, force=False):
+ return message.render(force)
+
class SlackUser(object):
"""
@@ -2159,7 +2165,7 @@ 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, self.channel, force)
+ text = render(self.message_json, self.team, force)
if (self.message_json.get('subtype') == 'me_message' and
not self.message_json['text'].startswith(self.sender)):
text = "{} {}".format(self.sender, text)
@@ -2248,9 +2254,9 @@ class SlackMessage(object):
class SlackThreadMessage(SlackMessage):
- def __init__(self, parent_id, *args):
+ def __init__(self, parent_message, *args):
super(SlackThreadMessage, self).__init__(*args)
- self.parent_id = parent_id
+ self.parent_message = parent_message
class WeeSlackMetadata(object):
@@ -2562,7 +2568,7 @@ def process_message(message_json, eventrouter, store=True, **kwargs):
subtype_functions[subtype](message_json, eventrouter, channel, team)
else:
message = SlackMessage(message_json, team, channel)
- text = message.render()
+ text = channel.render(message)
dbg("Rendered message: %s" % text)
dbg("Sender: %s (%s)" % (message.sender, message.sender_plain))
@@ -2586,19 +2592,22 @@ def subprocess_thread_message(message_json, eventrouter, channel, team):
if parent_ts:
parent_message = channel.messages.get(SlackTS(parent_ts), None)
if parent_message:
- message = SlackThreadMessage(parent_ts, message_json, team, channel)
+ message = SlackThreadMessage(
+ parent_message, message_json, team, channel)
parent_message.submessages.append(message)
channel.hash_message(parent_ts)
channel.store_message(message, team)
channel.change_message(parent_ts)
- text = message.render()
- # channel.buffer_prnt(message.sender, text, message.ts, **kwargs)
if parent_message.thread_channel and parent_message.thread_channel.active:
- parent_message.thread_channel.buffer_prnt(message.sender, text, message.ts, tag_nick=message.sender_plain)
+ parent_message.thread_channel.buffer_prnt(message.sender, parent_message.thread_channel.render(message), message.ts, tag_nick=message.sender_plain)
elif message.ts > channel.last_read and message.has_mention():
parent_message.notify_thread(action="mention", sender_id=message_json["user"])
+ if config.thread_messages_in_channel:
+ channel.buffer_prnt(
+ message.sender, channel.render(message), message.ts, tag_nick=message.sender_plain)
+
# channel = channels.find(message_json["channel"])
# server = channel.server
# #threadinfo = channel.get_message(message_json["thread_ts"])
@@ -2621,14 +2630,14 @@ def subprocess_thread_message(message_json, eventrouter, channel, team):
def subprocess_channel_join(message_json, eventrouter, channel, team):
joinprefix = w.prefix("join").strip()
message = SlackMessage(message_json, team, channel, override_sender=joinprefix)
- channel.buffer_prnt(joinprefix, message.render(), message_json["ts"], tagset='joinleave')
+ channel.buffer_prnt(joinprefix, channel.render(message), message_json["ts"], tagset='joinleave')
channel.user_joined(message_json['user'])
def subprocess_channel_leave(message_json, eventrouter, channel, team):
leaveprefix = w.prefix("quit").strip()
message = SlackMessage(message_json, team, channel, override_sender=leaveprefix)
- channel.buffer_prnt(leaveprefix, message.render(), message_json["ts"], tagset='joinleave')
+ channel.buffer_prnt(leaveprefix, channel.render(message), message_json["ts"], tagset='joinleave')
channel.user_left(message_json['user'])
# channel.update_nicklist(message_json['user'])
# channel.update_nicklist()
@@ -2795,7 +2804,7 @@ def render_formatting(text):
return text
-def render(message_json, team, channel, force=False):
+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"]
@@ -2827,10 +2836,6 @@ def render(message_json, team, channel, force=False):
if message_json.get('mrkdwn', True):
text = render_formatting(text)
-# if self.threads:
-# text += " [Replies: {} Thread ID: {} ] ".format(len(self.threads), self.thread_id)
-# #for thread in self.threads:
-
text += create_reaction_string(message_json.get("reactions", ""))
message_json["_rendered_text"] = text
return text
@@ -3328,7 +3333,7 @@ def command_register_callback(data, command, return_code, out, err):
w.prnt("", "ERROR: problem when trying to get Slack OAuth token. Got return code {}. Err: ".format(return_code, err))
w.prnt("", "Check the network or proxy settings")
return w.WEECHAT_RC_OK_EAT
-
+
if len(out) <= 0:
w.prnt("", "ERROR: problem when trying to get Slack OAuth token. Got 0 length answer. Err: ".format(err))
w.prnt("", "Check the network or proxy settings")
@@ -3923,6 +3928,9 @@ class PluginConfig(object):
'switch_buffer_on_join': Setting(
default='true',
desc='When /joining a channel, automatically switch to it as well.'),
+ 'thread_messages_in_channel': Setting(
+ default='false',
+ desc='When enabled shows thread messages in the parent channel.'),
'thread_suffix_color': Setting(
default='lightcyan',
desc='Color to use for the [thread: XXX] suffix on messages that'