diff options
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/wee_slack.py b/wee_slack.py index ec08206..0da53f0 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, @@ -974,6 +975,7 @@ class SlackTeam(object): self.channel_buffer = w.buffer_new("{}".format(self.preferred_name), "buffer_input_callback", "EVENTROUTER", "", "") self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self) w.buffer_set(self.channel_buffer, "localvar_set_type", 'server') + w.buffer_set(self.channel_buffer, "localvar_set_nick", self.nick) if w.config_string(w.config_get('irc.look.server_buffer')) == 'merge_with_core': w.buffer_merge(self.channel_buffer, w.buffer_search_main()) w.buffer_set(self.channel_buffer, "nicklist", "1") @@ -1111,6 +1113,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 +1139,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 +1185,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): @@ -1221,6 +1229,7 @@ class SlackChannel(object): else: w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel') w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name()) + w.buffer_set(self.channel_buffer, "localvar_set_nick", self.team.nick) w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True)) self.render_topic() self.eventrouter.weechat_controller.set_refresh_buffer_list(True) @@ -1231,22 +1240,16 @@ 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) + + 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: @@ -1765,6 +1768,7 @@ class SlackThreadChannel(object): self.channel_buffer = w.buffer_new(self.formatted_name(style="long_default"), "buffer_input_callback", "EVENTROUTER", "", "") self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self) w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel') + w.buffer_set(self.channel_buffer, "localvar_set_nick", self.team.nick) w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name()) w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True)) time_format = w.config_string(w.config_get("weechat.look.buffer_time_format")) @@ -2085,7 +2089,28 @@ def handle_rtmstart(login_data, eventrouter): # self.identifier = self.domain - +def handle_channelsinfo(channel_json, eventrouter, **kwargs): + request_metadata = pickle.loads(channel_json["wee_slack_request_metadata"]) + team = eventrouter.teams[request_metadata.team_hash] + 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): + request_metadata = pickle.loads(group_json["wee_slack_request_metadata"]) + team = eventrouter.teams[request_metadata.team_hash] + 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) @@ -2811,14 +2836,17 @@ def msg_command_cb(data, current_buffer, args): dbg("msg_command_cb") aargs = args.split(None, 2) who = aargs[1] - command_talk(data, current_buffer, who) + if who == "*": + who = EVENTROUTER.weechat_controller.buffers[current_buffer].slack_name + else: + command_talk(data, current_buffer, who) if len(aargs) > 2: message = aargs[2] team = EVENTROUTER.weechat_controller.buffers[current_buffer].team cmap = team.get_channel_map() if who in cmap: - channel = team.channels[cmap[channel]] + channel = team.channels[cmap[who]] channel.send_message(message) return w.WEECHAT_RC_OK_EAT |