From 15d64fb201848002a25facc3bbffc9535a704df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 26 Sep 2018 16:34:12 +0200 Subject: MM-7188: Cleaning push notification on every read, not only on channel switch (#9348) * MM-7188: Cleaning push notification on every read, not only on channel switch * Removed unnecesary goroutine * Fixing tests * Applying suggestion from PR --- store/sqlstore/user_store.go | 10 ++++++++++ store/store.go | 1 + store/storetest/mocks/UserStore.go | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) (limited to 'store') diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 900010ce4..941aa60e9 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -949,6 +949,16 @@ func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) }) } +func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) store.StoreChannel { + return store.Do(func(result *store.StoreResult) { + if count, err := us.GetReplica().SelectInt("SELECT SUM(c.TotalMsgCount - cm.MsgCount) 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.NewAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + } else { + result.Data = count + } + }) +} + func (us SqlUserStore) Search(teamId string, term string, options map[string]bool) store.StoreChannel { return store.Do(func(result *store.StoreResult) { searchQuery := "" diff --git a/store/store.go b/store/store.go index 8073b9437..608d501c0 100644 --- a/store/store.go +++ b/store/store.go @@ -265,6 +265,7 @@ type UserStore interface { AnalyticsActiveCount(time int64) StoreChannel GetUnreadCount(userId string) StoreChannel GetUnreadCountForChannel(userId string, channelId string) StoreChannel + GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel GetRecentlyActiveUsersForTeam(teamId string, offset, limit int) StoreChannel GetNewUsersForTeam(teamId string, offset, limit int) StoreChannel Search(teamId string, term string, options map[string]bool) StoreChannel diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index 51c37cb20..b505a2f0b 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -194,6 +194,22 @@ func (_m *UserStore) GetAllUsingAuthService(authService string) store.StoreChann return r0 } +// GetAnyUnreadPostCountForChannel provides a mock function with given fields: userId, channelId +func (_m *UserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) store.StoreChannel { + ret := _m.Called(userId, channelId) + + var r0 store.StoreChannel + if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok { + r0 = rf(userId, channelId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(store.StoreChannel) + } + } + + return r0 +} + // GetByAuth provides a mock function with given fields: authData, authService func (_m *UserStore) GetByAuth(authData *string, authService string) store.StoreChannel { ret := _m.Called(authData, authService) -- cgit v1.2.3-1-g7c22