diff options
author | Elias Nahum <nahumhbl@gmail.com> | 2016-03-11 00:14:55 -0300 |
---|---|---|
committer | Elias Nahum <nahumhbl@gmail.com> | 2016-03-17 13:20:17 -0300 |
commit | 1f5c8c4e4ebb2e163278f3e62d640f41a2df7294 (patch) | |
tree | a659674c9980e23752fc8d9f07eb48014c8bce26 /store | |
parent | d383ed2f8dfc320c090b67d9f2e2d111710ca3cf (diff) | |
download | chat-1f5c8c4e4ebb2e163278f3e62d640f41a2df7294.tar.gz chat-1f5c8c4e4ebb2e163278f3e62d640f41a2df7294.tar.bz2 chat-1f5c8c4e4ebb2e163278f3e62d640f41a2df7294.zip |
Option to enable full snippets in push notifications
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_user_store.go | 19 | ||||
-rw-r--r-- | store/sql_user_store_test.go | 81 | ||||
-rw-r--r-- | store/store.go | 2 |
3 files changed, 102 insertions, 0 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index cc6829b94..6062b8a6a 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -652,3 +652,22 @@ func (us SqlUserStore) AnalyticsUniqueUserCount(teamId string) StoreChannel { return storeChannel } + +func (us SqlUserStore) GetUnreadCount(userId 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 0 END + cm.MentionCount) FROM Channels c INNER JOIN ChannelMembers cm ON cm.ChannelId = c.Id AND cm.UserId = :UserId", map[string]interface{}{"UserId": userId}); err != nil { + result.Err = model.NewLocAppError("SqlUserStore.GetMentionCount", "store.sql_user.get_unread_count.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 2350bad30..8f2366136 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -421,3 +421,84 @@ func TestUserStoreUpdateAuthData(t *testing.T) { } } } + +func TestUserUnreadCount(t *testing.T) { + Setup() + + teamId := model.NewId() + + c1 := model.Channel{} + c1.TeamId = teamId + c1.DisplayName = "Unread Messages" + c1.Name = "unread-messages" + c1.Type = model.CHANNEL_OPEN + + c2 := model.Channel{} + c2.TeamId = teamId + c2.DisplayName = "Unread Direct" + c2.Name = "unread-direct" + c2.Type = model.CHANNEL_DIRECT + + u1 := model.User{} + u1.Email = model.NewId() + u1.Username = "user1" + u1.TeamId = teamId + Must(store.User().Save(&u1)) + + u2 := model.User{} + u2.Email = model.NewId() + u2.Username = "user2" + u2.TeamId = teamId + Must(store.User().Save(&u2)) + + if err := (<-store.Channel().Save(&c1)).Err; err != nil { + t.Fatal("couldn't save item", err) + } + + m1 := model.ChannelMember{} + m1.ChannelId = c1.Id + m1.UserId = u1.Id + m1.NotifyProps = model.GetDefaultChannelNotifyProps() + + m2 := model.ChannelMember{} + m2.ChannelId = c1.Id + m2.UserId = u2.Id + m2.NotifyProps = model.GetDefaultChannelNotifyProps() + + Must(store.Channel().SaveMember(&m1)) + Must(store.Channel().SaveMember(&m2)) + + m1.ChannelId = c2.Id + m2.ChannelId = c2.Id + + if err := (<-store.Channel().SaveDirectChannel(&c2, &m1, &m2)).Err; err != nil { + t.Fatal("couldn't save direct channel", err) + } + + p1 := model.Post{} + p1.ChannelId = c1.Id + p1.UserId = u1.Id + p1.Message = "this is a message for @" + u2.Username + + // Post one message with mention to open channel + Must(store.Post().Save(&p1)) + Must(store.Channel().IncrementMentionCount(c1.Id, u2.Id)) + + // Post 2 messages without mention to direct channel + p2 := model.Post{} + p2.ChannelId = c2.Id + p2.UserId = u1.Id + p2.Message = "first message" + Must(store.Post().Save(&p2)) + + p3 := model.Post{} + p3.ChannelId = c2.Id + p3.UserId = u1.Id + p3.Message = "second message" + Must(store.Post().Save(&p3)) + + badge := (<-store.User().GetUnreadCount(u2.Id)).Data.(int64) + if badge != 3 { + t.Fatal("should have 3 unread messages") + } +} diff --git a/store/store.go b/store/store.go index b041cfa25..1738ba84e 100644 --- a/store/store.go +++ b/store/store.go @@ -130,6 +130,8 @@ type UserStore interface { GetSystemAdminProfiles() StoreChannel PermanentDelete(userId string) StoreChannel AnalyticsUniqueUserCount(teamId string) StoreChannel + + GetUnreadCount(userId string) StoreChannel } type SessionStore interface { |