diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-01-15 13:08:31 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:53 +0100 |
commit | 7b9cf4d9278f584c4ce754e3dfbbcd245b1f9985 (patch) | |
tree | 5a0da39b050ebd94324d0ad508dafb29f9921c24 /slack/slack_user.py | |
parent | 3ce4745910e58275871d06073904d4660756b988 (diff) | |
download | wee-slack-7b9cf4d9278f584c4ce754e3dfbbcd245b1f9985.tar.gz |
Show nick suffix for external users
Diffstat (limited to 'slack/slack_user.py')
-rw-r--r-- | slack/slack_user.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/slack/slack_user.py b/slack/slack_user.py index 5baaf02..7b04605 100644 --- a/slack/slack_user.py +++ b/slack/slack_user.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING import weechat +from slack.shared import shared from slack.util import with_color if TYPE_CHECKING: @@ -19,11 +20,6 @@ class SlackUser: def _api(self) -> SlackApi: return self.workspace.api - @property - def nick(self) -> str: - nick = self._nick_from_profile() - return nick.replace(" ", "") - async def init(self): info = await self._api.fetch_users_info(self) if info["ok"] is False: @@ -31,24 +27,35 @@ class SlackUser: raise Exception("Failed fetching user info") self._info = info["user"] - def formatted_name(self, prepend: str = "", enable_color: bool = True): - name = prepend + self.nick - if enable_color: - return with_color(self._nick_color(name), name) - else: - return name + def nick(self, colorize: bool = False) -> str: + nick = self._name_without_spaces() + + if colorize: + nick = with_color(self._nick_color(), nick) - def _nick_from_profile(self) -> str: - if self.workspace.config.use_real_names.value: - return self._info["real_name"] + if self._info["profile"]["team"] != self.workspace.id: + nick += shared.config.look.external_user_suffix.value + return nick + + def _name_from_profile(self) -> str: display_name = self._info["profile"].get("display_name") - return display_name or self._info["real_name"] + if display_name and not self.workspace.config.use_real_names.value: + return display_name + + return ( + self._info["profile"].get("display_name") + or self._info.get("real_name") + or self._info["name"] + ) + + def _name_without_spaces(self) -> str: + return self._name_from_profile().replace(" ", "") - def _nick_color(self, nick: str) -> str: + def _nick_color(self) -> str: if self.id == self.workspace.my_user.id: return weechat.config_string( weechat.config_get("weechat.color.chat_nick_self") ) - return weechat.info_get("nick_color_name", nick) + return weechat.info_get("nick_color_name", self._name_without_spaces()) |