bar_items: Add a typing notice bar item.

This commit is contained in:
Damir Jelić 2018-11-01 11:56:43 +01:00
parent 6e27082c1a
commit 64bea928ef
4 changed files with 62 additions and 1 deletions

View file

@ -40,7 +40,8 @@ from matrix.bar_items import (
matrix_bar_item_lag,
matrix_bar_item_name,
matrix_bar_item_plugin,
matrix_bar_nicklist_count
matrix_bar_nicklist_count,
matrix_bar_typing_notices_cb
)
from matrix.buffer import room_buffer_close_cb, room_buffer_input_cb
# Weechat searches for the registered callbacks in the scope of the main script

View file

@ -16,6 +16,7 @@
from __future__ import unicode_literals
from . import globals as G
from .globals import SERVERS, W
from .utf import utf8_decode
@ -129,6 +130,41 @@ def matrix_bar_nicklist_count(data, item, window, buffer, extra_info):
return ""
@utf8_decode
def matrix_bar_typing_notices_cb(data, item, window, buffer, extra_info):
"""Update a status bar item showing users currently typing.
This function is called by weechat every time a buffer is switched or
W.bar_item_update(<item>) is explicitly called. The bar item shows
currently typing users for the current buffer."""
# pylint: disable=unused-argument
for server in SERVERS.values():
if buffer in server.buffers.values():
room_buffer = server.find_room_from_ptr(buffer)
room = room_buffer.room
if room.typing_users:
nicks = []
for user_id in room.typing_users:
nick = room_buffer.displayed_nicks.get(user_id, user_id)
nicks.append(nick)
msg = "{}{}".format(
G.CONFIG.look.bar_item_typing_notice_prefix,
", ".join(sorted(nicks))
)
max_len = G.CONFIG.look.max_typing_notice_item_length
if len(msg) > max_len:
msg[:max_len - 3] + "..."
return msg
return ""
return ""
def init_bar_items():
W.bar_item_new("(extra)buffer_plugin", "matrix_bar_item_plugin", "")
W.bar_item_new("(extra)buffer_name", "matrix_bar_item_name", "")
@ -138,5 +174,10 @@ def init_bar_items():
"matrix_bar_nicklist_count",
""
)
W.bar_item_new(
"(extra)matrix_typing_notice",
"matrix_bar_typing_notices_cb",
""
)
W.bar_item_new("(extra)buffer_modes", "matrix_bar_item_buffer_modes", "")
W.bar_item_new("(extra)matrix_modes", "matrix_bar_item_buffer_modes", "")

View file

@ -322,6 +322,24 @@ class MatrixConfig(WeechatConfig):
ServerBufferType,
config_server_buffer_cb,
),
Option(
"max_typing_notice_item_length",
"integer",
"",
10,
1000,
"50",
("Limit the length of the typing notice bar item."),
),
Option(
"bar_item_typing_notice_prefix",
"string",
"",
0,
0,
"Typing: ",
("Prefix for the typing notice bar item."),
),
]
network_options = [

View file

@ -949,6 +949,7 @@ class MatrixServer(object):
self.next_batch = response.next_batch
self.schedule_sync()
W.bar_item_update("matrix_typing_notice")
if self.rooms_with_missing_members:
self.get_joined_members(self.rooms_with_missing_members.pop())