Do not send push notifications for channels being actively viewed (#3931)

Этот коммит содержится в:
Joram Wilander
2016-09-02 12:50:15 -04:00
коммит произвёл GitHub
родитель eb0111f6bb
Коммит f32eb525f3
20 изменённых файлов: 213 добавлений и 47 удалений

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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))

Просмотреть файл

@@ -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)