diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-16 14:58:33 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-03-16 11:58:33 -0700 |
commit | d757645c2490dd4f0de16cc32e05551b1476d0a0 (patch) | |
tree | 5d6e4049aa296b7629a34ca5b02d0aba25dd27dc /model | |
parent | 04c0223c6402b12e67c61474ae310b0a56af6482 (diff) | |
download | chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.tar.gz chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.tar.bz2 chat-d757645c2490dd4f0de16cc32e05551b1476d0a0.zip |
Implement some channel endpoints for APIv4 (#5767)
Diffstat (limited to 'model')
-rw-r--r-- | model/channel_member.go | 20 | ||||
-rw-r--r-- | model/channel_member_test.go | 14 | ||||
-rw-r--r-- | model/client4.go | 32 |
3 files changed, 66 insertions, 0 deletions
diff --git a/model/channel_member.go b/model/channel_member.go index b9a08c769..32ffaf606 100644 --- a/model/channel_member.go +++ b/model/channel_member.go @@ -47,6 +47,15 @@ func (o *ChannelMembers) ToJson() string { } } +func (o *ChannelUnread) ToJson() string { + b, err := json.Marshal(o) + if err != nil { + return "" + } else { + return string(b) + } +} + func ChannelMembersFromJson(data io.Reader) *ChannelMembers { decoder := json.NewDecoder(data) var o ChannelMembers @@ -58,6 +67,17 @@ func ChannelMembersFromJson(data io.Reader) *ChannelMembers { } } +func ChannelUnreadFromJson(data io.Reader) *ChannelUnread { + decoder := json.NewDecoder(data) + var o ChannelUnread + err := decoder.Decode(&o) + if err == nil { + return &o + } else { + return nil + } +} + func (o *ChannelMember) ToJson() string { b, err := json.Marshal(o) if err != nil { diff --git a/model/channel_member_test.go b/model/channel_member_test.go index e43560cee..6fb666300 100644 --- a/model/channel_member_test.go +++ b/model/channel_member_test.go @@ -69,3 +69,17 @@ func TestChannelMemberIsValid(t *testing.T) { t.Fatal(err) } } + +func TestChannelUnreadJson(t *testing.T) { + o := ChannelUnread{ChannelId: NewId(), TeamId: NewId(), MsgCount: 5, MentionCount: 3} + json := o.ToJson() + ro := ChannelUnreadFromJson(strings.NewReader(json)) + + if o.TeamId != ro.TeamId { + t.Fatal("Team Ids do not match") + } + + if o.MentionCount != ro.MentionCount { + t.Fatal("MentionCount do not match") + } +} diff --git a/model/client4.go b/model/client4.go index 2da69b6b4..6e862a1db 100644 --- a/model/client4.go +++ b/model/client4.go @@ -842,6 +842,16 @@ func (c *Client4) GetChannel(channelId, etag string) (*Channel, *Response) { } } +// GetChannelStats returns statistics for a channel. +func (c *Client4) GetChannelStats(channelId string, etag string) (*ChannelStats, *Response) { + if r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/stats", etag); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return ChannelStatsFromJson(r.Body), BuildResponse(r) + } +} + // GetPublicChannelsForTeam returns a channel based on the provided team id string. func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) (*ChannelList, *Response) { query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage) @@ -894,6 +904,17 @@ func (c *Client4) GetChannelMembers(channelId string, page, perPage int, etag st } } +// GetChannelMembersByIds gets the channel members in a channel for a list of user ids. +func (c *Client4) GetChannelMembersByIds(channelId string, userIds []string) (*ChannelMembers, *Response) { + if r, err := c.DoApiPost(c.GetChannelMembersRoute(channelId)+"/ids", ArrayToJson(userIds)); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return ChannelMembersFromJson(r.Body), BuildResponse(r) + + } +} + // GetChannelMember gets a channel member. func (c *Client4) GetChannelMember(channelId, userId, etag string) (*ChannelMember, *Response) { if r, err := c.DoApiGet(c.GetChannelMemberRoute(channelId, userId), etag); err != nil { @@ -925,6 +946,17 @@ func (c *Client4) ViewChannel(userId string, view *ChannelView) (bool, *Response } } +// GetChannelUnread will return a ChannelUnread object that contains the number of +// unread messages and mentions for a user. +func (c *Client4) GetChannelUnread(channelId, userId string) (*ChannelUnread, *Response) { + if r, err := c.DoApiGet(c.GetUserRoute(userId)+c.GetChannelRoute(channelId)+"/unread", ""); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return ChannelUnreadFromJson(r.Body), BuildResponse(r) + } +} + // UpdateChannelRoles will update the roles on a channel for a user. func (c *Client4) UpdateChannelRoles(channelId, userId, roles string) (bool, *Response) { requestBody := map[string]string{"roles": roles} |