diff --git a/main.py b/main.py index 3f91cdd..ef8c8ea 100644 --- a/main.py +++ b/main.py @@ -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 diff --git a/matrix/bar_items.py b/matrix/bar_items.py index bfa3ecb..226b80c 100644 --- a/matrix/bar_items.py +++ b/matrix/bar_items.py @@ -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() 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", "") diff --git a/matrix/config.py b/matrix/config.py index 7ad3c27..c96c4bb 100644 --- a/matrix/config.py +++ b/matrix/config.py @@ -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 = [ diff --git a/matrix/server.py b/matrix/server.py index e9cc585..2567982 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -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())