diff options
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_channel_store.go | 16 | ||||
-rw-r--r-- | store/sql_post_store.go | 12 | ||||
-rw-r--r-- | store/sql_user_store.go | 4 |
3 files changed, 25 insertions, 7 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index 463fce16f..d61fbcdd0 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -79,7 +79,13 @@ func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel { if err := s.GetMaster().Insert(channel); err != nil { if strings.Contains(err.Error(), "Duplicate entry") && strings.Contains(err.Error(), "for key 'Name'") { - result.Err = model.NewAppError("SqlChannelStore.Save", "A channel with that name already exists", "id="+channel.Id+", "+err.Error()) + dupChannel := model.Channel{} + s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId=? AND Name=? AND DeleteAt > 0", channel.TeamId, channel.Name) + if (dupChannel.DeleteAt > 0) { + result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name was previously created", "id="+channel.Id+", "+err.Error()) + } else { + result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name already exists", "id="+channel.Id+", "+err.Error()) + } } else { result.Err = model.NewAppError("SqlChannelStore.Save", "We couldn't save the channel", "id="+channel.Id+", "+err.Error()) } @@ -111,7 +117,13 @@ func (s SqlChannelStore) Update(channel *model.Channel) StoreChannel { if count, err := s.GetMaster().Update(channel); err != nil { if strings.Contains(err.Error(), "Duplicate entry") && strings.Contains(err.Error(), "for key 'Name'") { - result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name already exists", "id="+channel.Id+", "+err.Error()) + dupChannel := model.Channel{} + s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId=? AND Name=? AND DeleteAt > 0", channel.TeamId, channel.Name) + if (dupChannel.DeleteAt > 0) { + result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name was previously created", "id="+channel.Id+", "+err.Error()) + } else { + result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that name already exists", "id="+channel.Id+", "+err.Error()) + } } else { result.Err = model.NewAppError("SqlChannelStore.Update", "We encounted an error updating the channel", "id="+channel.Id+", "+err.Error()) } diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 01900023f..7ada515d7 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -72,7 +72,13 @@ func (s SqlPostStore) Save(post *model.Post) StoreChannel { result.Err = model.NewAppError("SqlPostStore.Save", "We couldn't save the Post", "id="+post.Id+", "+err.Error()) } else { time := model.GetMillis() - s.GetMaster().Exec("UPDATE Channels SET LastPostAt = ?, TotalMsgCount = TotalMsgCount + 1 WHERE Id = ?", time, post.ChannelId) + + if post.Type != model.POST_JOIN_LEAVE { + s.GetMaster().Exec("UPDATE Channels SET LastPostAt = ?, TotalMsgCount = TotalMsgCount + 1 WHERE Id = ?", time, post.ChannelId) + } else { + // don't update TotalMsgCount for unimportant messages so that the channel isn't marked as unread + s.GetMaster().Exec("UPDATE Channels SET LastPostAt = ? WHERE Id = ?", time, post.ChannelId) + } if len(post.RootId) > 0 { s.GetMaster().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ?", time, post.RootId) @@ -361,8 +367,8 @@ func (s SqlPostStore) Search(teamId string, userId string, terms string, isHasht searchType := "Message" if isHashtagSearch { searchType = "Hashtags" - for _,term := range strings.Split(terms, " ") { - termMap[term] = true; + for _, term := range strings.Split(terms, " ") { + termMap[term] = true } } diff --git a/store/sql_user_store.go b/store/sql_user_store.go index bcaff1487..fc3d125c4 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -95,7 +95,7 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel { return storeChannel } -func (us SqlUserStore) Update(user *model.User, allowRoleActiveUpdate bool) StoreChannel { +func (us SqlUserStore) Update(user *model.User, allowActiveUpdate bool) StoreChannel { storeChannel := make(StoreChannel) @@ -125,7 +125,7 @@ func (us SqlUserStore) Update(user *model.User, allowRoleActiveUpdate bool) Stor user.LastPingAt = oldUser.LastPingAt user.EmailVerified = oldUser.EmailVerified - if !allowRoleActiveUpdate { + if !allowActiveUpdate { user.Roles = oldUser.Roles user.DeleteAt = oldUser.DeleteAt } |