Merge branch 'master' into mark-as-unread
Этот коммит содержится в:
@@ -2898,7 +2898,7 @@ func (c *Client4) GetPing() (string, *Response) {
|
||||
}
|
||||
|
||||
// GetPingWithServerStatus will return ok if several basic server health checks
|
||||
// all psss successfully.
|
||||
// all pass successfully.
|
||||
func (c *Client4) GetPingWithServerStatus() (string, *Response) {
|
||||
r, err := c.DoApiGet(c.GetSystemRoute()+"/ping?get_server_status=true", "")
|
||||
if r != nil && r.StatusCode == 500 {
|
||||
|
||||
@@ -7,6 +7,7 @@ const (
|
||||
POST_EMBED_IMAGE PostEmbedType = "image"
|
||||
POST_EMBED_MESSAGE_ATTACHMENT PostEmbedType = "message_attachment"
|
||||
POST_EMBED_OPENGRAPH PostEmbedType = "opengraph"
|
||||
POST_EMBED_LINK PostEmbedType = "link"
|
||||
)
|
||||
|
||||
type PostEmbedType string
|
||||
|
||||
@@ -539,8 +539,8 @@ func (u *User) GetFullName() string {
|
||||
}
|
||||
}
|
||||
|
||||
func (u *User) GetDisplayName(nameFormat string) string {
|
||||
displayName := u.Username
|
||||
func (u *User) getDisplayName(baseName, nameFormat string) string {
|
||||
displayName := baseName
|
||||
|
||||
if nameFormat == SHOW_NICKNAME_FULLNAME {
|
||||
if len(u.Nickname) > 0 {
|
||||
@@ -557,6 +557,18 @@ func (u *User) GetDisplayName(nameFormat string) string {
|
||||
return displayName
|
||||
}
|
||||
|
||||
func (u *User) GetDisplayName(nameFormat string) string {
|
||||
displayName := u.Username
|
||||
|
||||
return u.getDisplayName(displayName, nameFormat)
|
||||
}
|
||||
|
||||
func (u *User) GetDisplayNameWithPrefix(nameFormat, prefix string) string {
|
||||
displayName := prefix + u.Username
|
||||
|
||||
return u.getDisplayName(displayName, nameFormat)
|
||||
}
|
||||
|
||||
func (u *User) GetRoles() []string {
|
||||
return strings.Fields(u.Roles)
|
||||
}
|
||||
|
||||
@@ -252,6 +252,42 @@ func TestUserGetDisplayName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserGetDisplayNameWithPrefix(t *testing.T) {
|
||||
user := User{Username: "username"}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_FULLNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_USERNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
user.FirstName = "first"
|
||||
user.LastName = "last"
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_FULLNAME, "@"); displayName != "first last" {
|
||||
t.Fatal("Display name should be full name")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"); displayName != "first last" {
|
||||
t.Fatal("Display name should be full name since there is no nickname")
|
||||
}
|
||||
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_USERNAME, "@"); displayName != "@username" {
|
||||
t.Fatal("Display name should be username")
|
||||
}
|
||||
|
||||
user.Nickname = "nickname"
|
||||
if displayName := user.GetDisplayNameWithPrefix(SHOW_NICKNAME_FULLNAME, "@"); displayName != "nickname" {
|
||||
t.Fatal("Display name should be nickname")
|
||||
}
|
||||
}
|
||||
|
||||
var usernames = []struct {
|
||||
value string
|
||||
expected bool
|
||||
|
||||
Ссылка в новой задаче
Block a user