diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2021-05-08 20:11:37 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2021-05-08 20:41:34 +0200 |
commit | a191708db7a3edc99d9567efa523c75d03c134f3 (patch) | |
tree | dcc585482e2719ef4d166c3d2a83021579f171e5 /wee_slack.py | |
parent | 2c70f00a9996e104fbefefb8c2fd9d0103bbb04e (diff) | |
download | wee-slack-a191708db7a3edc99d9567efa523c75d03c134f3.tar.gz |
Support mpim_aware RTM API
Apparently, the API now sends an mpim_joined event when an MPIM is
created instead of a group_joined event, even if we don't set mpim_aware
to true.
Instead of just handling mpim_joined in addition to group_joined (which
could cause issues if both are called for MPIMs, though I haven't
experienced that), it's better to properly support mpim_aware.
Fixes #825, fixes #833
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/wee_slack.py b/wee_slack.py index bd03c7a..f8ea41d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3597,12 +3597,13 @@ def handle_rtmstart(login_data, eventrouter, team, channel, metadata): for item in login_data["ims"]: channels[item["id"]] = SlackDMChannel(eventrouter, users, **item) + for item in login_data["mpims"]: + channels[item["id"]] = SlackMPDMChannel( + eventrouter, users, login_data["self"]["id"], **item + ) + for item in login_data["groups"]: - if item["is_mpim"]: - channels[item["id"]] = SlackMPDMChannel( - eventrouter, users, login_data["self"]["id"], **item - ) - else: + if not item["is_mpim"]: channels[item["id"]] = SlackGroupChannel(eventrouter, **item) t = SlackTeam( @@ -4218,14 +4219,20 @@ def process_im_close(message_json, eventrouter, team, channel, metadata): ) +def process_mpim_joined(message_json, eventrouter, team, channel, metadata): + item = message_json["channel"] + channel = SlackMPDMChannel( + eventrouter, team.users, team.myidentifier, team=team, **item + ) + team.channels[item["id"]] = channel + channel.open() + + def process_group_joined(message_json, eventrouter, team, channel, metadata): item = message_json["channel"] - if item["name"].startswith("mpdm-"): - channel = SlackMPDMChannel( - eventrouter, team.users, team.myidentifier, team=team, **item - ) - else: - channel = SlackGroupChannel(eventrouter, team=team, **item) + if item["is_mpim"]: + return + channel = SlackGroupChannel(eventrouter, team=team, **item) team.channels[item["id"]] = channel channel.open() @@ -6623,10 +6630,14 @@ def trace_calls(frame, event, arg): def initiate_connection(token, retries=3, team=None, reconnect=False): + request_type = "connect" if team else "start" + post_data = {"batch_presence_aware": 1} + if request_type == "start": + post_data["mpim_aware"] = "true" return SlackRequest( team, - "rtm.{}".format("connect" if team else "start"), - {"batch_presence_aware": 1}, + "rtm.{}".format(request_type), + post_data, retries=retries, token=token, metadata={"reconnect": reconnect}, |