summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/post.go14
-rw-r--r--model/post_test.go15
2 files changed, 25 insertions, 4 deletions
diff --git a/model/post.go b/model/post.go
index e66009dd6..5c86ce70d 100644
--- a/model/post.go
+++ b/model/post.go
@@ -10,9 +10,11 @@ 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"
+ POST_HEADER_CHANGE = "system_header_change"
)
type Post struct {
@@ -104,7 +106,7 @@ func (o *Post) IsValid() *AppError {
}
// should be removed once more message types are supported
- if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT) {
+ if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE) {
return NewAppError("Post.IsValid", "Invalid type", "id="+o.Type)
}
@@ -159,3 +161,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 f498c83e6..cbd323fab 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")
+ }
+}