summaryrefslogtreecommitdiffstats
path: root/api4/team.go
diff options
context:
space:
mode:
authorAndrei Stanciu <andrei.stanciu@geminisols.ro>2017-02-28 17:47:30 +0200
committerGeorge Goldberg <george@gberg.me>2017-02-28 15:47:30 +0000
commit25b9b7d26b8738343d269c83031ba5a5408d0d58 (patch)
tree7f70c50bfdf9fe588268426005bb6305f6a074a7 /api4/team.go
parentb0410615b8206ea2706312a9f413785d86134f6d (diff)
downloadchat-25b9b7d26b8738343d269c83031ba5a5408d0d58.tar.gz
chat-25b9b7d26b8738343d269c83031ba5a5408d0d58.tar.bz2
chat-25b9b7d26b8738343d269c83031ba5a5408d0d58.zip
ApiV4: GET /users/{user_id}/teams/unread (#5539)
Diffstat (limited to 'api4/team.go')
-rw-r--r--api4/team.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/api4/team.go b/api4/team.go
index 9071458cb..c88c553fb 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -18,6 +18,7 @@ func InitTeam() {
BaseRoutes.Teams.Handle("", ApiSessionRequired(createTeam)).Methods("POST")
BaseRoutes.Teams.Handle("", ApiSessionRequired(getAllTeams)).Methods("GET")
BaseRoutes.TeamsForUser.Handle("", ApiSessionRequired(getTeamsForUser)).Methods("GET")
+ BaseRoutes.TeamsForUser.Handle("/unread", ApiSessionRequired(getTeamsUnreadForUser)).Methods("GET")
BaseRoutes.Team.Handle("", ApiSessionRequired(getTeam)).Methods("GET")
BaseRoutes.Team.Handle("/stats", ApiSessionRequired(getTeamStats)).Methods("GET")
@@ -104,6 +105,29 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
+ c.RequireUserId()
+ if c.Err != nil {
+ return
+ }
+
+ if c.Session.UserId != c.Params.UserId && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
+ return
+ }
+
+ // optional team id to be excluded from the result
+ teamId := r.URL.Query().Get("exclude_team")
+
+ unreadTeamsList, err := app.GetTeamsUnreadForUser(teamId, c.Params.UserId)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ w.Write([]byte(model.TeamsUnreadToJson(unreadTeamsList)))
+}
+
func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId().RequireUserId()
if c.Err != nil {