From 25b9b7d26b8738343d269c83031ba5a5408d0d58 Mon Sep 17 00:00:00 2001 From: Andrei Stanciu Date: Tue, 28 Feb 2017 17:47:30 +0200 Subject: ApiV4: GET /users/{user_id}/teams/unread (#5539) --- model/client4.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'model') diff --git a/model/client4.go b/model/client4.go index 0ccb94009..8d2423ad9 100644 --- a/model/client4.go +++ b/model/client4.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "mime/multipart" "net/http" + "net/url" "strconv" "strings" ) @@ -483,6 +484,23 @@ func (c *Client4) RevokeSession(userId, sessionId string) (bool, *Response) { } } +// getTeamsUnreadForUser will return an array with TeamUnread objects that contain the amount of +// unread messages and mentions the current user has for the teams it belongs to. +// An optional team ID can be set to exclude that team from the results. Must be authenticated. +func (c *Client4) GetTeamsUnreadForUser(userId, teamIdToExclude string) ([]*TeamUnread, *Response) { + optional := "" + if teamIdToExclude != "" { + optional += fmt.Sprintf("?exclude_team=%s", url.QueryEscape(teamIdToExclude)) + } + + if r, err := c.DoApiGet(c.GetUserRoute(userId)+"/teams/unread"+optional, ""); err != nil { + return nil, &Response{StatusCode: r.StatusCode, Error: err} + } else { + defer closeBody(r) + return TeamsUnreadFromJson(r.Body), BuildResponse(r) + } +} + // GetAudits returns a list of audit based on the provided user id string. func (c *Client4) GetAudits(userId string, page int, perPage int, etag string) (Audits, *Response) { query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage) -- cgit v1.2.3-1-g7c22