diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-12-30 22:43:23 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2024-02-18 11:32:54 +0100 |
commit | 51211931453f02a233ed38a35cde30981d6298ba (patch) | |
tree | b93c164868b51733e6261b680aa17f29cd9be983 /slack/commands.py | |
parent | c05d66e21a6e946b3fa0b1a48835860d1bb511a1 (diff) | |
download | wee-slack-51211931453f02a233ed38a35cde30981d6298ba.tar.gz |
Perform nick completion in last spoken order
This makes it complete nicks that spoke last first, and then nicks that
haven't spoken, and lastly yourself. This is the same as the IRC plugin
does by default.
It adds completion of nicks both with and without @, as the default
completion of nicks from the nicklist is just alphabetical.
Completion of workspace nicks is removed for now. It only completed
workspace nicks that are already loaded, so it might be better to
complete workspace nicks in the `input_complete_cb` function instead
(since functions using `completion_list_add` can't be async, only
`input_complete_cb` can).
Diffstat (limited to 'slack/commands.py')
-rw-r--r-- | slack/commands.py | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/slack/commands.py b/slack/commands.py index 58f464c..4fc3ce7 100644 --- a/slack/commands.py +++ b/slack/commands.py @@ -1,7 +1,6 @@ from __future__ import annotations import json -import locale import pprint import re from dataclasses import dataclass @@ -494,27 +493,62 @@ def completion_nicks_cb( if slack_buffer is None: return weechat.WEECHAT_RC_OK - buffer_nicks = set(f"@{user.nick(only_nick=True)}" for user in slack_buffer.members) - for nick in sorted(buffer_nicks, key=locale.strxfrm): + buffer_nicks = [user.nick() for user in slack_buffer.members] + for nick in buffer_nicks: weechat.completion_list_add( completion, nick, 1, - weechat.WEECHAT_LIST_POS_END, + weechat.WEECHAT_LIST_POS_SORT, + ) + weechat.completion_list_add( + completion, + f"@{nick}", + 1, + weechat.WEECHAT_LIST_POS_SORT, ) - workspace_nicks = set( - f"@{user.result().nick(only_nick=True)}" - for user in slack_buffer.workspace.users.values() - if user.done_with_result() - ) - for nick in sorted(workspace_nicks - buffer_nicks, key=locale.strxfrm): + senders = [ + m.sender_user_id + for m in slack_buffer.messages.values() + if m.sender_user_id and m.subtype in [None, "me_message", "thread_broadcast"] + ] + unique_senders = list(dict.fromkeys(senders)) + sender_user_futures = [ + slack_buffer.workspace.users[sender] for sender in unique_senders + ] + sender_users = [ + future.result() for future in sender_user_futures if future.done_with_result() + ] + nicks = [user.nick() for user in sender_users] + for nick in nicks: weechat.completion_list_add( completion, nick, 1, - weechat.WEECHAT_LIST_POS_END, + weechat.WEECHAT_LIST_POS_BEGINNING, ) + weechat.completion_list_add( + completion, + f"@{nick}", + 1, + weechat.WEECHAT_LIST_POS_BEGINNING, + ) + + my_user_nick = slack_buffer.workspace.my_user.nick() + weechat.completion_list_add( + completion, + my_user_nick, + 1, + weechat.WEECHAT_LIST_POS_END, + ) + weechat.completion_list_add( + completion, + f"@{my_user_nick}", + 1, + weechat.WEECHAT_LIST_POS_END, + ) + return weechat.WEECHAT_RC_OK |