encryption: Add completion for device verification.
This commit is contained in:
parent
c8fb416f88
commit
87a8c1a5c0
3 changed files with 62 additions and 2 deletions
3
main.py
3
main.py
|
@ -64,7 +64,8 @@ from matrix.bar_items import (init_bar_items, matrix_bar_item_name,
|
||||||
from matrix.completion import (
|
from matrix.completion import (
|
||||||
init_completion, matrix_command_completion_cb,
|
init_completion, matrix_command_completion_cb,
|
||||||
matrix_server_command_completion_cb, matrix_debug_completion_cb,
|
matrix_server_command_completion_cb, matrix_debug_completion_cb,
|
||||||
matrix_message_completion_cb, matrix_server_completion_cb)
|
matrix_message_completion_cb, matrix_server_completion_cb,
|
||||||
|
matrix_olm_user_completion_cb, matrix_olm_device_completion_cb)
|
||||||
|
|
||||||
from matrix.utils import (key_from_value, server_buffer_prnt, prnt_debug,
|
from matrix.utils import (key_from_value, server_buffer_prnt, prnt_debug,
|
||||||
server_buffer_set_title)
|
server_buffer_set_title)
|
||||||
|
|
|
@ -118,6 +118,59 @@ def matrix_message_completion_cb(data, completion_item, buffer, completion):
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
|
||||||
|
def server_from_buffer(buffer):
|
||||||
|
for server in SERVERS.values():
|
||||||
|
if buffer in server.buffers.values():
|
||||||
|
return server
|
||||||
|
elif buffer == server.server_buffer:
|
||||||
|
return server
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@utf8_decode
|
||||||
|
def matrix_olm_user_completion_cb(data, completion_item, buffer, completion):
|
||||||
|
server = server_from_buffer(buffer)
|
||||||
|
|
||||||
|
if not server:
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
olm = server.olm
|
||||||
|
|
||||||
|
for user in olm.device_keys:
|
||||||
|
W.hook_completion_list_add(completion, user, 0,
|
||||||
|
W.WEECHAT_LIST_POS_SORT)
|
||||||
|
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
|
||||||
|
@utf8_decode
|
||||||
|
def matrix_olm_device_completion_cb(data, completion_item, buffer, completion):
|
||||||
|
server = server_from_buffer(buffer)
|
||||||
|
|
||||||
|
if not server:
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
olm = server.olm
|
||||||
|
|
||||||
|
args = W.hook_completion_get_string(completion, "args")
|
||||||
|
|
||||||
|
fields = args.split()
|
||||||
|
|
||||||
|
if len(fields) < 2:
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
user = fields[1]
|
||||||
|
|
||||||
|
if user not in olm.device_keys:
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
for device in olm.device_keys[user]:
|
||||||
|
W.hook_completion_list_add(completion, device.device_id, 0,
|
||||||
|
W.WEECHAT_LIST_POS_SORT)
|
||||||
|
|
||||||
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
|
||||||
def init_completion():
|
def init_completion():
|
||||||
W.hook_completion("matrix_server_commands", "Matrix server completion",
|
W.hook_completion("matrix_server_commands", "Matrix server completion",
|
||||||
"matrix_server_command_completion_cb", "")
|
"matrix_server_command_completion_cb", "")
|
||||||
|
@ -133,3 +186,9 @@ def init_completion():
|
||||||
|
|
||||||
W.hook_completion("matrix_debug_types", "Matrix debugging type completion",
|
W.hook_completion("matrix_debug_types", "Matrix debugging type completion",
|
||||||
"matrix_debug_completion_cb", "")
|
"matrix_debug_completion_cb", "")
|
||||||
|
|
||||||
|
W.hook_completion("olm_user_ids", "Matrix olm user id completion",
|
||||||
|
"matrix_olm_user_completion_cb", "")
|
||||||
|
|
||||||
|
W.hook_completion("olm_devices", "Matrix olm device id completion",
|
||||||
|
"matrix_olm_device_completion_cb", "")
|
||||||
|
|
|
@ -126,7 +126,7 @@ def matrix_hook_olm_command():
|
||||||
('info all|blacklisted|private|unverified|verified ||'
|
('info all|blacklisted|private|unverified|verified ||'
|
||||||
'blacklist %(device_ids) ||'
|
'blacklist %(device_ids) ||'
|
||||||
'unverify %(user_ids) %(device_ids) ||'
|
'unverify %(user_ids) %(device_ids) ||'
|
||||||
'verify %(user_ids) %(device_ids)'),
|
'verify %(olm_user_ids) %(olm_devices)'),
|
||||||
# Function name
|
# Function name
|
||||||
'matrix_olm_command_cb',
|
'matrix_olm_command_cb',
|
||||||
'')
|
'')
|
||||||
|
|
Loading…
Add table
Reference in a new issue