[MM-16562] Migrate User.GetUnreadCountForChannel to Sync by default (#11604)
* Migrate User.GetUnreadCountForChannel to Sync by default * Remove else block from GetUnreadCountChannel in user_store.go * Return nil value for count when an error occurs in GetUnreadCountForChannel * Fix linting issue in user_store.go
Этот коммит содержится в:
коммит произвёл
Maria A Nunez
родитель
5690df9d95
Коммит
e8f77daa8a
@@ -1842,8 +1842,7 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if notify == model.USER_NOTIFY_MENTION || channel.Type == model.CHANNEL_DIRECT {
|
} else if notify == model.USER_NOTIFY_MENTION || channel.Type == model.CHANNEL_DIRECT {
|
||||||
if result := <-a.Srv.Store.User().GetUnreadCountForChannel(userId, channelId); result.Err == nil {
|
if count, err := a.Srv.Store.User().GetUnreadCountForChannel(userId, channelId); err == nil {
|
||||||
count := result.Data.(int64)
|
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId)
|
channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1143,14 +1143,12 @@ func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) store.StoreChannel {
|
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
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 = cm.ChannelId AND cm.ChannelId = :ChannelId AND cm.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||||
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 = cm.ChannelId AND cm.ChannelId = :ChannelId AND cm.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return 0, model.NewAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
}
|
||||||
result.Data = count
|
return count, nil
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) {
|
func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) {
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ type UserStore interface {
|
|||||||
PermanentDelete(userId string) *model.AppError
|
PermanentDelete(userId string) *model.AppError
|
||||||
AnalyticsActiveCount(time int64) (int64, *model.AppError)
|
AnalyticsActiveCount(time int64) (int64, *model.AppError)
|
||||||
GetUnreadCount(userId string) (int64, error)
|
GetUnreadCount(userId string) (int64, error)
|
||||||
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
GetUnreadCountForChannel(userId string, channelId string) (int64, *model.AppError)
|
||||||
GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError)
|
GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError)
|
||||||
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError)
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import "github.com/stretchr/testify/mock"
|
import mock "github.com/stretchr/testify/mock"
|
||||||
import "github.com/mattermost/mattermost-server/model"
|
import model "github.com/mattermost/mattermost-server/model"
|
||||||
|
|
||||||
// CommandWebhookStore is an autogenerated mock type for the CommandWebhookStore type
|
// CommandWebhookStore is an autogenerated mock type for the CommandWebhookStore type
|
||||||
type CommandWebhookStore struct {
|
type CommandWebhookStore struct {
|
||||||
|
|||||||
@@ -786,19 +786,26 @@ func (_m *UserStore) GetUnreadCount(userId string) (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUnreadCountForChannel provides a mock function with given fields: userId, channelId
|
// GetUnreadCountForChannel provides a mock function with given fields: userId, channelId
|
||||||
func (_m *UserStore) GetUnreadCountForChannel(userId string, channelId string) store.StoreChannel {
|
func (_m *UserStore) GetUnreadCountForChannel(userId string, channelId string) (int64, *model.AppError) {
|
||||||
ret := _m.Called(userId, channelId)
|
ret := _m.Called(userId, channelId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string) int64); ok {
|
||||||
r0 = rf(userId, channelId)
|
r0 = rf(userId, channelId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||||
|
r1 = rf(userId, channelId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsersBatchForIndexing provides a mock function with given fields: startTime, endTime, limit
|
// GetUsersBatchForIndexing provides a mock function with given fields: startTime, endTime, limit
|
||||||
|
|||||||
@@ -1950,12 +1950,14 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
|
|||||||
t.Fatal("should have 3 unread messages")
|
t.Fatal("should have 3 unread messages")
|
||||||
}
|
}
|
||||||
|
|
||||||
badge = (<-ss.User().GetUnreadCountForChannel(u2.Id, c1.Id)).Data.(int64)
|
badge, unreadCountErr = ss.User().GetUnreadCountForChannel(u2.Id, c1.Id)
|
||||||
|
require.Nil(t, unreadCountErr)
|
||||||
if badge != 1 {
|
if badge != 1 {
|
||||||
t.Fatal("should have 1 unread messages for that channel")
|
t.Fatal("should have 1 unread messages for that channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
badge = (<-ss.User().GetUnreadCountForChannel(u2.Id, c2.Id)).Data.(int64)
|
badge, unreadCountErr = ss.User().GetUnreadCountForChannel(u2.Id, c2.Id)
|
||||||
|
require.Nil(t, unreadCountErr)
|
||||||
if badge != 2 {
|
if badge != 2 {
|
||||||
t.Fatal("should have 2 unread messages for that channel")
|
t.Fatal("should have 2 unread messages for that channel")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user