call channel info on channel open to set unread count and update hotlist
@@ -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,6 +2079,13 @@ 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)
