mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Change Channel.GetChannelUnread to sync (#10804)
* Change Channel.GetChannelUnread to sync * Address comments
This commit is contained in:
committed by
Jesús Espino
parent
efe9d0a5f8
commit
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) {
|
||||
result := <-a.Srv.Store.Channel().GetChannelUnread(channelId, userId)
|
||||
if result.Err != nil {
|
||||
return nil, result.Err
|
||||
channelUnread, err := a.Srv.Store.Channel().GetChannelUnread(channelId, userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
channelUnread := result.Data.(*model.ChannelUnread)
|
||||
|
||||
if channelUnread.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.CHANNEL_MARK_UNREAD_MENTION {
|
||||
channelUnread.MsgCount = 0
|
||||
|
||||
@@ -682,11 +682,10 @@ func (s SqlChannelStore) updateChannelT(transaction *gorp.Transaction, channel *
|
||||
return result
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetChannelUnread(channelId, userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var unreadChannel model.ChannelUnread
|
||||
err := s.GetReplica().SelectOne(&unreadChannel,
|
||||
`SELECT
|
||||
func (s SqlChannelStore) GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) {
|
||||
var unreadChannel model.ChannelUnread
|
||||
err := s.GetReplica().SelectOne(&unreadChannel,
|
||||
`SELECT
|
||||
Channels.TeamId TeamId, Channels.Id ChannelId, (Channels.TotalMsgCount - ChannelMembers.MsgCount) MsgCount, ChannelMembers.MentionCount MentionCount, ChannelMembers.NotifyProps NotifyProps
|
||||
FROM
|
||||
Channels, ChannelMembers
|
||||
@@ -695,17 +694,15 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) store.StoreC
|
||||
AND Id = :ChannelId
|
||||
AND UserId = :UserId
|
||||
AND DeleteAt = 0`,
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
map[string]interface{}{"ChannelId": channelId, "UserId": userId})
|
||||
|
||||
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 {
|
||||
result.Err.StatusCode = http.StatusNotFound
|
||||
}
|
||||
} else {
|
||||
result.Data = &unreadChannel
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, model.NewAppError("SqlChannelStore.GetChannelUnread", "store.sql_channel.get_unread.app_error", nil, "channelId="+channelId+" "+err.Error(), http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
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) {
|
||||
|
||||
@@ -188,7 +188,7 @@ type ChannelStore interface {
|
||||
SearchMore(userId string, teamId string, term string) StoreChannel
|
||||
GetMembersByIds(channelId string, userIds []string) StoreChannel
|
||||
AnalyticsDeletedTypeCount(teamId string, channelType string) StoreChannel
|
||||
GetChannelUnread(channelId, userId string) StoreChannel
|
||||
GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError)
|
||||
ClearCaches()
|
||||
GetChannelsByScheme(schemeId string, offset int, limit int) 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))
|
||||
|
||||
// Check for Channel 1
|
||||
if resp := <-ss.Channel().GetChannelUnread(c1.Id, uid); resp.Err != nil {
|
||||
t.Fatal(resp.Err)
|
||||
if ch, err := ss.Channel().GetChannelUnread(c1.Id, uid); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
ch := resp.Data.(*model.ChannelUnread)
|
||||
if c1.Id != ch.ChannelId {
|
||||
t.Fatal("wrong channel id")
|
||||
}
|
||||
@@ -327,10 +326,9 @@ func testGetChannelUnread(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
// Check for Channel 2
|
||||
if resp2 := <-ss.Channel().GetChannelUnread(c2.Id, uid); resp2.Err != nil {
|
||||
t.Fatal(resp2.Err)
|
||||
if ch2, err := ss.Channel().GetChannelUnread(c2.Id, uid); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
ch2 := resp2.Data.(*model.ChannelUnread)
|
||||
if c2.Id != ch2.ChannelId {
|
||||
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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
||||
var r0 *model.ChannelUnread
|
||||
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelUnread); ok {
|
||||
r0 = rf(channelId, userId)
|
||||
} else {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user