diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2018-01-27 13:00:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-27 13:00:10 +0100 |
commit | 01a3032162e48bbb0e3a9a974f9561aaacc7f814 (patch) | |
tree | 6c82061a9bf6480c6a85b5a5de205131f6a34e2f | |
parent | 3c8f78ab74f6523fc66c76fad386a6492126ea2a (diff) | |
parent | 08d62d3620a3e4d9985f105874a39a08227cae7d (diff) | |
download | wee-slack-01a3032162e48bbb0e3a9a974f9561aaacc7f814.tar.gz |
Merge pull request #496 from immae/presence_subscription
Fix presence subscription now mandatory to get state changes
-rw-r--r-- | wee_slack.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py index d131811..c452b1b 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -195,7 +195,6 @@ def get_nick_color_name(nick): ##### BEGIN NEW IGNORED_EVENTS = [ - "hello", # "pref_change", # "reconnect_url", ] @@ -1108,7 +1107,7 @@ class SlackTeam(object): # The fast reconnect failed, so start over-ish for chan in self.channels: self.channels[chan].got_history = False - s = SlackRequest(self.token, 'rtm.start', {}, retries=999) + s = initiate_connection(self.token, retries=999) self.eventrouter.receive(s) self.connecting = False # del self.eventrouter.teams[self.get_team_hash()] @@ -1151,6 +1150,11 @@ class SlackTeam(object): if user.id in c.members: c.update_nicklist(user.id) + def subscribe_users_presence(self): + self.send_to_websocket({ + "type": "presence_sub", + "ids": self.users.keys(), + }, expect_reply=False) class SlackChannel(object): """ @@ -2234,6 +2238,8 @@ def handle_history(message_json, eventrouter, **kwargs): ###### New/converted process_ and subprocess_ methods +def process_hello(message_json, eventrouter, **kwargs): + kwargs['team'].subscribe_users_presence() def process_reconnect_url(message_json, eventrouter, **kwargs): kwargs['team'].set_reconnect_url(message_json['url']) @@ -2245,9 +2251,15 @@ def process_manual_presence_change(message_json, eventrouter, **kwargs): def process_presence_change(message_json, eventrouter, **kwargs): if "user" in kwargs: + # TODO: remove once it's stable user = kwargs["user"] team = kwargs["team"] team.update_member_presence(user, message_json["presence"]) + if "users" in message_json: + team = kwargs["team"] + for user_id in message_json["users"]: + user = team.users[user_id] + team.update_member_presence(user, message_json["presence"]) def process_pref_change(message_json, eventrouter, **kwargs): @@ -3705,6 +3717,11 @@ def trace_calls(frame, event, arg): f.flush() return +def initiate_connection(token, retries=3): + return SlackRequest(token, + 'rtm.start', + {"batch_presence_aware": 1 }, + retries=retries) # Main if __name__ == "__main__": @@ -3751,7 +3768,7 @@ if __name__ == "__main__": tokens = config.slack_api_token.split(',') for t in tokens: - s = SlackRequest(t, 'rtm.start', {}) + s = initiate_connection(t) EVENTROUTER.receive(s) if config.record_events: EVENTROUTER.record() |