Replaced ChannelMember.MarkUnreadLevel with ChannelMember.NotifyProps

Этот коммит содержится в:
hmhealey
2015-09-30 11:08:36 -04:00
родитель 111fbb2495
Коммит c16b9de8dc
13 изменённых файлов: 227 добавлений и 119 удалений

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

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

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

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

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

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