matrix: add support for global display names

This commit is contained in:
James Lu
2020-06-22 05:07:46 +00:00
parent 2f0f2ee40d
commit 221a21fd3b
2 changed files with 18 additions and 2 deletions

View File

@@ -180,9 +180,21 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
return
}
// Use display name (/nick) if available
// XXX: no support for per-room display names or disambiguation yet
hasDisplayName := false
displayName := ev.Sender[1:]
if b.GetBool("UseDisplayName") {
if resp, err := b.mc.GetDisplayName(ev.Sender); err == nil {
displayName = resp.DisplayName
b.Log.Debugf("Got display name %s for user %s", displayName, ev.Sender)
hasDisplayName = true
}
}
// Create our message
rmsg := config.Message{
Username: ev.Sender[1:],
Username: displayName,
Channel: channel,
Account: b.Account,
UserID: ev.Sender,
@@ -198,7 +210,7 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
}
// Remove homeserver suffix if configured
if b.GetBool("NoHomeServerSuffix") {
if b.GetBool("NoHomeServerSuffix") && !hasDisplayName {
re := regexp.MustCompile("(.*?):.*")
rmsg.Username = re.ReplaceAllString(rmsg.Username, `$1`)
}

View File

@@ -1213,6 +1213,10 @@ Password="yourpass"
#OPTIONAL (default false)
NoHomeServerSuffix=false
#Whether to prefer display names when available. Currently this does not
#support disambiguation if display names collide. (default false)
#UseDisplayName=false
#Whether to disable sending of HTML content to matrix
#See https://github.com/42wim/matterbridge/issues/1022
#OPTIONAL (default false)