summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-09-30 11:08:36 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-10-01 08:31:11 -0400
commitc16b9de8dc4924cf2fb243579284e67f55cf3a47 (patch)
treed7780fae809cec0b021281638f25ed7920050b0a /store/sql_channel_store.go
parent111fbb2495e88d69bec29971da8ddf086ac3f3b6 (diff)
downloadchat-c16b9de8dc4924cf2fb243579284e67f55cf3a47.tar.gz
chat-c16b9de8dc4924cf2fb243579284e67f55cf3a47.tar.bz2
chat-c16b9de8dc4924cf2fb243579284e67f55cf3a47.zip
Replaced ChannelMember.MarkUnreadLevel with ChannelMember.NotifyProps
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r--store/sql_channel_store.go105
1 files changed, 74 insertions, 31 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 892ee1398..f453c3589 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -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)