aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_conversation.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-07-11 22:13:40 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit9457fb1de585458db6330e0b52805131300584c6 (patch)
tree4ba82bda8f2ce3c704353d0659f37c4e1995f28e /slack/slack_conversation.py
parente6afe041876394a6f75cbb3e8671faa3dd91b0cc (diff)
downloadwee-slack-9457fb1de585458db6330e0b52805131300584c6.tar.gz
Set buffer properties
Diffstat (limited to 'slack/slack_conversation.py')
-rw-r--r--slack/slack_conversation.py57
1 files changed, 45 insertions, 12 deletions
diff --git a/slack/slack_conversation.py b/slack/slack_conversation.py
index 1e8728d..00052af 100644
--- a/slack/slack_conversation.py
+++ b/slack/slack_conversation.py
@@ -68,6 +68,17 @@ class SlackConversation:
def id(self) -> str:
return self._info["id"]
+ @property
+ def type(self) -> Literal["channel", "private", "mpim", "im"]:
+ if self._info["is_im"] is True:
+ return "im"
+ elif self._info["is_mpim"] is True:
+ return "mpim"
+ elif self._info["is_private"] is True:
+ return "private"
+ else:
+ return "channel"
+
async def name(self) -> str:
if self._info["is_im"] is True:
im_user = await self.workspace.users[self._info["user"]]
@@ -128,20 +139,42 @@ class SlackConversation:
return
name = await self.name()
- full_name = f"{shared.SCRIPT_NAME}.{self.workspace.name}.{self.name_prefix('full_name')}{name}"
+ name_with_prefix_for_full_name = f"{self.name_prefix('full_name')}{name}"
+ full_name = f"{shared.SCRIPT_NAME}.{self.workspace.name}.{name_with_prefix_for_full_name}"
short_name = self.name_prefix("short_name") + name
- self.buffer_pointer = weechat.buffer_new(
- full_name,
- get_callback_name(self._buffer_input_cb),
- "",
- get_callback_name(self._buffer_close_cb),
- "",
- )
- weechat.buffer_set(self.buffer_pointer, "short_name", short_name)
- weechat.buffer_set(
- self.buffer_pointer, "localvar_set_nick", self.workspace.my_user.nick()
- )
+ buffer_props = {
+ "short_name": short_name,
+ "title": "topic",
+ "input_multiline": "1",
+ "localvar_set_type": (
+ "private" if self.type in ("im", "mpim") else "channel"
+ ),
+ "localvar_set_slack_type": self.type,
+ "localvar_set_nick": self.workspace.my_user.nick(),
+ "localvar_set_channel": name_with_prefix_for_full_name,
+ "localvar_set_server": self.workspace.name,
+ }
+
+ if shared.weechat_version >= 0x03050000:
+ self.buffer_pointer = weechat.buffer_new_props(
+ full_name,
+ buffer_props,
+ get_callback_name(self._buffer_input_cb),
+ "",
+ get_callback_name(self._buffer_close_cb),
+ "",
+ )
+ else:
+ self.buffer_pointer = weechat.buffer_new(
+ full_name,
+ get_callback_name(self._buffer_input_cb),
+ "",
+ get_callback_name(self._buffer_close_cb),
+ "",
+ )
+ for prop_name, value in buffer_props.items():
+ weechat.buffer_set(self.buffer_pointer, prop_name, value)
self.workspace.open_conversations[self.id] = self