Migrates Channel.UpdateLastViewedAt to sync by default (#11240)

Этот коммит содержится в:
Rodrigo Villablanca Vásquez
2019-06-26 05:52:43 -04:00
коммит произвёл Hanzei
родитель 6df57d7a83
Коммит 4cf6ae6808
5 изменённых файлов: 97 добавлений и 92 удалений

Просмотреть файл

@@ -1708,8 +1708,8 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError
}
func (a *App) UpdateChannelLastViewedAt(channelIds []string, userId string) *model.AppError {
if result := <-a.Srv.Store.Channel().UpdateLastViewedAt(channelIds, userId); result.Err != nil {
return result.Err
if _, err := a.Srv.Store.Channel().UpdateLastViewedAt(channelIds, userId); err != nil {
return err
}
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
@@ -1856,12 +1856,11 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe
}
}
}
result := <-a.Srv.Store.Channel().UpdateLastViewedAt(channelIds, userId)
if result.Err != nil {
return nil, result.Err
times, err := a.Srv.Store.Channel().UpdateLastViewedAt(channelIds, userId)
if err != nil {
return nil, err
}
times := result.Data.(map[string]int64)
if *a.Config().ServiceSettings.EnableChannelViewedMessages {
for _, channelId := range channelIds {
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CHANNEL_VIEWED, "", "", userId, nil)

Просмотреть файл

@@ -1725,8 +1725,7 @@ func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) store.Store
})
}
func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string) store.StoreChannel {
return store.Do(func(result *store.StoreResult) {
func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) {
props := make(map[string]interface{})
updateIdQuery := ""
@@ -1758,8 +1757,7 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
} else {
extra = err.Error()
}
result.Err = model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+extra, status)
return
return nil, model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+extra, status)
}
times := map[string]int64{}
@@ -1806,12 +1804,10 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
props["UserId"] = userId
if _, err := s.GetMaster().Exec(updateQuery, props); err != nil {
result.Err = model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
return
return nil, model.NewAppError("SqlChannelStore.UpdateLastViewedAt", "store.sql_channel.update_last_viewed_at.app_error", nil, "channel_ids="+strings.Join(channelIds, ",")+", user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
}
result.Data = times
})
return times, nil
}
func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string) *model.AppError {

Просмотреть файл

@@ -176,7 +176,7 @@ type ChannelStore interface {
RemoveMember(channelId string, userId string) *model.AppError
PermanentDeleteMembersByUser(userId string) StoreChannel
PermanentDeleteMembersByChannel(channelId string) *model.AppError
UpdateLastViewedAt(channelIds []string, userId string) StoreChannel
UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError)
IncrementMentionCount(channelId string, userId string) *model.AppError
AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError)
GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError)

Просмотреть файл

@@ -1686,15 +1686,16 @@ func testChannelStoreUpdateLastViewedAt(t *testing.T, ss store.Store) {
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
store.Must(ss.Channel().SaveMember(&m2))
if result := <-ss.Channel().UpdateLastViewedAt([]string{m1.ChannelId}, m1.UserId); result.Err != nil {
t.Fatal("failed to update", result.Err)
} else if result.Data.(map[string]int64)[o1.Id] != o1.LastPostAt {
var times map[string]int64
if times, err = ss.Channel().UpdateLastViewedAt([]string{m1.ChannelId}, m1.UserId); err != nil {
t.Fatal("failed to update", err)
} else if times[o1.Id] != o1.LastPostAt {
t.Fatal("last viewed at time incorrect")
}
if result := <-ss.Channel().UpdateLastViewedAt([]string{m1.ChannelId, m2.ChannelId}, m1.UserId); result.Err != nil {
t.Fatal("failed to update", result.Err)
} else if result.Data.(map[string]int64)[o2.Id] != o2.LastPostAt {
if times, err = ss.Channel().UpdateLastViewedAt([]string{m1.ChannelId, m2.ChannelId}, m1.UserId); err != nil {
t.Fatal("failed to update", err)
} else if times[o2.Id] != o2.LastPostAt {
t.Fatal("last viewed at time incorrect")
}
@@ -1710,7 +1711,7 @@ func testChannelStoreUpdateLastViewedAt(t *testing.T, ss store.Store) {
assert.Equal(t, rm2.LastUpdateAt, o2.LastPostAt)
assert.Equal(t, rm2.MsgCount, o2.TotalMsgCount)
if result := <-ss.Channel().UpdateLastViewedAt([]string{m1.ChannelId}, "missing id"); result.Err != nil {
if _, err := ss.Channel().UpdateLastViewedAt([]string{m1.ChannelId}, "missing id"); err != nil {
t.Fatal("failed to update")
}
}

Просмотреть файл

@@ -1450,19 +1450,28 @@ func (_m *ChannelStore) Update(channel *model.Channel) (*model.Channel, *model.A
}
// UpdateLastViewedAt provides a mock function with given fields: channelIds, userId
func (_m *ChannelStore) UpdateLastViewedAt(channelIds []string, userId string) store.StoreChannel {
func (_m *ChannelStore) UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) {
ret := _m.Called(channelIds, userId)
var r0 store.StoreChannel
if rf, ok := ret.Get(0).(func([]string, string) store.StoreChannel); ok {
var r0 map[string]int64
if rf, ok := ret.Get(0).(func([]string, string) map[string]int64); ok {
r0 = rf(channelIds, userId)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(store.StoreChannel)
r0 = ret.Get(0).(map[string]int64)
}
}
return r0
var r1 *model.AppError
if rf, ok := ret.Get(1).(func([]string, string) *model.AppError); ok {
r1 = rf(channelIds, userId)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// UpdateMember provides a mock function with given fields: member