Merge pull request #138 from hmhealey/mm756

MM-756 Don't mark channels as unread after user joined/left messages
Этот коммит содержится в:
Christopher Speller
2015-07-07 13:36:05 -04:00
родитель 95b9f87288 23e527978e
Коммит 4e856c29b2
3 изменённых файлов: 15 добавлений и 8 удалений

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

@@ -366,7 +366,7 @@ func JoinChannel(c *Context, channelId string, role string) {
post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf( post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf(
`User %v has joined this channel.`, `User %v has joined this channel.`,
user.Username)} user.Username), Type: model.POST_JOIN_LEAVE}
if _, err := CreatePost(c, post, false); err != nil { if _, err := CreatePost(c, post, false); err != nil {
l4g.Error("Failed to post join message %v", err) l4g.Error("Failed to post join message %v", err)
c.Err = model.NewAppError("joinChannel", "Failed to send join request", "") c.Err = model.NewAppError("joinChannel", "Failed to send join request", "")
@@ -453,7 +453,7 @@ func leaveChannel(c *Context, w http.ResponseWriter, r *http.Request) {
post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf( post := &model.Post{ChannelId: channel.Id, Message: fmt.Sprintf(
`%v has left the channel.`, `%v has left the channel.`,
user.Username)} user.Username), Type: model.POST_JOIN_LEAVE}
if _, err := CreatePost(c, post, false); err != nil { if _, err := CreatePost(c, post, false); err != nil {
l4g.Error("Failed to post leave message %v", err) l4g.Error("Failed to post leave message %v", err)
c.Err = model.NewAppError("leaveChannel", "Failed to send leave message", "") c.Err = model.NewAppError("leaveChannel", "Failed to send leave message", "")
@@ -646,7 +646,7 @@ func addChannelMember(c *Context, w http.ResponseWriter, r *http.Request) {
post := &model.Post{ChannelId: id, Message: fmt.Sprintf( post := &model.Post{ChannelId: id, Message: fmt.Sprintf(
`%v added to the channel by %v`, `%v added to the channel by %v`,
nUser.Username, oUser.Username)} nUser.Username, oUser.Username), Type: model.POST_JOIN_LEAVE}
if _, err := CreatePost(c, post, false); err != nil { if _, err := CreatePost(c, post, false); err != nil {
l4g.Error("Failed to post add message %v", err) l4g.Error("Failed to post add message %v", err)
c.Err = model.NewAppError("addChannelMember", "Failed to add member to channel", "") c.Err = model.NewAppError("addChannelMember", "Failed to add member to channel", "")

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

@@ -9,7 +9,8 @@ import (
) )
const ( const (
POST_DEFAULT = "" POST_DEFAULT = ""
POST_JOIN_LEAVE = "join_leave"
) )
type Post struct { type Post struct {
@@ -100,7 +101,7 @@ func (o *Post) IsValid() *AppError {
return NewAppError("Post.IsValid", "Invalid hashtags", "id="+o.Id) return NewAppError("Post.IsValid", "Invalid hashtags", "id="+o.Id)
} }
if !(o.Type == POST_DEFAULT) { if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE) {
return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type) return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type)
} }

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

@@ -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()) result.Err = model.NewAppError("SqlPostStore.Save", "We couldn't save the Post", "id="+post.Id+", "+err.Error())
} else { } else {
time := model.GetMillis() 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 { if len(post.RootId) > 0 {
s.GetMaster().Exec("UPDATE Posts SET UpdateAt = ? WHERE Id = ?", time, post.RootId) 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" searchType := "Message"
if isHashtagSearch { if isHashtagSearch {
searchType = "Hashtags" searchType = "Hashtags"
for _,term := range strings.Split(terms, " ") { for _, term := range strings.Split(terms, " ") {
termMap[term] = true; termMap[term] = true
} }
} }