Change Channel.GetChannelUnread to sync (#10804)
* Change Channel.GetChannelUnread to sync * Address comments
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
efe9d0a5f8
Коммит
9ab3cc9051
@@ -1342,11 +1342,10 @@ func (a *App) GetChannelCounts(teamId string, userId string) (*model.ChannelCoun
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
func (a *App) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||||
result := <-a.Srv.Store.Channel().GetChannelUnread(channelId, userId)
|
channelUnread, err := a.Srv.Store.Channel().GetChannelUnread(channelId, userId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
channelUnread := result.Data.(*model.ChannelUnread)
|
|
||||||
|
|
||||||
if channelUnread.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_MARK_UNREAD_MENTION {
|
if channelUnread.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_MARK_UNREAD_MENTION {
|
||||||
channelUnread.MsgCount = 0
|
channelUnread.MsgCount = 0
|
||||||
|
|||||||
@@ -682,11 +682,10 @@ func (s SqlChannelStore) updateChannelT(transaction *gorp.Transaction, channel *
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) GetChannelUnread(channelId, userId string) store.StoreChannel {
|
func (s SqlChannelStore) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
var unreadChannel model.ChannelUnread
|
||||||
var unreadChannel model.ChannelUnread
|
err := s.GetReplica().SelectOne(&unreadChannel,
|
||||||
err := s.GetReplica().SelectOne(&unreadChannel,
|
`SELECT
|
||||||
`SELECT
|
|
||||||
Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, ChannelMembers.MentionCount MentionCount, ChannelMembers.NotifyProps NotifyProps
|
Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, ChannelMembers.MentionCount MentionCount, ChannelMembers.NotifyProps NotifyProps
|
||||||
FROM
|
FROM
|
||||||
Channels, ChannelMembers
|
Channels, ChannelMembers
|
||||||
@@ -695,17 +694,15 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) store.StoreC
|
|||||||
AND Id = :ChannelId
|
AND Id = :ChannelId
|
||||||
AND UserId = :UserId
|
AND UserId = :UserId
|
||||||
AND DeleteAt = 0`,
|
AND DeleteAt = 0`,
|
||||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.GetChannelUnread", "store.sql_channel.get_unread.app_error", nil, "channelId="+channelId+" "+err.Error(), http.StatusInternalServerError)
|
if err == sql.ErrNoRows {
|
||||||
if err == sql.ErrNoRows {
|
return nil, model.NewAppError("SqlChannelStore.GetChannelUnread", "store.sql_channel.get_unread.app_error", nil, "channelId="+channelId+" "+err.Error(), http.StatusNotFound)
|
||||||
result.Err.StatusCode = http.StatusNotFound
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.Data = &unreadChannel
|
|
||||||
}
|
}
|
||||||
})
|
return nil, model.NewAppError("SqlChannelStore.GetChannelUnread", "store.sql_channel.get_unread.app_error", nil, "channelId="+channelId+" "+err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
return &unreadChannel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) InvalidateChannel(id string) {
|
func (s SqlChannelStore) InvalidateChannel(id string) {
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ type ChannelStore interface {
|
|||||||
SearchMore(userId string, teamId string, term string) StoreChannel
|
SearchMore(userId string, teamId string, term string) StoreChannel
|
||||||
GetMembersByIds(channelId string, userIds []string) StoreChannel
|
GetMembersByIds(channelId string, userIds []string) StoreChannel
|
||||||
AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel
|
AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel
|
||||||
GetChannelUnread(channelId, userId string) StoreChannel
|
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
|
||||||
ClearCaches()
|
ClearCaches()
|
||||||
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel
|
||||||
MigrateChannelMembers(fromChannelId string, fromUserId string) StoreChannel
|
MigrateChannelMembers(fromChannelId string, fromUserId string) StoreChannel
|
||||||
|
|||||||
@@ -301,10 +301,9 @@ func testGetChannelUnread(t *testing.T, ss store.Store) {
|
|||||||
store.Must(ss.Channel().SaveMember(cm2))
|
store.Must(ss.Channel().SaveMember(cm2))
|
||||||
|
|
||||||
// Check for Channel 1
|
// Check for Channel 1
|
||||||
if resp := <-ss.Channel().GetChannelUnread(c1.Id, uid); resp.Err != nil {
|
if ch, err := ss.Channel().GetChannelUnread(c1.Id, uid); err != nil {
|
||||||
t.Fatal(resp.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
ch := resp.Data.(*model.ChannelUnread)
|
|
||||||
if c1.Id != ch.ChannelId {
|
if c1.Id != ch.ChannelId {
|
||||||
t.Fatal("wrong channel id")
|
t.Fatal("wrong channel id")
|
||||||
}
|
}
|
||||||
@@ -327,10 +326,9 @@ func testGetChannelUnread(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for Channel 2
|
// Check for Channel 2
|
||||||
if resp2 := <-ss.Channel().GetChannelUnread(c2.Id, uid); resp2.Err != nil {
|
if ch2, err := ss.Channel().GetChannelUnread(c2.Id, uid); err != nil {
|
||||||
t.Fatal(resp2.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
ch2 := resp2.Data.(*model.ChannelUnread)
|
|
||||||
if c2.Id != ch2.ChannelId {
|
if c2.Id != ch2.ChannelId {
|
||||||
t.Fatal("wrong channel id")
|
t.Fatal("wrong channel id")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,19 +348,28 @@ func (_m *ChannelStore) GetChannelMembersTimezones(channelId string) store.Store
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetChannelUnread provides a mock function with given fields: channelId, userId
|
// GetChannelUnread provides a mock function with given fields: channelId, userId
|
||||||
func (_m *ChannelStore) GetChannelUnread(channelId string, userId string) store.StoreChannel {
|
func (_m *ChannelStore) GetChannelUnread(channelId string, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||||
ret := _m.Called(channelId, userId)
|
ret := _m.Called(channelId, userId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.ChannelUnread
|
||||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelUnread); ok {
|
||||||
r0 = rf(channelId, userId)
|
r0 = rf(channelId, userId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.ChannelUnread)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||||
|
r1 = rf(channelId, userId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChannels provides a mock function with given fields: teamId, userId, includeDeleted
|
// GetChannels provides a mock function with given fields: teamId, userId, includeDeleted
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user