diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/channel_member.go | 58 | ||||
-rw-r--r-- | model/channel_member_test.go | 18 | ||||
-rw-r--r-- | model/client.go | 4 | ||||
-rw-r--r-- | model/post.go | 5 | ||||
-rw-r--r-- | model/post_test.go | 13 |
5 files changed, 75 insertions, 23 deletions
diff --git a/model/channel_member.go b/model/channel_member.go index 50f51304b..3ae612700 100644 --- a/model/channel_member.go +++ b/model/channel_member.go @@ -10,22 +10,24 @@ import ( ) const ( - CHANNEL_ROLE_ADMIN = "admin" - CHANNEL_NOTIFY_ALL = "all" - CHANNEL_NOTIFY_MENTION = "mention" - CHANNEL_NOTIFY_NONE = "none" - CHANNEL_NOTIFY_QUIET = "quiet" + CHANNEL_ROLE_ADMIN = "admin" + CHANNEL_NOTIFY_DEFAULT = "default" + CHANNEL_NOTIFY_ALL = "all" + CHANNEL_NOTIFY_MENTION = "mention" + CHANNEL_NOTIFY_NONE = "none" + CHANNEL_MARK_UNREAD_ALL = "all" + CHANNEL_MARK_UNREAD_MENTION = "mention" ) 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"` - 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"` + LastUpdateAt int64 `json:"last_update_at"` } func (o *ChannelMember) ToJson() string { @@ -64,8 +66,14 @@ func (o *ChannelMember) IsValid() *AppError { } } - if len(o.NotifyLevel) > 20 || !IsChannelNotifyLevelValid(o.NotifyLevel) { - return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+o.NotifyLevel) + notifyLevel := o.NotifyProps["desktop"] + if len(notifyLevel) > 20 || !IsChannelNotifyLevelValid(notifyLevel) { + return NewAppError("ChannelMember.IsValid", "Invalid notify level", "notify_level="+notifyLevel) + } + + 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 @@ -75,6 +83,24 @@ func (o *ChannelMember) PreSave() { o.LastUpdateAt = GetMillis() } +func (o *ChannelMember) PreUpdate() { + o.LastUpdateAt = GetMillis() +} + func IsChannelNotifyLevelValid(notifyLevel string) bool { - return notifyLevel == CHANNEL_NOTIFY_ALL || notifyLevel == CHANNEL_NOTIFY_MENTION || notifyLevel == CHANNEL_NOTIFY_NONE || notifyLevel == CHANNEL_NOTIFY_QUIET + return notifyLevel == CHANNEL_NOTIFY_DEFAULT || + notifyLevel == CHANNEL_NOTIFY_ALL || + notifyLevel == CHANNEL_NOTIFY_MENTION || + notifyLevel == CHANNEL_NOTIFY_NONE +} + +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 3b64ffbf7..edbb46e9b 100644 --- a/model/channel_member_test.go +++ b/model/channel_member_test.go @@ -31,24 +31,34 @@ func TestChannelMemberIsValid(t *testing.T) { } o.Roles = "missing" - o.NotifyLevel = CHANNEL_NOTIFY_ALL + o.NotifyProps = GetDefaultChannelNotifyProps() o.UserId = NewId() if err := o.IsValid(); err == nil { t.Fatal("should be invalid") } o.Roles = CHANNEL_ROLE_ADMIN - o.NotifyLevel = "junk" + o.NotifyProps["desktop"] = "junk" if err := o.IsValid(); err == nil { t.Fatal("should be invalid") } - o.NotifyLevel = "123456789012345678901" + o.NotifyProps["desktop"] = "123456789012345678901" if err := o.IsValid(); err == nil { t.Fatal("should be invalid") } - o.NotifyLevel = CHANNEL_NOTIFY_ALL + o.NotifyProps["desktop"] = CHANNEL_NOTIFY_ALL + if err := o.IsValid(); err != nil { + t.Fatal(err) + } + + o.NotifyProps["mark_unread"] = "123456789012345678901" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + 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 26e00864d..a291cc4f2 100644 --- a/model/client.go +++ b/model/client.go @@ -450,8 +450,8 @@ func (c *Client) UpdateChannelDesc(data map[string]string) (*Result, *AppError) } } -func (c *Client) UpdateNotifyLevel(data map[string]string) (*Result, *AppError) { - if r, err := c.DoApiPost("/channels/update_notify_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), diff --git a/model/post.go b/model/post.go index e78469940..1fc5963c3 100644 --- a/model/post.go +++ b/model/post.go @@ -120,7 +120,10 @@ func (o *Post) PreSave() { o.OriginalId = "" - o.CreateAt = GetMillis() + if o.CreateAt == 0 { + o.CreateAt = GetMillis() + } + o.UpdateAt = o.CreateAt if o.Props == nil { diff --git a/model/post_test.go b/model/post_test.go index 38f4b4c98..a6b880fa0 100644 --- a/model/post_test.go +++ b/model/post_test.go @@ -83,5 +83,18 @@ func TestPostIsValid(t *testing.T) { func TestPostPreSave(t *testing.T) { o := Post{Message: "test"} o.PreSave() + + if o.CreateAt == 0 { + t.Fatal("should be set") + } + + past := GetMillis() - 1 + o = Post{Message: "test", CreateAt: past} + o.PreSave() + + if o.CreateAt > past { + t.Fatal("should not be updated") + } + o.Etag() } |