diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2018-10-13 12:35:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-13 12:35:57 +0200 |
commit | 908ed5555f8a3d37cd057035b2792d66c8b7838a (patch) | |
tree | 7ad4248a72a7c3b6e6c3981840c5951c6108fe1d /model | |
parent | e87965f39d2ce6dbd0e7883c387956413c663f6a (diff) | |
download | chat-908ed5555f8a3d37cd057035b2792d66c8b7838a.tar.gz chat-908ed5555f8a3d37cd057035b2792d66c8b7838a.tar.bz2 chat-908ed5555f8a3d37cd057035b2792d66c8b7838a.zip |
[APIv4] add getChannelMembersTimezone (#9286)
* add getChannelMembersTimezone
* update per feedback review
* add delimeter to error
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 11 | ||||
-rw-r--r-- | model/user.go | 6 | ||||
-rw-r--r-- | model/utils.go | 23 |
3 files changed, 35 insertions, 5 deletions
diff --git a/model/client4.go b/model/client4.go index 903687ece..6a613b6b3 100644 --- a/model/client4.go +++ b/model/client4.go @@ -1746,6 +1746,17 @@ func (c *Client4) GetChannelStats(channelId string, etag string) (*ChannelStats, } } +// GetChannelMembersTimezones gets a list of timezones for a channel. +func (c *Client4) GetChannelMembersTimezones(channelId string) ([]string, *Response) { + r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/timezones", "") + if err != nil { + return nil, BuildErrorResponse(r, err) + } + + defer closeBody(r) + return ArrayFromJson(r.Body), BuildResponse(r) +} + // GetPinnedPosts gets a list of pinned posts. func (c *Client4) GetPinnedPosts(channelId string, etag string) (*PostList, *Response) { if r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/pinned", etag); err != nil { diff --git a/model/user.go b/model/user.go index 781bcae66..06ad9294f 100644 --- a/model/user.go +++ b/model/user.go @@ -499,11 +499,7 @@ func (u *User) IsSAMLUser() bool { } func (u *User) GetPreferredTimezone() string { - if u.Timezone["useAutomaticTimezone"] == "true" { - return u.Timezone["automaticTimezone"] - } - - return u.Timezone["manualTimezone"] + return GetPreferredTimezone(u.Timezone) } // UserFromJson will decode the input and return a User diff --git a/model/utils.go b/model/utils.go index 172b78242..849e529c1 100644 --- a/model/utils.go +++ b/model/utils.go @@ -564,3 +564,26 @@ func IsDomainName(s string) bool { return ok } + +func RemoveDuplicateStrings(in []string) []string { + out := []string{} + seen := make(map[string]bool, len(in)) + + for _, item := range in { + if !seen[item] { + out = append(out, item) + + seen[item] = true + } + } + + return out +} + +func GetPreferredTimezone(timezone StringMap) string { + if timezone["useAutomaticTimezone"] == "true" { + return timezone["automaticTimezone"] + } + + return timezone["manualTimezone"] +} |