Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use FullName, FirstName, LastName, NickName or UserName(if neither is set) as nick for Mattermost #2108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bridge/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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
Expand Down
30 changes: 24 additions & 6 deletions bridge/mattermost/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,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) != "" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid deeply nested control flow statements.

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
}
Expand Down
8 changes: 6 additions & 2 deletions matterbridge.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions vendor/github.com/matterbridge/matterclient/users.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.