Allow specifying preferred order of displayname source. Fixes #20
This commit is contained in:
@@ -21,6 +21,23 @@ bridge:
|
|||||||
username_template: "telegram_${ID}"
|
username_template: "telegram_${ID}"
|
||||||
# ${DISPLAYNAME} is replaced with the display name of the Telegram user.
|
# ${DISPLAYNAME} is replaced with the display name of the Telegram user.
|
||||||
displayname_template: "${DISPLAYNAME} (Telegram)"
|
displayname_template: "${DISPLAYNAME} (Telegram)"
|
||||||
|
# Set the preferred order of user identifiers which to use in the Matrix puppet display name.
|
||||||
|
# In the (hopefully unlikely) scenario that none of the given keys are found, the numeric user ID is used.
|
||||||
|
#
|
||||||
|
# If the bridge is working properly, a phone number or an username should always be known, but the other one can
|
||||||
|
# very well be empty.
|
||||||
|
#
|
||||||
|
# Valid keys:
|
||||||
|
# fullName (First and/or last name)
|
||||||
|
# fullNameReversed (Last and/or first name)
|
||||||
|
# firstName
|
||||||
|
# lastName
|
||||||
|
# username
|
||||||
|
# phoneNumber
|
||||||
|
displayname_preference:
|
||||||
|
- fullName
|
||||||
|
- username
|
||||||
|
- phoneNumber
|
||||||
# ${NAME} is replaced with the name part of the public channel/group invite link ( https://t.me/${NAME} )
|
# ${NAME} is replaced with the name part of the public channel/group invite link ( https://t.me/${NAME} )
|
||||||
alias_template: "telegram_${NAME}"
|
alias_template: "telegram_${NAME}"
|
||||||
# Username of the bot. The registration must be regenerated to change this.
|
# Username of the bot. The registration must be regenerated to change this.
|
||||||
|
|||||||
+29
-17
@@ -82,17 +82,19 @@ class TelegramUser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let changed = false
|
let changed = false
|
||||||
if (user.first_name && this.firstName !== user.first_name) {
|
if (user.first_name || user.last_name || user.username) {
|
||||||
this.firstName = user.first_name
|
if (this.firstName !== user.first_name) {
|
||||||
changed = true
|
this.firstName = user.first_name
|
||||||
}
|
changed = true
|
||||||
if (user.last_name && this.lastName !== user.last_name) {
|
}
|
||||||
this.lastName = user.last_name
|
if (this.lastName !== user.last_name) {
|
||||||
changed = true
|
this.lastName = user.last_name
|
||||||
}
|
changed = true
|
||||||
if (user.username && this.username !== user.username) {
|
}
|
||||||
this.username = user.username
|
if (user.username && this.username !== user.username) {
|
||||||
changed = true
|
this.username = user.username
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (user.access_hash && telegramPOV && this.accessHashes.get(telegramPOV.userID) !== user.access_hash) {
|
if (user.access_hash && telegramPOV && this.accessHashes.get(telegramPOV.userID) !== user.access_hash) {
|
||||||
this.accessHashes.set(telegramPOV.userID, user.access_hash)
|
this.accessHashes.set(telegramPOV.userID, user.access_hash)
|
||||||
@@ -129,13 +131,23 @@ class TelegramUser {
|
|||||||
return [this.firstName, this.lastName].filter(s => !!s).join(" ")
|
return [this.firstName, this.lastName].filter(s => !!s).join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastAndFirstName() {
|
||||||
|
return [this.lastName, this.firstName].filter(s => !!s).join(" ")
|
||||||
|
}
|
||||||
|
|
||||||
getDisplayName() {
|
getDisplayName() {
|
||||||
if (this.firstName || this.lastName) {
|
for (const preference of this.app.config.bridge.displayname_preference) {
|
||||||
return this.getFirstAndLastName()
|
if (preference === "fullName") {
|
||||||
} else if (this.username) {
|
if (this.firstName || this.lastName) {
|
||||||
return this.username
|
return this.getFirstAndLastName()
|
||||||
} else if (this.phoneNumber) {
|
}
|
||||||
return this.phoneNumber
|
} else if (preference === "fullNameReversed") {
|
||||||
|
if (this.firstName || this.lastName) {
|
||||||
|
return this.getLastAndFirstName()
|
||||||
|
}
|
||||||
|
} else if (this[preference]) {
|
||||||
|
return this[preference]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this.id
|
return this.id
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user