Implement some channel endpoints for APIv4 (#5767)

Этот коммит содержится в:
Joram Wilander
2017-03-16 14:58:33 -04:00
коммит произвёл Corey Hulen
родитель 04c0223c64
Коммит d757645c24
11 изменённых файлов: 399 добавлений и 1 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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")
}
}

Просмотреть файл

@@ -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}