diff --git a/bridge/config/config.go b/bridge/config/config.go index 75792ed0..9320c441 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -170,7 +170,9 @@ type Protocol struct { UseSASL bool // IRC UseTLS bool // IRC UseDiscriminator bool // discord - UseFirstName bool // telegram + UseFullName bool // mattermost + UseFirstName bool // telegram, mattermost + UseLastName bool // mattermost UseUserName bool // discord, matrix, mattermost UseInsecureURL bool // telegram UserName string // IRC diff --git a/bridge/mattermost/handlers.go b/bridge/mattermost/handlers.go index b7b53386..4fac8401 100644 --- a/bridge/mattermost/handlers.go +++ b/bridge/mattermost/handlers.go @@ -144,12 +144,30 @@ func (b *Bmattermost) handleMatterClient(messages chan *config.Message) { } } - // Use nickname instead of username if defined - if !b.GetBool("useusername") { - if nick := b.mc.GetNickName(rmsg.UserID); nick != "" { - rmsg.Username = nick - } - } + // Choose what to use as user nick Nickname/FullName/FirstName/LastName (or Username if neither is set) + if b.GetBool("UseNickName") { + if b.mc.GetNickName(rmsg.UserID) != "" { + rmsg.Username = b.mc.GetNickName(rmsg.UserID) + } + } else if b.GetBool("UseFirstName") { + if b.mc.GetFirstName(rmsg.UserID) != "" { + rmsg.Username = b.mc.GetFirstName(rmsg.UserID) + } + } else if b.GetBool("UseLastName") { + if b.mc.GetLastName(rmsg.UserID) != "" { + rmsg.Username = b.mc.GetLastName(rmsg.UserID) + } + } else if b.GetBool("UseFullName") { + if b.mc.GetFirstName(rmsg.UserID) != "" && b.mc.GetLastName(rmsg.UserID) != "" { + rmsg.Username = b.mc.GetFirstName(rmsg.UserID) + " " + b.mc.GetLastName(rmsg.UserID) + } else if b.mc.GetFirstName(rmsg.UserID) != "" { + rmsg.Username = b.mc.GetFirstName(rmsg.UserID) + } else if b.mc.GetLastName(rmsg.UserID) != "" { + rmsg.Username = b.mc.GetLastName(rmsg.UserID) + } else { + rmsg.Username = "" + } + } messages <- rmsg } diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 0665a599..305435d7 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -409,9 +409,13 @@ SkipTLSVerify=true ## RELOADABLE SETTINGS ## Settings below can be reloaded by editing the file -# UseUserName shows the username instead of the server nickname +# Choose what use as user nick NickName/FullName/FirstName/LastName/UserName # OPTIONAL (default false) -UseUserName=false +UseNickName=false +UseFullName=false +UseFirstName=false +UseLastName=false +#if neither is set as true will use username #how to format the list of IRC nicks when displayed in mattermost. #Possible options are "table" and "plain" diff --git a/vendor/github.com/matterbridge/matterclient/users.go b/vendor/github.com/matterbridge/matterclient/users.go index c8fae852..818f90c4 100644 --- a/vendor/github.com/matterbridge/matterclient/users.go +++ b/vendor/github.com/matterbridge/matterclient/users.go @@ -14,6 +14,22 @@ func (m *Client) GetNickName(userID string) string { return "" } +func (m *Client) GetFirstName(userID string) string { + if user := m.GetUser(userID); user != nil { + return user.FirstName + } + + return "" +} + +func (m *Client) GetLastName(userID string) string { + if user := m.GetUser(userID); user != nil { + return user.LastName + } + + return "" +} + func (m *Client) GetStatus(userID string) string { res, _, err := m.Client.GetUserStatus(context.TODO(), userID, "") if err != nil {