From ba6e370ca71abacaa30234cb164427d27c86df13 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 21 Dec 2016 16:35:01 -0500 Subject: PLT-5012 Combine updateLastViewedAt, setLastViewedAt and setActiveChannel into a single API (#4840) * Combine updateLastViewedAt, setLastViewedAt and setActiveChannel into a single API * Remove preference DB writes --- model/client.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'model/client.go') diff --git a/model/client.go b/model/client.go index e5f5fcea4..9ff34f5bf 100644 --- a/model/client.go +++ b/model/client.go @@ -48,6 +48,13 @@ type Result struct { Data interface{} } +type ResponseMetadata struct { + StatusCode int + Error *AppError + RequestId string + Etag string +} + type Client struct { Url string // The location of the server like "http://localhost:8065" ApiUrl string // The api location of the server like "http://localhost:8065/api/v3" @@ -1329,6 +1336,7 @@ func (c *Client) RemoveChannelMember(id, user_id string) (*Result, *AppError) { // 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. +// SCHEDULED FOR DEPRECATION IN 3.8 - use ViewChannel instead func (c *Client) UpdateLastViewedAt(channelId string, active bool) (*Result, *AppError) { data := make(map[string]interface{}) data["active"] = active @@ -1341,6 +1349,24 @@ func (c *Client) UpdateLastViewedAt(channelId string, active bool) (*Result, *Ap } } +// ViewChannel performs all the actions related to viewing a channel. This includes marking +// the channel and the previous one as read, marking the channel as being actively viewed. +// ChannelId is required but may be blank to indicate no channel is being viewed. +// PrevChannelId is optional, populate to indicate a channel switch occurred. Optionally +// provide a non-zero Time, in Unix milliseconds, to manually set the viewing time. +func (c *Client) ViewChannel(params ChannelView) (bool, *ResponseMetadata) { + if r, err := c.DoApiPost(c.GetTeamRoute()+"/channels/view", params.ToJson()); err != nil { + return false, &ResponseMetadata{StatusCode: r.StatusCode, Error: err} + } else { + return c.CheckStatusOK(r), + &ResponseMetadata{ + StatusCode: r.StatusCode, + RequestId: r.Header.Get(HEADER_REQUEST_ID), + Etag: r.Header.Get(HEADER_ETAG_SERVER), + } + } +} + func (c *Client) GetChannelStats(id string, etag string) (*Result, *AppError) { if r, err := c.DoApiGet(c.GetChannelRoute(id)+"/stats", "", etag); err != nil { return nil, err @@ -1718,6 +1744,7 @@ func (c *Client) GetStatusesByIds(userIds []string) (*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. +// SCHEDULED FOR DEPRECATION IN 3.8 - use ViewChannel instead func (c *Client) SetActiveChannel(channelId string) (*Result, *AppError) { data := map[string]string{} data["channel_id"] = channelId -- cgit v1.2.3-1-g7c22