aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2017-09-27 00:22:08 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2017-10-08 23:58:49 +0200
commite64293b41573b5caad2ebf343d9a4397cef22a67 (patch)
treecde7044956cd2331158f55da247994944d495550
parent4c63a2103635fb7ab8b19dbcbbc8d9df167542d5 (diff)
downloadwee-slack-e64293b41573b5caad2ebf343d9a4397cef22a67.tar.gz
fix: Update topic property in channel when topic changes
I also changed the channel to only store the topic value, since that is the only part of the topic property we get from Slack that we use.
-rw-r--r--wee_slack.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 46ad278..c7b08a7 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1107,8 +1107,8 @@ class SlackChannel(object):
self.members = set(kwargs.get('members', set()))
self.eventrouter = eventrouter
self.slack_name = kwargs["name"]
- self.slack_topic = kwargs.get("topic", {"value": ""})
self.slack_purpose = kwargs.get("purpose", {"value": ""})
+ self.topic = kwargs.get("topic", {}).get("value", "")
self.identifier = kwargs["id"]
self.last_read = SlackTS(kwargs.get("last_read", SlackTS()))
self.channel_buffer = None
@@ -1174,15 +1174,18 @@ class SlackChannel(object):
}
return select[style]
- def render_topic(self, topic=None):
+ def render_topic(self):
if self.channel_buffer:
- if not topic:
- if self.slack_topic['value'] != "":
- topic = self.slack_topic['value']
- else:
- topic = self.slack_purpose['value']
+ if self.topic != "":
+ topic = self.topic
+ else:
+ topic = self.slack_purpose['value']
w.buffer_set(self.channel_buffer, "title", topic)
+ def set_topic(self, value):
+ self.topic = value
+ self.render_topic()
+
def update_from_message_json(self, message_json):
for key, value in message_json.items():
setattr(self, key, value)
@@ -2335,7 +2338,7 @@ def subprocess_message_deleted(message_json, eventrouter, channel, team):
def subprocess_channel_topic(message_json, eventrouter, channel, team):
text = unhtmlescape(unfurl_refs(message_json["text"], ignore_alt_text=False))
channel.buffer_prnt(w.prefix("network").rstrip(), text, message_json["ts"], tagset="muted")
- channel.render_topic(unhtmlescape(message_json["topic"]))
+ channel.set_topic(unhtmlescape(message_json["topic"]))
def process_reply(message_json, eventrouter, **kwargs):
@@ -2869,7 +2872,7 @@ def topic_command_cb(data, current_buffer, command):
return w.WEECHAT_RC_OK_EAT
if topic is None:
- w.prnt(channel.channel_buffer, 'Topic for {} is "{}"'.format(channel.name, channel.slack_topic['value']))
+ w.prnt(channel.channel_buffer, 'Topic for {} is "{}"'.format(channel.name, channel.topic))
else:
s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier, "topic": topic}, team_hash=team.team_hash)
EVENTROUTER.receive(s)