summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/client.go24
-rw-r--r--model/status.go10
-rw-r--r--model/status_test.go2
-rw-r--r--model/user.go18
4 files changed, 29 insertions, 25 deletions
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
diff --git a/model/status.go b/model/status.go
index 477b750d5..f4ad8e775 100644
--- a/model/status.go
+++ b/model/status.go
@@ -9,10 +9,11 @@ import (
)
const (
- STATUS_OFFLINE = "offline"
- STATUS_AWAY = "away"
- STATUS_ONLINE = "online"
- STATUS_CACHE_SIZE = 10000
+ STATUS_OFFLINE = "offline"
+ STATUS_AWAY = "away"
+ STATUS_ONLINE = "online"
+ STATUS_CACHE_SIZE = 10000
+ STATUS_CHANNEL_TIMEOUT = 20000 // 20 seconds
)
type Status struct {
@@ -20,6 +21,7 @@ type Status struct {
Status string `json:"status"`
Manual bool `json:"manual"`
LastActivityAt int64 `json:"last_activity_at"`
+ ActiveChannel string `json:"active_channel"`
}
func (o *Status) ToJson() string {
diff --git a/model/status_test.go b/model/status_test.go
index b5e876bc5..0b4a33d5d 100644
--- a/model/status_test.go
+++ b/model/status_test.go
@@ -9,7 +9,7 @@ import (
)
func TestStatus(t *testing.T) {
- status := Status{NewId(), STATUS_ONLINE, true, 0}
+ status := Status{NewId(), STATUS_ONLINE, true, 0, ""}
json := status.ToJson()
status2 := StatusFromJson(strings.NewReader(json))
diff --git a/model/user.go b/model/user.go
index 8917658df..434ce2732 100644
--- a/model/user.go
+++ b/model/user.go
@@ -378,24 +378,6 @@ func (u *User) IsLDAPUser() bool {
return false
}
-func (u *User) StatusAllowsPushNotification(status *Status) bool {
- props := u.NotifyProps
-
- if props["push"] == "none" {
- return false
- }
-
- if pushStatus, ok := props["push_status"]; pushStatus == STATUS_ONLINE || !ok {
- return true
- } else if pushStatus == STATUS_AWAY && (status.Status == STATUS_AWAY || status.Status == STATUS_OFFLINE) {
- return true
- } else if pushStatus == STATUS_OFFLINE && status.Status == STATUS_OFFLINE {
- return true
- }
-
- return false
-}
-
// UserFromJson will decode the input and return a User
func UserFromJson(data io.Reader) *User {
decoder := json.NewDecoder(data)