mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[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
This commit is contained in:
committed by
Maria A Nunez
parent
5690df9d95
commit
e8f77daa8a
@@ -1143,14 +1143,12 @@ func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.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 = cm.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) GetUnreadCountForChannel(userId string, channelId string) (int64, *model.AppError) {
|
||||
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 err != nil {
|
||||
return 0, model.NewAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) {
|
||||
|
||||
@@ -287,7 +287,7 @@ type UserStore interface {
|
||||
PermanentDelete(userId string) *model.AppError
|
||||
AnalyticsActiveCount(time int64) (int64, *model.AppError)
|
||||
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)
|
||||
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)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
package mocks
|
||||
|
||||
import "github.com/stretchr/testify/mock"
|
||||
import "github.com/mattermost/mattermost-server/model"
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import model "github.com/mattermost/mattermost-server/model"
|
||||
|
||||
// CommandWebhookStore is an autogenerated mock type for the CommandWebhookStore type
|
||||
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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string, string) int64); ok {
|
||||
r0 = rf(userId, channelId)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -1950,12 +1950,14 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
|
||||
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 {
|
||||
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 {
|
||||
t.Fatal("should have 2 unread messages for that channel")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user