Fix mentioning users without display names

This commit is contained in:
miruka 2020-08-23 09:41:41 -04:00
parent e79094c18c
commit fbf6e48b5b
3 changed files with 10 additions and 10 deletions

View File

@ -312,8 +312,8 @@ class HTMLProcessor:
}}
username_link_regexes = [re.compile(r) for r in [
rf"(?<!\w)(?P<body>{re.escape(name)})(?!\w)(?P<host>)"
for name in (display_name_mentions or {})
rf"(?<!\w)(?P<body>{re.escape(name or user_id)})(?!\w)(?P<host>)"
for user_id, name in (display_name_mentions or {}).items()
]]
return {
@ -495,8 +495,8 @@ class HTMLProcessor:
el.attrib["href"] = f"https://matrix.to/#/{el.attrib['href']}"
return el
for name, user_id in (display_name_mentions or {}).items():
if unquote(el.attrib["href"]) == name:
for user_id, name in (display_name_mentions or {}).items():
if unquote(el.attrib["href"]) == (name or user_id):
el.attrib["href"] = f"https://matrix.to/#/{user_id}"
return el

View File

@ -512,7 +512,7 @@ class MatrixClient(nio.AsyncClient):
self,
room_id: str,
text: str,
display_name_mentions: Optional[Dict[str, str]] = None, # {name: id}
display_name_mentions: Optional[Dict[str, str]] = None, # {id: name}
reply_to_event_id: Optional[str] = None,
) -> None:
"""Send a markdown `m.text` or `m.notice` (with `/me`) message ."""

View File

@ -16,7 +16,7 @@ HListView {
property int replacementStart: -1
property int replacementEnd: -1
property bool autoOpenCompleted: false
property var usersCompleted: ({}) // {displayName: userId}
property var usersCompleted: ({}) // {userId: displayName}
readonly property bool autoOpen: {
if (autoOpenCompleted) return true
@ -70,7 +70,7 @@ HListView {
function accept() {
if (currentIndex !== -1) {
const member = model.get(currentIndex)
usersCompleted[member.display_name] = member.id
usersCompleted[member.id] = member.display_name
usersCompletedChanged()
}
@ -165,9 +165,9 @@ HListView {
function onTextChanged() {
let changed = false
for (const displayName of Object.keys(root.usersCompleted)) {
if (! root.textArea.text.includes(displayName)) {
delete root.usersCompleted[displayName]
for (const [id, name] of Object.entries(root.usersCompleted)) {
if (! root.textArea.text.includes(name)) {
delete root.usersCompleted[id]
changed = true
}
}