From 6718e2f88a9f9153b2b125ce9ec7c097a8d1ad61 Mon Sep 17 00:00:00 2001 From: Bryan Gilbert Date: Sun, 16 Jul 2017 20:59:58 -0400 Subject: call channel info on channel open to set unread count and update hotlist --- wee_slack.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index bf45ffc..367899c 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1111,6 +1111,7 @@ class SlackChannel(object): # short name relates to the localvar we change for typing indication self.current_short_name = self.name self.update_nicklist() + self.unread_count_display = 0 def __eq__(self, compare_str): if compare_str == self.slack_name or compare_str == self.formatted_name() or compare_str == self.formatted_name(style="long_default"): @@ -1136,6 +1137,14 @@ class SlackChannel(object): return True return False + def set_unread_count_display(self, count): + self.unread_count_display = count + if (self.unread_count_display > 0): + if self.type == "im": + w.buffer_set(self.channel_buffer, "hotlist", "2") + else: + w.buffer_set(self.channel_buffer, "hotlist", "1") + def formatted_name(self, style="default", typing=False, **kwargs): if config.channel_name_typing_indicator: if not typing: @@ -1174,9 +1183,6 @@ class SlackChannel(object): 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"], {"name": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier) - self.eventrouter.receive(s) # self.create_buffer() def check_should_open(self, force=False): @@ -1231,22 +1237,10 @@ class SlackChannel(object): w.buffer_set(self.channel_buffer, "localvar_set_server", self.team.preferred_name) # else: # self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self) - try: - for c in range(self.unread_count_display): - if self.type == "im": - w.buffer_set(self.channel_buffer, "hotlist", "2") - else: - w.buffer_set(self.channel_buffer, "hotlist", "1") - else: - pass - # dbg("no unread in {}".format(self.name)) - except: - pass - self.update_nicklist() - # dbg("exception no unread count") - # if self.unread_count != 0 and not self.muted: - # w.buffer_set(self.channel_buffer, "hotlist", "1") + 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) def destroy_buffer(self, update_remote): if self.channel_buffer is not None: @@ -2085,7 +2079,14 @@ def handle_rtmstart(login_data, eventrouter): # self.identifier = self.domain - +def handle_channelsinfo(channel_json, eventrouter, **kwargs): + unread_count_display = channel_json['channel']['unread_count_display'] + channel_id = channel_json['channel']['id'] + request_metadata = pickle.loads(channel_json["wee_slack_request_metadata"]) + team = eventrouter.teams[request_metadata.team_hash] + channel = team.channels[channel_id] + channel.set_unread_count_display(unread_count_display) + def handle_groupshistory(message_json, eventrouter, **kwargs): handle_history(message_json, eventrouter, **kwargs) -- cgit From 6106d9e766f0ea759be3ece5a74ab0e5c3833126 Mon Sep 17 00:00:00 2001 From: Bryan Gilbert Date: Mon, 17 Jul 2017 11:54:56 -0400 Subject: add group info request and handler to set unread count and update hotlist --- wee_slack.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wee_slack.py b/wee_slack.py index 367899c..f269349 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -56,6 +56,7 @@ SLACK_API_TRANSLATOR = { "join": "channels.join", "leave": "groups.leave", "mark": "groups.mark", + "info": "groups.info" }, "thread": { "history": None, @@ -2086,6 +2087,14 @@ def handle_channelsinfo(channel_json, eventrouter, **kwargs): team = eventrouter.teams[request_metadata.team_hash] channel = team.channels[channel_id] channel.set_unread_count_display(unread_count_display) + +def handle_groupsinfo(group_json, eventrouter, **kwargs): + unread_count_display = group_json['group']['unread_count_display'] + group_id = group_json['group']['id'] + request_metadata = pickle.loads(group_json["wee_slack_request_metadata"]) + team = eventrouter.teams[request_metadata.team_hash] + group = team.channels[group_id] + group.set_unread_count_display(unread_count_display) def handle_groupshistory(message_json, eventrouter, **kwargs): handle_history(message_json, eventrouter, **kwargs) -- cgit From cf925197db601bab09ddf5aecd38817b137a5689 Mon Sep 17 00:00:00 2001 From: Bryan Gilbert Date: Wed, 19 Jul 2017 11:49:27 -0400 Subject: use im.open endpoint to properly update unread count for ims on startup --- wee_slack.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index f269349..801b61d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1243,6 +1243,11 @@ class SlackChannel(object): 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 self.type == "im": + if "join" in SLACK_API_TRANSLATOR[self.type]: + s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["join"], {"user": self.user, "return_im": "true"}, team_hash=self.team.team_hash, channel_identifier=self.identifier) + self.eventrouter.receive(s) + def destroy_buffer(self, update_remote): if self.channel_buffer is not None: self.channel_buffer = None @@ -2081,20 +2086,26 @@ def handle_rtmstart(login_data, eventrouter): # self.identifier = self.domain def handle_channelsinfo(channel_json, eventrouter, **kwargs): - unread_count_display = channel_json['channel']['unread_count_display'] - channel_id = channel_json['channel']['id'] request_metadata = pickle.loads(channel_json["wee_slack_request_metadata"]) team = eventrouter.teams[request_metadata.team_hash] - channel = team.channels[channel_id] + channel = team.channels[request_metadata.channel_identifier] + unread_count_display = channel_json['channel']['unread_count_display'] channel.set_unread_count_display(unread_count_display) def handle_groupsinfo(group_json, eventrouter, **kwargs): - unread_count_display = group_json['group']['unread_count_display'] - group_id = group_json['group']['id'] request_metadata = pickle.loads(group_json["wee_slack_request_metadata"]) team = eventrouter.teams[request_metadata.team_hash] - group = team.channels[group_id] + group = team.channels[request_metadata.channel_identifier] + unread_count_display = group_json['group']['unread_count_display'] + group_id = group_json['group']['id'] group.set_unread_count_display(unread_count_display) + +def handle_imopen(im_json, eventrouter, **kwargs): + request_metadata = pickle.loads(im_json["wee_slack_request_metadata"]) + team = eventrouter.teams[request_metadata.team_hash] + im = team.channels[request_metadata.channel_identifier] + unread_count_display = im_json['channel']['unread_count_display'] + im.set_unread_count_display(unread_count_display) def handle_groupshistory(message_json, eventrouter, **kwargs): handle_history(message_json, eventrouter, **kwargs) -- cgit From d5177db702454bff3a7082fb6e0a10c14f950cbf Mon Sep 17 00:00:00 2001 From: Bryan Gilbert Date: Wed, 19 Jul 2017 12:02:32 -0400 Subject: restore call to update_nicklist() (accidental removal) --- wee_slack.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wee_slack.py b/wee_slack.py index 801b61d..31ee7f4 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1238,6 +1238,7 @@ class SlackChannel(object): w.buffer_set(self.channel_buffer, "localvar_set_server", self.team.preferred_name) # else: # self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self) + self.update_nicklist() 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) -- cgit