Merge b502420de89c9f1c5825f2a6e01a0a323ae5366c into c4157a4d5b49fce79c80a30730dc7c404bacd663

This commit is contained in:
AlexanderShK 2024-08-30 12:36:40 +08:00 committed by GitHub
commit 4ede82486c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 9 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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"

View File

@ -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 {