Этот коммит содержится в:
коммит произвёл
Miguel de la Cruz
родитель
9bab407f26
Коммит
2193e43aac
@@ -72,11 +72,11 @@ func (a *App) sendPushNotificationSync(post *model.Post, user *model.User, chann
|
|||||||
SenderId: post.UserId,
|
SenderId: post.UserId,
|
||||||
}
|
}
|
||||||
|
|
||||||
if badge := <-a.Srv.Store.User().GetUnreadCount(user.Id); badge.Err != nil {
|
if unreadCount, err := a.Srv.Store.User().GetUnreadCount(user.Id); err != nil {
|
||||||
msg.Badge = 1
|
msg.Badge = 1
|
||||||
mlog.Error(fmt.Sprint("We could not get the unread message count for the user", user.Id, badge.Err), mlog.String("user_id", user.Id))
|
mlog.Error(fmt.Sprint("We could not get the unread message count for the user", user.Id, err), mlog.String("user_id", user.Id))
|
||||||
} else {
|
} else {
|
||||||
msg.Badge = int(badge.Data.(int64))
|
msg.Badge = int(unreadCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
contentsConfig := *cfg.EmailSettings.PushNotificationContents
|
contentsConfig := *cfg.EmailSettings.PushNotificationContents
|
||||||
@@ -232,11 +232,11 @@ func (a *App) ClearPushNotificationSync(currentSessionId, userId, channelId stri
|
|||||||
ContentAvailable: 1,
|
ContentAvailable: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
if badge := <-a.Srv.Store.User().GetUnreadCount(userId); badge.Err != nil {
|
if unreadCount, err := a.Srv.Store.User().GetUnreadCount(userId); err != nil {
|
||||||
msg.Badge = 0
|
msg.Badge = 0
|
||||||
mlog.Error(fmt.Sprint("We could not get the unread message count for the user", userId, badge.Err), mlog.String("user_id", userId))
|
mlog.Error(fmt.Sprint("We could not get the unread message count for the user", userId, err), mlog.String("user_id", userId))
|
||||||
} else {
|
} else {
|
||||||
msg.Badge = int(badge.Data.(int64))
|
msg.Badge = int(unreadCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, session := range sessions {
|
for _, session := range sessions {
|
||||||
|
|||||||
@@ -1187,20 +1187,21 @@ func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64) store.StoreChannel
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetUnreadCount(userId string) store.StoreChannel {
|
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query := `
|
||||||
if count, err := us.GetReplica().SelectInt(`
|
|
||||||
SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
|
SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
|
||||||
FROM Channels c
|
FROM Channels c
|
||||||
INNER JOIN ChannelMembers cm
|
INNER JOIN ChannelMembers cm
|
||||||
ON cm.ChannelId = c.Id
|
ON cm.ChannelId = c.Id
|
||||||
AND cm.UserId = :UserId
|
AND cm.UserId = :UserId
|
||||||
AND c.DeleteAt = 0`, map[string]interface{}{"UserId": userId}); err != nil {
|
AND c.DeleteAt = 0
|
||||||
result.Err = model.NewAppError("SqlUserStore.GetMentionCount", "store.sql_user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
`
|
||||||
} else {
|
count, err := us.GetReplica().SelectInt(query, map[string]interface{}{"UserId": userId})
|
||||||
result.Data = count
|
if err != nil {
|
||||||
}
|
return count, model.NewAppError("SqlUserStore.GetMentionCount", "store.sql_user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
})
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) store.StoreChannel {
|
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) store.StoreChannel {
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ type UserStore interface {
|
|||||||
GetSystemAdminProfiles() StoreChannel
|
GetSystemAdminProfiles() StoreChannel
|
||||||
PermanentDelete(userId string) *model.AppError
|
PermanentDelete(userId string) *model.AppError
|
||||||
AnalyticsActiveCount(time int64) StoreChannel
|
AnalyticsActiveCount(time int64) StoreChannel
|
||||||
GetUnreadCount(userId string) StoreChannel
|
GetUnreadCount(userId string) (int64, error)
|
||||||
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
GetUnreadCountForChannel(userId string, channelId string) StoreChannel
|
||||||
GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel
|
GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel
|
||||||
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel
|
||||||
|
|||||||
@@ -608,19 +608,24 @@ func (_m *UserStore) GetTeamGroupUsers(teamID string) store.StoreChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUnreadCount provides a mock function with given fields: userId
|
// GetUnreadCount provides a mock function with given fields: userId
|
||||||
func (_m *UserStore) GetUnreadCount(userId string) store.StoreChannel {
|
func (_m *UserStore) GetUnreadCount(userId string) (int64, error) {
|
||||||
ret := _m.Called(userId)
|
ret := _m.Called(userId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string) int64); ok {
|
||||||
r0 = rf(userId)
|
r0 = rf(userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(1).(func(string) error); ok {
|
||||||
|
r1 = rf(userId)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUnreadCountForChannel provides a mock function with given fields: userId, channelId
|
// GetUnreadCountForChannel provides a mock function with given fields: userId, channelId
|
||||||
|
|||||||
@@ -1874,7 +1874,8 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
|
|||||||
err = ss.Channel().IncrementMentionCount(c2.Id, u2.Id)
|
err = ss.Channel().IncrementMentionCount(c2.Id, u2.Id)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
badge := (<-ss.User().GetUnreadCount(u2.Id)).Data.(int64)
|
badge, unreadCountErr := ss.User().GetUnreadCount(u2.Id)
|
||||||
|
require.Nil(t, unreadCountErr)
|
||||||
if badge != 3 {
|
if badge != 3 {
|
||||||
t.Fatal("should have 3 unread messages")
|
t.Fatal("should have 3 unread messages")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user