diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-06-01 20:04:23 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-06-02 23:09:20 +0200 |
commit | d0b3e45dbe1b35e4d966733867ac7e3ee05e7630 (patch) | |
tree | e19d4f2fff03432fa0070abe92abec032a9528a7 /wee_slack.py | |
parent | 54134d675b323eb86bf63286d82454d027f3b8e7 (diff) | |
download | wee-slack-d0b3e45dbe1b35e4d966733867ac7e3ee05e7630.tar.gz |
Set own nick to display name if set
Previously, own nick would always be set to the username.
Fixes #692
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py index ad695b1..e38c877 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2217,13 +2217,7 @@ class SlackUser(object): for key, value in kwargs.items(): setattr(self, key, value) - if self.profile.get("display_name"): - self.slack_name = self.profile["display_name"] - self.name = self.profile["display_name"].replace(' ', '') - else: - # No display name set. Fall back to the deprecated username field. - self.slack_name = kwargs["name"] - self.name = self.slack_name + self.name = nick_from_profile(self.profile, kwargs["name"]) self.update_color() def __repr__(self): @@ -2545,13 +2539,20 @@ def handle_rtmstart(login_data, eventrouter): else: channels[item["id"]] = SlackGroupChannel(eventrouter, **item) + self_profile = next( + user["profile"] + for user in login_data["users"] + if user["id"] == login_data["self"]["id"] + ) + self_nick = nick_from_profile(self_profile, login_data["self"]["name"]) + t = SlackTeam( eventrouter, metadata.token, login_data['url'], login_data["team"], subteams, - login_data["self"]["name"], + self_nick, login_data["self"]["id"], users, bots, @@ -3374,6 +3375,11 @@ def modify_last_print_time(buffer_pointer, ts_minor): return w.WEECHAT_RC_OK +def nick_from_profile(profile, username): + nick = profile.get('display_name') or username + return nick.replace(' ', '') + + def format_nick(nick, previous_nick=None): if nick == previous_nick: nick = w.config_string(w.config_get('weechat.look.prefix_same_nick')) or nick |