aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2019-06-02 22:16:07 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2019-06-02 23:09:20 +0200
commit593ea9ffa6c96e46c9b5bdf2f07369f0130549a2 (patch)
treebc8e9771a39d971fd8296dd9cf2894dbdd34da34 /wee_slack.py
parentdddb6d674985be2c17fec0297d6dc138c9c95c7d (diff)
downloadwee-slack-593ea9ffa6c96e46c9b5bdf2f07369f0130549a2.tar.gz
Unfurl and linkify in topic command
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 2aea305..38407df 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1559,16 +1559,19 @@ class SlackChannel(SlackChannelCommon):
}
return select[style]
- def render_topic(self):
+ def render_topic(self, fallback_to_purpose=False):
+ topic = self.topic['value']
+ if not topic and fallback_to_purpose:
+ topic = self.slack_purpose['value']
+ return unhtmlescape(unfurl_refs(topic, ignore_alt_text=False))
+
+ def set_topic(self, value=None):
+ if value is not None:
+ self.topic = {"value": value}
if self.channel_buffer:
- topic = self.topic['value'] or self.slack_purpose['value']
- topic = unhtmlescape(unfurl_refs(topic, ignore_alt_text=False))
+ topic = self.render_topic(fallback_to_purpose=True)
w.buffer_set(self.channel_buffer, "title", topic)
- def set_topic(self, value):
- self.topic = {"value": value}
- self.render_topic()
-
def update_from_message_json(self, message_json):
for key, value in message_json.items():
setattr(self, key, value)
@@ -1643,7 +1646,7 @@ class SlackChannel(SlackChannelCommon):
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.set_topic()
self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
if self.channel_buffer:
# if self.team.server_alias:
@@ -3493,9 +3496,11 @@ 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.topic['value']))
+ w.prnt(channel.channel_buffer,
+ 'Topic for {} is "{}"'.format(channel.name, channel.render_topic()))
else:
- s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier, "topic": topic}, team_hash=team.team_hash)
+ s = SlackRequest(team.token, "channels.setTopic", {"channel": channel.identifier,
+ "topic": linkify_text(topic, team)}, team_hash=team.team_hash)
EVENTROUTER.receive(s)
return w.WEECHAT_RC_OK_EAT