Badge count fix for push notifications when CRT is enabled (#20898)

* Fix

* Fixed other cases and tests

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Anurag Shivarathri
2022-09-12 14:51:33 +05:30
коммит произвёл GitHub
родитель 8edd351f27
Коммит 203c6a5013
11 изменённых файлов: 85 добавлений и 51 удалений

Просмотреть файл

@@ -960,20 +960,20 @@ func (_m *UserStore) GetTeamGroupUsers(teamID string) ([]*model.User, error) {
return r0, r1
}
// GetUnreadCount provides a mock function with given fields: userID
func (_m *UserStore) GetUnreadCount(userID string) (int64, error) {
ret := _m.Called(userID)
// GetUnreadCount provides a mock function with given fields: userID, isCRTEnabled
func (_m *UserStore) GetUnreadCount(userID string, isCRTEnabled bool) (int64, error) {
ret := _m.Called(userID, isCRTEnabled)
var r0 int64
if rf, ok := ret.Get(0).(func(string) int64); ok {
r0 = rf(userID)
if rf, ok := ret.Get(0).(func(string, bool) int64); ok {
r0 = rf(userID, isCRTEnabled)
} else {
r0 = ret.Get(0).(int64)
}
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(userID)
if rf, ok := ret.Get(1).(func(string, bool) error); ok {
r1 = rf(userID, isCRTEnabled)
} else {
r1 = ret.Error(1)
}

Просмотреть файл

@@ -2440,14 +2440,23 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
nErr = ss.Channel().IncrementMentionCount(c2.Id, []string{u2.Id}, false)
require.NoError(t, nErr)
badge, unreadCountErr := ss.User().GetUnreadCount(u2.Id)
badge, unreadCountErr := ss.User().GetUnreadCount(u2.Id, false)
require.NoError(t, unreadCountErr)
require.Equal(t, int64(3), badge, "should have 3 unread messages")
badge, unreadCountErr = ss.User().GetUnreadCount(u3.Id)
badge, unreadCountErr = ss.User().GetUnreadCount(u3.Id, false)
require.NoError(t, unreadCountErr)
require.Equal(t, int64(1), badge, "should have 1 unread message")
// Increment root mentions by 1
nErr = ss.Channel().IncrementMentionCount(c1.Id, []string{u3.Id}, true)
require.NoError(t, nErr)
// CRT is enabled, only root mentions are counted
badge, unreadCountErr = ss.User().GetUnreadCount(u3.Id, true)
require.NoError(t, unreadCountErr)
require.Equal(t, int64(1), badge, "should have 1 unread message with CRT")
badge, unreadCountErr = ss.User().GetUnreadCountForChannel(u2.Id, c1.Id)
require.NoError(t, unreadCountErr)
require.Equal(t, int64(1), badge, "should have 1 unread messages for that channel")