diff --git a/api/channel.go b/api/channel.go index 99640e71a7..6fa6ec2954 100644 --- a/api/channel.go +++ b/api/channel.go @@ -421,7 +421,7 @@ func JoinChannel(c *Context, channelId string, role string) { c.Err = err return } - PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`User %v has joined this channel.`, user.Username)) + PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(`%v has joined the channel.`, user.Username)) } else { c.Err = model.NewAppError("join", "You do not have the appropriate permissions", "") c.Err.StatusCode = http.StatusForbidden diff --git a/model/post.go b/model/post.go index e66009dd69..2c90d8b7b0 100644 --- a/model/post.go +++ b/model/post.go @@ -10,9 +10,10 @@ import ( ) const ( - POST_DEFAULT = "" - POST_SLACK_ATTACHMENT = "slack_attachment" - POST_JOIN_LEAVE = "join_leave" + POST_SYSTEM_MESSAGE_PREFIX = "system_" + POST_DEFAULT = "" + POST_SLACK_ATTACHMENT = "slack_attachment" + POST_JOIN_LEAVE = "system_join_leave" ) type Post struct { @@ -159,3 +160,7 @@ func (o *Post) AddProp(key string, value interface{}) { func (o *Post) PreExport() { } + +func (o *Post) IsSystemMessage() bool { + return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX +} diff --git a/model/post_test.go b/model/post_test.go index f498c83e6e..cbd323fab4 100644 --- a/model/post_test.go +++ b/model/post_test.go @@ -98,3 +98,18 @@ func TestPostPreSave(t *testing.T) { o.Etag() } + +func TestPostIsSystemMessage(t *testing.T) { + post1 := Post{Message: "test_1"} + post1.PreSave() + + if post1.IsSystemMessage() { + t.Fatalf("TestPostIsSystemMessage failed, expected post1.IsSystemMessage() to be false") + } + + post2 := Post{Message: "test_2", Type: POST_JOIN_LEAVE} + post2.PreSave() + if !post2.IsSystemMessage() { + t.Fatalf("TestPostIsSystemMessage failed, expected post2.IsSystemMessage() to be true") + } +} diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 9db5806c54..035309e211 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -38,7 +38,8 @@ func NewSqlPostStore(sqlStore *SqlStore) PostStore { } func (s SqlPostStore) UpgradeSchemaIfNeeded() { - s.RemoveColumnIfExists("Posts", "ImgCount") // remove after 1.3 release + s.RemoveColumnIfExists("Posts", "ImgCount") // remove after 1.3 release + s.GetMaster().Exec(`UPDATE Preferences SET Type = :NewType WHERE Type = :CurrentType`, map[string]string{"NewType": model.POST_JOIN_LEAVE, "CurrentType": "join_leave"}) // remove after 1.3 release } func (s SqlPostStore) CreateIndexesIfNotExists() { diff --git a/web/react/components/post.jsx b/web/react/components/post.jsx index b32656bfca..786a4a3250 100644 --- a/web/react/components/post.jsx +++ b/web/react/components/post.jsx @@ -173,6 +173,11 @@ export default class Post extends React.Component { shouldHighlightClass = 'post--highlight'; } + let systemMessageClass = ''; + if (utils.isSystemMessage(post)) { + systemMessageClass = 'post--system'; + } + let profilePic = null; if (!this.props.hideProfilePic) { let src = '/api/v1/users/' + post.user_id + '/image?time=' + timestamp + '&' + utils.getSessionIndex(); @@ -180,6 +185,8 @@ export default class Post extends React.Component { if (post.props.override_icon_url) { src = post.props.override_icon_url; } + } else if (utils.isSystemMessage(post)) { + src = Constants.SYSTEM_MESSAGE_PROFILE_IMAGE; } profilePic = ( @@ -195,7 +202,7 @@ export default class Post extends React.Component {