diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-03-18 00:26:46 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2020-03-18 01:02:54 +0100 |
commit | 8e13b38200f83d4a6fde15188aa00f7679eb17d7 (patch) | |
tree | d3ec7fb6587b87cb96120f209aaf836ed252a597 | |
parent | f61e946f647b797e4268405df8160dae818e19ab (diff) | |
download | wee-slack-8e13b38200f83d4a6fde15188aa00f7679eb17d7.tar.gz |
Reply to parent message if trying to reply to thread message
Opening a thread on a thread message is not possible, so the logical
thing to do if a user tries to reply to a thread message is to put the
message in the same thread as the message that is replied to.
Slack currently has a bug which causes thread messages to be converted
to normal messages if you try to reply to them (that is, send a message
with thread_ts set to the ts of the thread message), but the message you
reply with will end up in the original thread. I filed an issue and they
confirmed that it is a bug, and that you should not send messages with
thread_ts set to the ts of a thread message.
Fixes #751
-rw-r--r-- | _pytest/test_command_reply.py | 25 | ||||
-rw-r--r-- | wee_slack.py | 5 |
2 files changed, 29 insertions, 1 deletions
diff --git a/_pytest/test_command_reply.py b/_pytest/test_command_reply.py new file mode 100644 index 0000000..bbff617 --- /dev/null +++ b/_pytest/test_command_reply.py @@ -0,0 +1,25 @@ +from __future__ import print_function, unicode_literals + +import json + +from wee_slack import SlackTS, command_reply + +parent_ts = SlackTS('1485975824.000004') +child_ts = SlackTS('1485975835.000005') + +def test_replying_to_child_should_use_parent_ts(realish_eventrouter, team, channel_general): + datafiles = [ + '_pytest/data/websocket/1485975824.48-message.json', + '_pytest/data/websocket/1485975836.23-message.json' + ] + for datafile in datafiles: + data = json.loads(open(datafile).read()) + team.ws.add(data) + realish_eventrouter.receive_ws_callback(team.team_hash, None) + realish_eventrouter.handle_next() + + child_hash = channel_general.hash_message(child_ts) + command_reply(None, channel_general.channel_buffer, '${} test'.format(child_hash)) + + sent = json.loads(team.ws.sentdata[0]) + assert sent['thread_ts'] == parent_ts diff --git a/wee_slack.py b/wee_slack.py index 82a91b4..3dd10cc 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4075,7 +4075,10 @@ def command_reply(data, current_buffer, args): msg = get_msg_from_id(channel, msg_id) if msg: - parent_id = str(msg.ts) + if isinstance(msg, SlackThreadMessage): + parent_id = str(msg.parent_message.ts) + else: + parent_id = str(msg.ts) elif msg_id.isdigit() and int(msg_id) >= 1: mkeys = channel.main_message_keys_reversed() parent_id = str(next(islice(mkeys, int(msg_id) - 1, None))) |