diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/channel_member.go | 34 | ||||
-rw-r--r-- | model/channel_member_test.go | 6 | ||||
-rw-r--r-- | model/client.go | 4 |
3 files changed, 28 insertions, 16 deletions
diff --git a/model/channel_member.go b/model/channel_member.go index 58c73d54a..f4a9a9836 100644 --- a/model/channel_member.go +++ b/model/channel_member.go @@ -20,15 +20,15 @@ const ( ) type ChannelMember struct { - ChannelId string `json:"channel_id"` - UserId string `json:"user_id"` - Roles string `json:"roles"` - LastViewedAt int64 `json:"last_viewed_at"` - MsgCount int64 `json:"msg_count"` - MentionCount int64 `json:"mention_count"` - NotifyLevel string `json:"notify_level"` - MarkUnreadLevel string `json:"mark_unread_level"` - LastUpdateAt int64 `json:"last_update_at"` + ChannelId string `json:"channel_id"` + UserId string `json:"user_id"` + Roles string `json:"roles"` + LastViewedAt int64 `json:"last_viewed_at"` + MsgCount int64 `json:"msg_count"` + MentionCount int64 `json:"mention_count"` + NotifyProps StringMap `json:"notify_props"` + NotifyLevel string `json:"notify_level"` + LastUpdateAt int64 `json:"last_update_at"` } func (o *ChannelMember) ToJson() string { @@ -71,8 +71,9 @@ func (o *ChannelMember) IsValid() *AppError { return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+o.NotifyLevel) } - if len(o.MarkUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(o.MarkUnreadLevel) { - return NewAppError("ChannelMember.IsValid", "Invalid mark unread level", "mark_unread_level="+o.MarkUnreadLevel) + markUnreadLevel := o.NotifyProps["mark_unread"] + if len(markUnreadLevel) > 20 || !IsChannelMarkUnreadLevelValid(markUnreadLevel) { + return NewAppError("ChannelMember.IsValid", "Invalid mark unread level", "mark_unread_level="+markUnreadLevel) } return nil @@ -82,6 +83,10 @@ func (o *ChannelMember) PreSave() { o.LastUpdateAt = GetMillis() } +func (o *ChannelMember) PreUpdate() { + o.LastUpdateAt = GetMillis() +} + func IsChannelNotifyLevelValid(notifyLevel string) bool { return notifyLevel == CHANNEL_NOTIFY_DEFAULT || notifyLevel == CHANNEL_NOTIFY_ALL || @@ -92,3 +97,10 @@ func IsChannelNotifyLevelValid(notifyLevel string) bool { func IsChannelMarkUnreadLevelValid(markUnreadLevel string) bool { return markUnreadLevel == CHANNEL_MARK_UNREAD_ALL || markUnreadLevel == CHANNEL_MARK_UNREAD_MENTION } + +func GetDefaultChannelNotifyProps() StringMap { + return StringMap{ + "desktop": CHANNEL_NOTIFY_DEFAULT, + "mark_unread": CHANNEL_MARK_UNREAD_ALL, + } +} diff --git a/model/channel_member_test.go b/model/channel_member_test.go index ae3da73cc..5dc34ae56 100644 --- a/model/channel_member_test.go +++ b/model/channel_member_test.go @@ -32,7 +32,7 @@ func TestChannelMemberIsValid(t *testing.T) { o.Roles = "missing" o.NotifyLevel = CHANNEL_NOTIFY_ALL - o.MarkUnreadLevel = CHANNEL_MARK_UNREAD_ALL + o.NotifyProps = GetDefaultChannelNotifyProps() o.UserId = NewId() if err := o.IsValid(); err == nil { t.Fatal("should be invalid") @@ -54,12 +54,12 @@ func TestChannelMemberIsValid(t *testing.T) { t.Fatal(err) } - o.MarkUnreadLevel = "123456789012345678901" + o.NotifyProps["mark_unread"] = "123456789012345678901" if err := o.IsValid(); err == nil { t.Fatal("should be invalid") } - o.MarkUnreadLevel = CHANNEL_MARK_UNREAD_ALL + o.NotifyProps["mark_unread"] = CHANNEL_MARK_UNREAD_ALL if err := o.IsValid(); err != nil { t.Fatal(err) } diff --git a/model/client.go b/model/client.go index 1d1c5a52c..bba839809 100644 --- a/model/client.go +++ b/model/client.go @@ -459,8 +459,8 @@ func (c *Client) UpdateNotifyLevel(data map[string]string) (*Result, *AppError) } } -func (c *Client) UpdateMarkUnreadLevel(data map[string]string) (*Result, *AppError) { - if r, err := c.DoApiPost("/channels/update_mark_unread_level", MapToJson(data)); err != nil { +func (c *Client) UpdateNotifyProps(data map[string]string) (*Result, *AppError) { + if r, err := c.DoApiPost("/channels/update_notify_props", MapToJson(data)); err != nil { return nil, err } else { return &Result{r.Header.Get(HEADER_REQUEST_ID), |