aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorEric Wang <gnawrice@gmail.com>2017-10-23 21:02:03 -0700
committerEric Wang <gnawrice@gmail.com>2017-11-29 20:17:25 -0800
commit9e841e5614a97f7c21d9508fb1543c3053ad9128 (patch)
tree45563dfe7c37581a1af3c2d6bf1146b530618c70 /wee_slack.py
parentcdf6f49984d83d094999efcf5355d12e15ee4e51 (diff)
downloadwee-slack-9e841e5614a97f7c21d9508fb1543c3053ad9128.tar.gz
Fix MPDM joins not syncing with Slack and switch to mpim.open
conversations.open doesn't return `unread_count_display` for MPDMs for some reason (only DMs), so use mpim.open instead.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/wee_slack.py b/wee_slack.py
index ffd1c84..4b0de73 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -53,7 +53,7 @@ SLACK_API_TRANSLATOR = {
},
"mpim": {
"history": "mpim.history",
- "join": "conversations.open",
+ "join": "mpim.open", # conversations.open lacks unread_count_display
"leave": "conversations.close",
"mark": "mpim.mark",
"info": "groups.info",
@@ -1704,13 +1704,16 @@ class SlackMPDMChannel(SlackChannel):
self.set_name(n)
self.type = "mpim"
- def open(self, update_remote=False):
+ def open(self, update_remote=True):
self.create_buffer()
self.active = True
self.get_history()
if "info" in SLACK_API_TRANSLATOR[self.type]:
s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"channel": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
self.eventrouter.receive(s)
+ if update_remote and 'join' in SLACK_API_TRANSLATOR[self.type]:
+ s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]['join'], {'users': ','.join(self.members)}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
+ self.eventrouter.receive(s)
# self.create_buffer()
@staticmethod
@@ -2170,12 +2173,23 @@ def handle_groupsinfo(group_json, eventrouter, **kwargs):
group_id = group_json['group']['id']
group.set_unread_count_display(unread_count_display)
-def handle_conversationsopen(conversation_json, eventrouter, **kwargs):
+def handle_conversationsopen(conversation_json, eventrouter, object_name='channel', **kwargs):
request_metadata = pickle.loads(conversation_json["wee_slack_request_metadata"])
- team = eventrouter.teams[request_metadata.team_hash]
- conversation = team.channels[request_metadata.channel_identifier]
- unread_count_display = conversation_json['channel']['unread_count_display']
- conversation.set_unread_count_display(unread_count_display)
+
+ # Set unread count if the channel isn't new (channel_identifier exists)
+ try:
+ channel_id = request_metadata.channel_identifier
+ team = eventrouter.teams[request_metadata.team_hash]
+ conversation = team.channels[channel_id]
+ unread_count_display = conversation_json[object_name]['unread_count_display']
+ conversation.set_unread_count_display(unread_count_display)
+ except AttributeError:
+ pass
+
+
+def handle_mpimopen(mpim_json, eventrouter, object_name='group', **kwargs):
+ handle_conversationsopen(mpim_json, eventrouter, object_name, **kwargs)
+
def handle_groupshistory(message_json, eventrouter, **kwargs):
handle_history(message_json, eventrouter, **kwargs)