From f32eb525f3fa0828a23f589d765c267e3b2aea86 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 2 Sep 2016 12:50:15 -0400 Subject: Do not send push notifications for channels being actively viewed (#3931) --- model/client.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'model/client.go') diff --git a/model/client.go b/model/client.go index f43e5ad79..2c3fb5aca 100644 --- a/model/client.go +++ b/model/client.go @@ -1140,8 +1140,13 @@ func (c *Client) RemoveChannelMember(id, user_id string) (*Result, *AppError) { } } -func (c *Client) UpdateLastViewedAt(channelId string) (*Result, *AppError) { - if r, err := c.DoApiPost(c.GetChannelRoute(channelId)+"/update_last_viewed_at", ""); err != nil { +// UpdateLastViewedAt will mark a channel as read. +// The channelId indicates the channel to mark as read. If active is true, push notifications +// will be cleared if there are unread messages. The default for active is true. +func (c *Client) UpdateLastViewedAt(channelId string, active bool) (*Result, *AppError) { + data := make(map[string]interface{}) + data["active"] = active + if r, err := c.DoApiPost(c.GetChannelRoute(channelId)+"/update_last_viewed_at", StringInterfaceToJson(data)); err != nil { return nil, err } else { defer closeBody(r) @@ -1463,6 +1468,21 @@ func (c *Client) GetStatuses() (*Result, *AppError) { } } +// SetActiveChannel sets the the channel id the user is currently viewing. +// The channelId key is required but the value can be blank. Returns standard +// response. +func (c *Client) SetActiveChannel(channelId string) (*Result, *AppError) { + data := map[string]string{} + data["channel_id"] = channelId + if r, err := c.DoApiPost("/users/status/set_active_channel", MapToJson(data)); err != nil { + return nil, err + } else { + defer closeBody(r) + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil + } +} + func (c *Client) GetMyTeam(etag string) (*Result, *AppError) { if r, err := c.DoApiGet(c.GetTeamRoute()+"/me", "", etag); err != nil { return nil, err -- cgit v1.2.3-1-g7c22