Fix mentioning users without display names
This commit is contained in:
parent
e79094c18c
commit
fbf6e48b5b
|
@ -312,8 +312,8 @@ class HTMLProcessor:
|
||||||
}}
|
}}
|
||||||
|
|
||||||
username_link_regexes = [re.compile(r) for r in [
|
username_link_regexes = [re.compile(r) for r in [
|
||||||
rf"(?<!\w)(?P<body>{re.escape(name)})(?!\w)(?P<host>)"
|
rf"(?<!\w)(?P<body>{re.escape(name or user_id)})(?!\w)(?P<host>)"
|
||||||
for name in (display_name_mentions or {})
|
for user_id, name in (display_name_mentions or {}).items()
|
||||||
]]
|
]]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -495,8 +495,8 @@ class HTMLProcessor:
|
||||||
el.attrib["href"] = f"https://matrix.to/#/{el.attrib['href']}"
|
el.attrib["href"] = f"https://matrix.to/#/{el.attrib['href']}"
|
||||||
return el
|
return el
|
||||||
|
|
||||||
for name, user_id in (display_name_mentions or {}).items():
|
for user_id, name in (display_name_mentions or {}).items():
|
||||||
if unquote(el.attrib["href"]) == name:
|
if unquote(el.attrib["href"]) == (name or user_id):
|
||||||
el.attrib["href"] = f"https://matrix.to/#/{user_id}"
|
el.attrib["href"] = f"https://matrix.to/#/{user_id}"
|
||||||
return el
|
return el
|
||||||
|
|
||||||
|
|
|
@ -512,7 +512,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
self,
|
self,
|
||||||
room_id: str,
|
room_id: str,
|
||||||
text: 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,
|
reply_to_event_id: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Send a markdown `m.text` or `m.notice` (with `/me`) message ."""
|
"""Send a markdown `m.text` or `m.notice` (with `/me`) message ."""
|
||||||
|
|
|
@ -16,7 +16,7 @@ HListView {
|
||||||
property int replacementStart: -1
|
property int replacementStart: -1
|
||||||
property int replacementEnd: -1
|
property int replacementEnd: -1
|
||||||
property bool autoOpenCompleted: false
|
property bool autoOpenCompleted: false
|
||||||
property var usersCompleted: ({}) // {displayName: userId}
|
property var usersCompleted: ({}) // {userId: displayName}
|
||||||
|
|
||||||
readonly property bool autoOpen: {
|
readonly property bool autoOpen: {
|
||||||
if (autoOpenCompleted) return true
|
if (autoOpenCompleted) return true
|
||||||
|
@ -70,7 +70,7 @@ HListView {
|
||||||
function accept() {
|
function accept() {
|
||||||
if (currentIndex !== -1) {
|
if (currentIndex !== -1) {
|
||||||
const member = model.get(currentIndex)
|
const member = model.get(currentIndex)
|
||||||
usersCompleted[member.display_name] = member.id
|
usersCompleted[member.id] = member.display_name
|
||||||
usersCompletedChanged()
|
usersCompletedChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,9 +165,9 @@ HListView {
|
||||||
function onTextChanged() {
|
function onTextChanged() {
|
||||||
let changed = false
|
let changed = false
|
||||||
|
|
||||||
for (const displayName of Object.keys(root.usersCompleted)) {
|
for (const [id, name] of Object.entries(root.usersCompleted)) {
|
||||||
if (! root.textArea.text.includes(displayName)) {
|
if (! root.textArea.text.includes(name)) {
|
||||||
delete root.usersCompleted[displayName]
|
delete root.usersCompleted[id]
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user