diff options
-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))) |