From 5e38c949f2adbef6507cd3fb12ddb5543fed7baf Mon Sep 17 00:00:00 2001 From: AlexanderShK <113863493+AlexanderShK@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:13:19 +0300 Subject: [PATCH] Update handlers.go Add ability to use FullName, FirstName, LastName, NickName or UserName(if neither is set) as nick for Mattermost --- bridge/mattermost/handlers.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/bridge/mattermost/handlers.go b/bridge/mattermost/handlers.go index 8c4ea365..06c86a06 100644 --- a/bridge/mattermost/handlers.go +++ b/bridge/mattermost/handlers.go @@ -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) != "" { + 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 }