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 /store/sql_post_store.go | |
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 'store/sql_post_store.go')
-rw-r--r-- | store/sql_post_store.go | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go index e89b5e042..c66e44274 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -97,8 +97,7 @@ func (s SqlPostStore) Save(post *model.Post) StoreChannel { } else { time := post.UpdateAt - if post.Type != model.POST_JOIN_LEAVE && post.Type != model.POST_JOIN_CHANNEL && post.Type != model.POST_LEAVE_CHANNEL && - post.Type != model.POST_ADD_REMOVE && post.Type != model.POST_ADD_TO_CHANNEL && post.Type != model.POST_REMOVE_FROM_CHANNEL { + if !post.IsUserActivitySystemMessage() { s.GetMaster().Exec("UPDATE Channels SET LastPostAt = :LastPostAt, TotalMsgCount = TotalMsgCount + 1 WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": post.ChannelId}) } else { // don't update TotalMsgCount for unimportant messages so that the channel isn't marked as unread @@ -1355,3 +1354,29 @@ func (s SqlPostStore) GetPostsBatchForIndexing(startTime int64, limit int) Store return storeChannel } + +func (s SqlPostStore) GetLastPostForChannel(channelId string) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + + var post model.Post + query := ` + SELECT * FROM Posts + WHERE ChannelId = :channelId AND DeleteAt = 0 + ORDER BY CreateAt DESC + LIMIT 1 + ` + + if err := s.GetReplica().SelectOne(&post, query, map[string]interface{}{"channelId": channelId}); err != nil { + l4g.Error(err) + } + + result.Data = &post + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} |