Replaced ChannelMember.MarkUnreadLevel with ChannelMember.NotifyProps

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

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

@@ -4,6 +4,7 @@
package store
import (
l4g "code.google.com/p/log4go"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
@@ -30,14 +31,56 @@ func NewSqlChannelStore(sqlStore *SqlStore) ChannelStore {
tablem.ColMap("ChannelId").SetMaxSize(26)
tablem.ColMap("UserId").SetMaxSize(26)
tablem.ColMap("Roles").SetMaxSize(64)
tablem.ColMap("NotifyLevel").SetMaxSize(20)
tablem.ColMap("NotifyProps").SetMaxSize(2000)
}
return s
}
func (s SqlChannelStore) UpgradeSchemaIfNeeded() {
s.CreateColumnIfNotExists("ChannelMembers", "MarkUnreadLevel", "varchar(20)", "varchar(20)", model.CHANNEL_MARK_UNREAD_ALL)
if s.CreateColumnIfNotExists("ChannelMembers", "NotifyProps", "varchar(2000)", "varchar(2000)", "{}") {
// populate NotifyProps from existing NotifyLevel field
// set default values
_, err := s.GetMaster().Exec(
`UPDATE
ChannelMembers
SET
NotifyProps = CONCAT('{"desktop":"', CONCAT(NotifyLevel, '","mark_unread":"` + model.CHANNEL_MARK_UNREAD_ALL + `"}'))`)
if err != nil {
l4g.Error("Unable to set default values for ChannelMembers.NotifyProps")
l4g.Error(err.Error())
}
// assume channels with all notifications enabled are just using the default settings
_, err = s.GetMaster().Exec(
`UPDATE
ChannelMembers
SET
NotifyProps = '{"desktop":"` + model.CHANNEL_NOTIFY_DEFAULT + `","mark_unread":"` + model.CHANNEL_MARK_UNREAD_ALL + `"}'
WHERE
NotifyLevel = '` + model.CHANNEL_NOTIFY_ALL + `'`)
if err != nil {
l4g.Error("Unable to set values for ChannelMembers.NotifyProps when members previously had notifyLevel=all")
l4g.Error(err.Error())
}
// set quiet mode channels to have no notifications and only mark the channel unread on mentions
_, err = s.GetMaster().Exec(
`UPDATE
ChannelMembers
SET
NotifyProps = '{"desktop":"` + model.CHANNEL_NOTIFY_NONE + `","mark_unread":"` + model.CHANNEL_MARK_UNREAD_MENTION + `"}'
WHERE
NotifyLevel = 'quiet'`)
if err != nil {
l4g.Error("Unable to set values for ChannelMembers.NotifyProps when members previously had notifyLevel=quiet")
l4g.Error(err.Error())
}
// TODO uncomment me
// s.RemoveColumnIfExists("ChannelMembers", "NotifyLevel")
}
}
func (s SqlChannelStore) CreateIndexesIfNotExists() {
@@ -387,6 +430,34 @@ func (s SqlChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
return storeChannel
}
func (s SqlChannelStore) UpdateMember(member *model.ChannelMember) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
member.PreUpdate()
if result.Err = member.IsValid(); result.Err != nil {
storeChannel <- result
close(storeChannel)
return
}
if _, err := s.GetMaster().Update(member); err != nil {
result.Err = model.NewAppError("SqlChannelStore.UpdateMember", "We encounted an error updating the channel member",
"channel_id="+member.ChannelId+", "+"user_id="+member.UserId+", "+err.Error())
} else {
result.Data = member
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlChannelStore) GetMembers(channelId string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -650,6 +721,7 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string)
return storeChannel
}
// TODO remove me
func (s SqlChannelStore) UpdateNotifyLevel(channelId, userId, notifyLevel string) StoreChannel {
storeChannel := make(StoreChannel)
@@ -679,35 +751,6 @@ func (s SqlChannelStore) UpdateNotifyLevel(channelId, userId, notifyLevel string
return storeChannel
}
func (s SqlChannelStore) UpdateMarkUnreadLevel(channelId, userId, markUnreadLevel string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
updateAt := model.GetMillis()
_, err := s.GetMaster().Exec(
`UPDATE
ChannelMembers
SET
MarkUnreadLevel = :MarkUnreadLevel,
LastUpdateAt = :LastUpdateAt
WHERE
UserId = :UserId
AND ChannelId = :ChannelId`,
map[string]interface{}{"ChannelId": channelId, "UserId": userId, "MarkUnreadLevel": markUnreadLevel, "LastUpdateAt": updateAt})
if err != nil {
result.Err = model.NewAppError("SqlChannelStore.UpdateMarkUnreadLevel", "We couldn't update the mark unread level", "channel_id="+channelId+", user_id="+userId+", "+err.Error())
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlChannelStore) GetForExport(teamId string) StoreChannel {
storeChannel := make(StoreChannel)

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

@@ -136,14 +136,14 @@ func TestChannelStoreDelete(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o2.Id
m2.UserId = m1.UserId
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m2.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m2))
if r := <-store.Channel().Delete(o1.Id, model.GetMillis()); r.Err != nil {
@@ -225,14 +225,14 @@ func TestChannelMemberStore(t *testing.T) {
o1.ChannelId = c1.Id
o1.UserId = u1.Id
o1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
o1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
o1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&o1))
o2 := model.ChannelMember{}
o2.ChannelId = c1.Id
o2.UserId = u2.Id
o2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
o2.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
o2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&o2))
c1t2 := (<-store.Channel().Get(c1.Id)).Data.(*model.Channel)
@@ -296,7 +296,7 @@ func TestChannelStorePermissionsTo(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
count := (<-store.Channel().CheckPermissionsTo(o1.TeamId, o1.Id, m1.UserId)).Data.(int64)
@@ -377,21 +377,21 @@ func TestChannelStoreGetChannels(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = model.NewId()
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m2.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m2))
m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m3.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m3))
cresult := <-store.Channel().GetChannels(o1.TeamId, m1.UserId)
@@ -423,21 +423,21 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = model.NewId()
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m2.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m2))
m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m3.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m3))
o3 := model.Channel{}
@@ -494,21 +494,21 @@ func TestChannelStoreGetChannelCounts(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
m2 := model.ChannelMember{}
m2.ChannelId = o1.Id
m2.UserId = model.NewId()
m2.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m2.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m2))
m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m3.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m3))
cresult := <-store.Channel().GetChannelCounts(o1.TeamId, m1.UserId)
@@ -538,7 +538,7 @@ func TestChannelStoreUpdateLastViewedAt(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
err := (<-store.Channel().UpdateLastViewedAt(m1.ChannelId, m1.UserId)).Err
@@ -567,7 +567,7 @@ func TestChannelStoreIncrementMentionCount(t *testing.T) {
m1.ChannelId = o1.Id
m1.UserId = model.NewId()
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
err := (<-store.Channel().IncrementMentionCount(m1.ChannelId, m1.UserId)).Err

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

@@ -485,7 +485,7 @@ func TestPostStoreSearch(t *testing.T) {
m1.ChannelId = c1.Id
m1.UserId = userId
m1.NotifyLevel = model.CHANNEL_NOTIFY_ALL
m1.MarkUnreadLevel = model.CHANNEL_MARK_UNREAD_ALL
m1.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m1))
c2 := &model.Channel{}

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

@@ -62,6 +62,7 @@ type ChannelStore interface {
GetForExport(teamId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
UpdateMember(member *model.ChannelMember) StoreChannel
GetMembers(channelId string) StoreChannel
GetMember(channelId string, userId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
@@ -72,7 +73,6 @@ type ChannelStore interface {
UpdateLastViewedAt(channelId string, userId string) StoreChannel
IncrementMentionCount(channelId string, userId string) StoreChannel
UpdateNotifyLevel(channelId string, userId string, notifyLevel string) StoreChannel
UpdateMarkUnreadLevel(channelId string, userId string, markUnreadLevel string) StoreChannel
}
type PostStore interface {