summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-10-13 12:35:57 +0200
committerGitHub <noreply@github.com>2018-10-13 12:35:57 +0200
commit908ed5555f8a3d37cd057035b2792d66c8b7838a (patch)
tree7ad4248a72a7c3b6e6c3981840c5951c6108fe1d /app
parente87965f39d2ce6dbd0e7883c387956413c663f6a (diff)
downloadchat-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 'app')
-rw-r--r--app/channel.go18
-rw-r--r--app/channel_test.go38
2 files changed, 56 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go
index 93037cf05..dee856b94 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -1153,6 +1153,24 @@ func (a *App) GetChannelMembersPage(channelId string, page, perPage int) (*model
return result.Data.(*model.ChannelMembers), nil
}
+func (a *App) GetChannelMembersTimezones(channelId string) ([]string, *model.AppError) {
+ result := <-a.Srv.Store.Channel().GetChannelMembersTimezones(channelId)
+ if result.Err != nil {
+ return nil, result.Err
+ }
+ membersTimezones := result.Data.([]map[string]string)
+
+ var timezones []string
+ for _, membersTimezone := range membersTimezones {
+ if membersTimezone["automaticTimezone"] == "" && membersTimezone["manualTimezone"] == "" {
+ continue
+ }
+ timezones = append(timezones, model.GetPreferredTimezone(membersTimezone))
+ }
+
+ return model.RemoveDuplicateStrings(timezones), nil
+}
+
func (a *App) GetChannelMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError) {
result := <-a.Srv.Store.Channel().GetMembersByIds(channelId, userIds)
if result.Err != nil {
diff --git a/app/channel_test.go b/app/channel_test.go
index 4b09bbb78..b6f460741 100644
--- a/app/channel_test.go
+++ b/app/channel_test.go
@@ -4,6 +4,7 @@
package app
import (
+ "strings"
"testing"
"github.com/mattermost/mattermost-server/model"
@@ -709,3 +710,40 @@ func TestRenameChannel(t *testing.T) {
})
}
}
+
+func TestGetChannelMembersTimezones(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer th.TearDown()
+
+ userRequestorId := ""
+ postRootId := ""
+ if _, err := th.App.AddChannelMember(th.BasicUser2.Id, th.BasicChannel, userRequestorId, postRootId, false); err != nil {
+ t.Fatal("Failed to add user to channel. Error: " + err.Message)
+ }
+
+ user := th.BasicUser
+ user.Timezone["useAutomaticTimezone"] = "false"
+ user.Timezone["manualTimezone"] = "XOXO/BLABLA"
+ th.App.UpdateUser(user, false)
+
+ user2 := th.BasicUser2
+ user2.Timezone["automaticTimezone"] = "NoWhere/Island"
+ th.App.UpdateUser(user2, false)
+
+ user3 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
+ ruser, _ := th.App.CreateUser(&user3)
+ th.App.AddUserToChannel(ruser, th.BasicChannel)
+
+ ruser.Timezone["automaticTimezone"] = "NoWhere/Island"
+ th.App.UpdateUser(ruser, false)
+
+ user4 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
+ ruser, _ = th.App.CreateUser(&user4)
+ th.App.AddUserToChannel(ruser, th.BasicChannel)
+
+ timezones, err := th.App.GetChannelMembersTimezones(th.BasicChannel.Id)
+ if err != nil {
+ t.Fatal("Failed to get the timezones for a channel. Error: " + err.Error())
+ }
+ assert.Equal(t, 2, len(timezones))
+}