diff options
author | Debanshu Kundu <debanshu.kundu@joshtechnologygroup.com> | 2017-07-31 23:47:21 +0530 |
---|---|---|
committer | Saturnino Abril <saturnino.abril@gmail.com> | 2017-08-01 02:17:21 +0800 |
commit | 8a91235fb3cdc8d094dbc2eaa0d7baa447132b3c (patch) | |
tree | 28496b27f4da93baa8707bf0690ef88f8cdcc178 /model | |
parent | 59992ae4a4638006ec1489dd834151b258c1728c (diff) | |
download | chat-8a91235fb3cdc8d094dbc2eaa0d7baa447132b3c.tar.gz chat-8a91235fb3cdc8d094dbc2eaa0d7baa447132b3c.tar.bz2 chat-8a91235fb3cdc8d094dbc2eaa0d7baa447132b3c.zip |
#4755 Combining consecutive user join/leave system messages to single message and few other changes. (#5945)
fix 7 and 8
remove @ at "{username} joined the channel"
refactor and update test
Diffstat (limited to 'model')
-rw-r--r-- | model/post.go | 9 | ||||
-rw-r--r-- | model/post_test.go | 45 |
2 files changed, 54 insertions, 0 deletions
diff --git a/model/post.go b/model/post.go index 55e6f591d..67a418700 100644 --- a/model/post.go +++ b/model/post.go @@ -205,6 +205,15 @@ 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 } +func (o *Post) IsUserActivitySystemMessage() bool { + return o.Type == POST_JOIN_LEAVE || + o.Type == POST_JOIN_CHANNEL || + o.Type == POST_LEAVE_CHANNEL || + o.Type == POST_ADD_REMOVE || + o.Type == POST_ADD_TO_CHANNEL || + o.Type == POST_REMOVE_FROM_CHANNEL +} + func (p *Post) Patch(patch *PostPatch) { if patch.IsPinned != nil { p.IsPinned = *patch.IsPinned diff --git a/model/post_test.go b/model/post_test.go index 1096ccbd8..64c8a2f3d 100644 --- a/model/post_test.go +++ b/model/post_test.go @@ -113,3 +113,48 @@ func TestPostIsSystemMessage(t *testing.T) { t.Fatalf("TestPostIsSystemMessage failed, expected post2.IsSystemMessage() to be true") } } + +func TestPostIsUserActivitySystemMessage(t *testing.T) { + post1 := Post{Message: "test_1"} + post1.PreSave() + + if post1.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post1.IsSystemMessage() to be false") + } + + post2 := Post{Message: "test_2", Type: POST_JOIN_LEAVE} + post2.PreSave() + if !post2.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post2.IsSystemMessage() to be true") + } + + post3 := Post{Message: "test_3", Type: POST_JOIN_CHANNEL} + post3.PreSave() + if !post3.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post3.IsSystemMessage() to be true") + } + + post4 := Post{Message: "test_4", Type: POST_LEAVE_CHANNEL} + post4.PreSave() + if !post4.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post4.IsSystemMessage() to be true") + } + + post5 := Post{Message: "test_5", Type: POST_ADD_REMOVE} + post5.PreSave() + if !post5.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post5.IsSystemMessage() to be true") + } + + post6 := Post{Message: "test_6", Type: POST_ADD_TO_CHANNEL} + post6.PreSave() + if !post6.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post6.IsSystemMessage() to be true") + } + + post7 := Post{Message: "test_7", Type: POST_REMOVE_FROM_CHANNEL} + post7.PreSave() + if !post7.IsUserActivitySystemMessage() { + t.Fatalf("TestPostIsUserActivitySystemMessage failed, expected post7.IsSystemMessage() to be true") + } +} |