summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-08-31 12:52:14 -0400
committerGitHub <noreply@github.com>2016-08-31 12:52:14 -0400
commit26f96b240ddc8cf8c56decea72102b10238e0a43 (patch)
tree7eda509038de3d6b95a02b95bee2ad72e2e3a063 /store
parentb0b39ce71cd77fbffbf23d56b20db1927f0c6cb1 (diff)
downloadchat-26f96b240ddc8cf8c56decea72102b10238e0a43.tar.gz
chat-26f96b240ddc8cf8c56decea72102b10238e0a43.tar.bz2
chat-26f96b240ddc8cf8c56decea72102b10238e0a43.zip
PLT-3462 Add the ability to clear push notifications after channel is viewed (#3834)
* Add the ability to clear push notifications after channel is viewed * Fix race condition between updating the mention count and reading it when sending push notifications
Diffstat (limited to 'store')
-rw-r--r--store/sql_user_store.go19
-rw-r--r--store/sql_user_store_test.go10
-rw-r--r--store/store.go1
3 files changed, 30 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 027dcbd75..61bfa35b8 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -921,3 +921,22 @@ func (us SqlUserStore) GetUnreadCount(userId string) StoreChannel {
return storeChannel
}
+
+func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ if count, err := us.GetReplica().SelectInt("SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = :ChannelId AND cm.ChannelId = :ChannelId AND cm.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
+ result.Err = model.NewLocAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error())
+ } else {
+ result.Data = count
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go
index e44cee99d..74c27dbea 100644
--- a/store/sql_user_store_test.go
+++ b/store/sql_user_store_test.go
@@ -660,6 +660,16 @@ func TestUserUnreadCount(t *testing.T) {
if badge != 3 {
t.Fatal("should have 3 unread messages")
}
+
+ badge = (<-store.User().GetUnreadCountForChannel(u2.Id, c1.Id)).Data.(int64)
+ if badge != 1 {
+ t.Fatal("should have 1 unread messages for that channel")
+ }
+
+ badge = (<-store.User().GetUnreadCountForChannel(u2.Id, c2.Id)).Data.(int64)
+ if badge != 2 {
+ t.Fatal("should have 2 unread messages for that channel")
+ }
}
func TestUserStoreUpdateMfaSecret(t *testing.T) {
diff --git a/store/store.go b/store/store.go
index 78db41e77..d3b908106 100644
--- a/store/store.go
+++ b/store/store.go
@@ -153,6 +153,7 @@ type UserStore interface {
PermanentDelete(userId string) StoreChannel
AnalyticsUniqueUserCount(teamId string) StoreChannel
GetUnreadCount(userId string) StoreChannel
+ GetUnreadCountForChannel(userId string, channelId string) StoreChannel
}
type SessionStore interface {