Initial nicklist handling implementation.
This commit is contained in:
parent
a6bafb79f2
commit
c71770cf90
1 changed files with 42 additions and 32 deletions
|
@ -37,8 +37,6 @@ SERVERS = dict() # type: Dict[unicode, MatrixServer]
|
||||||
CONFIG = None # type: weechat.config
|
CONFIG = None # type: weechat.config
|
||||||
GLOBAL_OPTIONS = None # type: PluginOptions
|
GLOBAL_OPTIONS = None # type: PluginOptions
|
||||||
|
|
||||||
NICK_GROUP_HERE = "0|Here"
|
|
||||||
|
|
||||||
|
|
||||||
# Unicode handling
|
# Unicode handling
|
||||||
def encode_to_utf8(data):
|
def encode_to_utf8(data):
|
||||||
|
@ -572,6 +570,29 @@ def strip_matrix_server(string):
|
||||||
return string.rsplit(":", 1)[0]
|
return string.rsplit(":", 1)[0]
|
||||||
|
|
||||||
|
|
||||||
|
def add_user_to_nicklist(buf, user):
|
||||||
|
group_name = "999|..."
|
||||||
|
|
||||||
|
if user.power_level >= 100:
|
||||||
|
group_name = "000|o"
|
||||||
|
elif user.power_level >= 50:
|
||||||
|
group_name = "001|h"
|
||||||
|
elif user.power_level > 0:
|
||||||
|
group_name = "002|v"
|
||||||
|
|
||||||
|
group = W.nicklist_search_group(buf, "", group_name)
|
||||||
|
# TODO make it configurable so we can use a display name or user_id here
|
||||||
|
W.nicklist_add_nick(
|
||||||
|
buf,
|
||||||
|
group,
|
||||||
|
user.display_name,
|
||||||
|
user.nick_color,
|
||||||
|
user.prefix,
|
||||||
|
get_prefix_color(user.prefix),
|
||||||
|
1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def matrix_create_room_buffer(server, room_id):
|
def matrix_create_room_buffer(server, room_id):
|
||||||
# type: (MatrixServer, unicode) -> None
|
# type: (MatrixServer, unicode) -> None
|
||||||
buf = W.buffer_new(
|
buf = W.buffer_new(
|
||||||
|
@ -593,13 +614,10 @@ def matrix_create_room_buffer(server, room_id):
|
||||||
short_name = strip_matrix_server(room_id)
|
short_name = strip_matrix_server(room_id)
|
||||||
W.buffer_set(buf, "short_name", short_name)
|
W.buffer_set(buf, "short_name", short_name)
|
||||||
|
|
||||||
W.nicklist_add_group(
|
W.nicklist_add_group(buf, '', "000|o", "weechat.color.nicklist_group", 1)
|
||||||
buf,
|
W.nicklist_add_group(buf, '', "001|h", "weechat.color.nicklist_group", 1)
|
||||||
'',
|
W.nicklist_add_group(buf, '', "002|v", "weechat.color.nicklist_group", 1)
|
||||||
NICK_GROUP_HERE,
|
W.nicklist_add_group(buf, '', "999|...", "weechat.color.nicklist_group", 1)
|
||||||
"weechat.color.nicklist_group",
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
W.buffer_set(buf, "nicklist", "1")
|
W.buffer_set(buf, "nicklist", "1")
|
||||||
W.buffer_set(buf, "nicklist_display_groups", "0")
|
W.buffer_set(buf, "nicklist_display_groups", "0")
|
||||||
|
@ -630,7 +648,6 @@ def matrix_handle_room_members(server, room_id, event):
|
||||||
# type: (MatrixServer, unicode, Dict[unicode, Any]) -> None
|
# type: (MatrixServer, unicode, Dict[unicode, Any]) -> None
|
||||||
buf = server.buffers[room_id]
|
buf = server.buffers[room_id]
|
||||||
room = server.rooms[room_id]
|
room = server.rooms[room_id]
|
||||||
here = W.nicklist_search_group(buf, '', NICK_GROUP_HERE)
|
|
||||||
|
|
||||||
# TODO print out a informational message
|
# TODO print out a informational message
|
||||||
if event['membership'] == 'join':
|
if event['membership'] == 'join':
|
||||||
|
@ -652,17 +669,12 @@ def matrix_handle_room_members(server, room_id, event):
|
||||||
|
|
||||||
room.users[full_name] = user
|
room.users[full_name] = user
|
||||||
|
|
||||||
nick_pointer = W.nicklist_search_nick(buf, "", user.name)
|
nick_pointer = W.nicklist_search_nick(buf, "", user.display_name)
|
||||||
if not nick_pointer:
|
if not nick_pointer:
|
||||||
W.nicklist_add_nick(
|
add_user_to_nicklist(buf, user)
|
||||||
buf,
|
else:
|
||||||
here,
|
# TODO we can get duplicate display names
|
||||||
user.display_name,
|
pass
|
||||||
user.nick_color,
|
|
||||||
user.prefix,
|
|
||||||
"",
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
elif event['membership'] == 'leave':
|
elif event['membership'] == 'leave':
|
||||||
full_name = event['sender']
|
full_name = event['sender']
|
||||||
|
@ -697,7 +709,7 @@ def matrix_handle_room_text_message(server, room_id, event, old=False):
|
||||||
room = server.rooms[room_id]
|
room = server.rooms[room_id]
|
||||||
msg = event['content']['body']
|
msg = event['content']['body']
|
||||||
|
|
||||||
if user in room.users:
|
if event['sender'] in room.users:
|
||||||
user = room.users[event['sender']]
|
user = room.users[event['sender']]
|
||||||
msg_author = user.display_name
|
msg_author = user.display_name
|
||||||
nick_color_name = user.nick_color
|
nick_color_name = user.nick_color
|
||||||
|
@ -902,6 +914,7 @@ def get_prefix_for_level(level):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
# TODO make this configurable
|
||||||
def get_prefix_color(prefix):
|
def get_prefix_color(prefix):
|
||||||
# type: (unicode) -> unicode
|
# type: (unicode) -> unicode
|
||||||
if prefix == "&":
|
if prefix == "&":
|
||||||
|
@ -913,13 +926,6 @@ def get_prefix_color(prefix):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def update_nicklist_nick(buf, user, nick):
|
|
||||||
# type: (weechat.buffer, MatrixUser, weechat.nick) -> None
|
|
||||||
W.nicklist_nick_set(buf, nick, "prefix", user.prefix)
|
|
||||||
W.nicklist_nick_set(buf, nick, "prefix_color",
|
|
||||||
get_prefix_color(user.prefix))
|
|
||||||
|
|
||||||
|
|
||||||
def matrix_handle_room_power_levels(server, room_id, event):
|
def matrix_handle_room_power_levels(server, room_id, event):
|
||||||
if not event['content']['users']:
|
if not event['content']['users']:
|
||||||
return
|
return
|
||||||
|
@ -935,9 +941,9 @@ def matrix_handle_room_power_levels(server, room_id, event):
|
||||||
user.power_level = level
|
user.power_level = level
|
||||||
user.prefix = get_prefix_for_level(level)
|
user.prefix = get_prefix_for_level(level)
|
||||||
|
|
||||||
W.nicklist_remove_nick(buf, user.name)
|
nick_pointer = W.nicklist_search_nick(buf, "", user.display_name)
|
||||||
nick = W.nicklist_search_nick(buf, "", user.name)
|
W.nicklist_remove_nick(buf, nick_pointer)
|
||||||
update_nicklist_nick(buf, user, nick)
|
add_user_to_nicklist(buf, user)
|
||||||
|
|
||||||
|
|
||||||
def matrix_handle_room_events(server, room_id, room_events):
|
def matrix_handle_room_events(server, room_id, room_events):
|
||||||
|
@ -1009,6 +1015,11 @@ def matrix_handle_room_events(server, room_id, room_events):
|
||||||
elif event["type"] == "m.room.power_levels":
|
elif event["type"] == "m.room.power_levels":
|
||||||
matrix_handle_room_power_levels(server, room_id, event)
|
matrix_handle_room_power_levels(server, room_id, event)
|
||||||
|
|
||||||
|
elif event["type"] in ["m.room.create", "m.room.join_rules",
|
||||||
|
"m.room.history_visibility",
|
||||||
|
"m.room.canonical_alias"]:
|
||||||
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message = ("{prefix}Handling of room event type "
|
message = ("{prefix}Handling of room event type "
|
||||||
"{type} not implemented").format(
|
"{type} not implemented").format(
|
||||||
|
@ -1602,7 +1613,6 @@ def matrix_config_change_cb(data, option):
|
||||||
elif option_name == "max_backlog_sync_events":
|
elif option_name == "max_backlog_sync_events":
|
||||||
GLOBAL_OPTIONS.backlog_limit = W.config_integer(option)
|
GLOBAL_OPTIONS.backlog_limit = W.config_integer(option)
|
||||||
elif option_name == "fetch_backlog_on_pgup":
|
elif option_name == "fetch_backlog_on_pgup":
|
||||||
print("Turning off backlog thing")
|
|
||||||
GLOBAL_OPTIONS.enable_backlog = W.config_boolean(option)
|
GLOBAL_OPTIONS.enable_backlog = W.config_boolean(option)
|
||||||
|
|
||||||
if GLOBAL_OPTIONS.enable_backlog:
|
if GLOBAL_OPTIONS.enable_backlog:
|
||||||
|
|
Loading…
Add table
Reference in a new issue