aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTomas Varneckas <t.varneckas@gmail.com>2019-02-21 22:35:14 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2019-02-23 16:23:38 +0100
commit8d778b7ece7c8f484252b719464f7d05bab9bca4 (patch)
treeae6512d8c694745b9883c42ddf50aa4debd02cc6 /wee_slack.py
parentf5e977bceb7eab5327275f551dcf9c560118a4ad (diff)
downloadwee-slack-8d778b7ece7c8f484252b719464f7d05bab9bca4.tar.gz
Add ability to open last thread in channel without specifying message id
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py
index ea9858e..310be3c 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -3577,18 +3577,26 @@ def get_msg_from_id(channel, msg_id):
@utf8_decode
def command_thread(data, current_buffer, args):
"""
- /thread <message_id>
+ /thread [message_id]
Open the thread for the message.
+ If no message id is specified the last thread in channel will be opened.
"""
channel = EVENTROUTER.weechat_controller.buffers[current_buffer]
- if not args:
- w.prnt('', 'Usage: /thread <id>')
- return w.WEECHAT_RC_OK_EAT
- msg = get_msg_from_id(channel, args)
- if not msg:
- w.prnt('', 'ERROR: Invalid id given, must be an existing id')
- return w.WEECHAT_RC_OK_EAT
+ if args:
+ msg = get_msg_from_id(channel, args)
+ if not msg:
+ w.prnt('', 'ERROR: Invalid id given, must be an existing id')
+ return w.WEECHAT_RC_OK_EAT
+ else:
+ for message in reversed(channel.messages.values()):
+ if type(message) == SlackMessage and len(message.submessages) > 0:
+ msg = message
+ break
+ else:
+ w.prnt('', 'ERROR: No threads found in channel')
+ return w.WEECHAT_RC_OK_EAT
+
msg.open_thread(switch=config.switch_buffer_on_join)
return w.WEECHAT_RC_OK_EAT