Merge branch 'master' into PLT-462

Этот коммит содержится в:
=Corey Hulen
2015-10-02 08:36:56 -07:00
родитель 9d688821aa c427e9c9d6
Коммит b2052de746
27 изменённых файлов: 501 добавлений и 271 удалений

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

@@ -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 IsChannelNotifyLevelValid(notifyLevel string) bool {
return notifyLevel == CHANNEL_NOTIFY_ALL || notifyLevel == CHANNEL_NOTIFY_MENTION || notifyLevel == CHANNEL_NOTIFY_NONE || notifyLevel == CHANNEL_NOTIFY_QUIET
func (o *ChannelMember) PreUpdate() {
o.LastUpdateAt = GetMillis()
}
func IsChannelNotifyLevelValid(notifyLevel string) bool {
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,
}
}

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

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

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

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

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

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

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

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