summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-12-21 16:35:01 -0500
committerChristopher Speller <crspeller@gmail.com>2016-12-21 16:35:01 -0500
commitba6e370ca71abacaa30234cb164427d27c86df13 (patch)
tree2379b6dab897deef1226f66772b8f05e0bb08f9c /model
parent139cb52c99ac525f44a280803447bbbd88369f23 (diff)
downloadchat-ba6e370ca71abacaa30234cb164427d27c86df13.tar.gz
chat-ba6e370ca71abacaa30234cb164427d27c86df13.tar.bz2
chat-ba6e370ca71abacaa30234cb164427d27c86df13.zip
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
Diffstat (limited to 'model')
-rw-r--r--model/channel_view.go35
-rw-r--r--model/client.go27
2 files changed, 62 insertions, 0 deletions
diff --git a/model/channel_view.go b/model/channel_view.go
new file mode 100644
index 000000000..9803c4bbc
--- /dev/null
+++ b/model/channel_view.go
@@ -0,0 +1,35 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+type ChannelView struct {
+ ChannelId string `json:"channel_id"`
+ PrevChannelId string `json:"prev_channel_id"`
+ Time int64 `json:"time"`
+}
+
+func (o *ChannelView) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func ChannelViewFromJson(data io.Reader) *ChannelView {
+ decoder := json.NewDecoder(data)
+ var o ChannelView
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}
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