Allow nil network in Get{Nick,Username,Realname}

Will simplify callers.
This commit is contained in:
Simon Ser 2022-03-30 14:15:12 +02:00
parent 3d8022d030
commit f6655fbe11

6
db.go
View File

@ -116,21 +116,21 @@ func (net *Network) URL() (*url.URL, error) {
} }
func GetNick(user *User, net *Network) string { func GetNick(user *User, net *Network) string {
if net.Nick != "" { if net != nil && net.Nick != "" {
return net.Nick return net.Nick
} }
return user.Username return user.Username
} }
func GetUsername(user *User, net *Network) string { func GetUsername(user *User, net *Network) string {
if net.Username != "" { if net != nil && net.Username != "" {
return net.Username return net.Username
} }
return GetNick(user, net) return GetNick(user, net)
} }
func GetRealname(user *User, net *Network) string { func GetRealname(user *User, net *Network) string {
if net.Realname != "" { if net != nil && net.Realname != "" {
return net.Realname return net.Realname
} }
if user.Realname != "" { if user.Realname != "" {