MM-30558 - Add unreadReplies and unreadMentions to thread membership (#16304)

Этот коммит содержится в:
Eli Yukelzon
2020-12-06 10:02:53 +02:00
коммит произвёл GitHub
родитель cd9185fa23
Коммит 86e228b6c6
18 изменённых файлов: 653 добавлений и 187 удалений

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

@@ -691,8 +691,8 @@ type AppIface interface {
GetTeamsForUser(userId string) ([]*model.Team, *model.AppError)
GetTeamsUnreadForUser(excludeTeamId string, userId string) ([]*model.TeamUnread, *model.AppError)
GetTermsOfService(id string) (*model.TermsOfService, *model.AppError)
GetThreadMembershipsForUser(userId string) ([]*model.ThreadMembership, error)
GetThreadsForUser(userId string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError)
GetThreadMembershipsForUser(userId, teamId string) ([]*model.ThreadMembership, error)
GetThreadsForUser(userId, teamId string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError)
GetUploadSession(uploadId string) (*model.UploadSession, *model.AppError)
GetUploadSessionsForUser(userId string) ([]*model.UploadSession, *model.AppError)
GetUser(userId string) (*model.User, *model.AppError)
@@ -1002,8 +1002,8 @@ type AppIface interface {
UpdateTeamPrivacy(teamId string, teamType string, allowOpenInvite bool) *model.AppError
UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
UpdateThreadFollowForUser(userId, threadId string, state bool) *model.AppError
UpdateThreadReadForUser(userId, threadId string, timestamp int64) *model.AppError
UpdateThreadsReadForUser(userId string, timestamp int64) *model.AppError
UpdateThreadReadForUser(userId, teamId, threadId string, timestamp int64) *model.AppError
UpdateThreadsReadForUser(userId, teamId string) *model.AppError
UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError)
UpdateUserActive(userId string, active bool) *model.AppError
UpdateUserAsUser(user *model.User, asAdmin bool) (*model.User, *model.AppError)

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

@@ -8485,7 +8485,7 @@ func (a *OpenTracingAppLayer) GetTermsOfService(id string) (*model.TermsOfServic
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetThreadMembershipsForUser(userId string) ([]*model.ThreadMembership, error) {
func (a *OpenTracingAppLayer) GetThreadMembershipsForUser(userId string, teamId string) ([]*model.ThreadMembership, error) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetThreadMembershipsForUser")
@@ -8497,7 +8497,7 @@ func (a *OpenTracingAppLayer) GetThreadMembershipsForUser(userId string) ([]*mod
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetThreadMembershipsForUser(userId)
resultVar0, resultVar1 := a.app.GetThreadMembershipsForUser(userId, teamId)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@@ -8507,7 +8507,7 @@ func (a *OpenTracingAppLayer) GetThreadMembershipsForUser(userId string) ([]*mod
return resultVar0, resultVar1
}
func (a *OpenTracingAppLayer) GetThreadsForUser(userId string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError) {
func (a *OpenTracingAppLayer) GetThreadsForUser(userId string, teamId string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError) {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetThreadsForUser")
@@ -8519,7 +8519,7 @@ func (a *OpenTracingAppLayer) GetThreadsForUser(userId string, options model.Get
}()
defer span.Finish()
resultVar0, resultVar1 := a.app.GetThreadsForUser(userId, options)
resultVar0, resultVar1 := a.app.GetThreadsForUser(userId, teamId, options)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
@@ -15319,7 +15319,7 @@ func (a *OpenTracingAppLayer) UpdateThreadFollowForUser(userId string, threadId
return resultVar0
}
func (a *OpenTracingAppLayer) UpdateThreadReadForUser(userId string, threadId string, timestamp int64) *model.AppError {
func (a *OpenTracingAppLayer) UpdateThreadReadForUser(userId string, teamId string, threadId string, timestamp int64) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateThreadReadForUser")
@@ -15331,7 +15331,7 @@ func (a *OpenTracingAppLayer) UpdateThreadReadForUser(userId string, threadId st
}()
defer span.Finish()
resultVar0 := a.app.UpdateThreadReadForUser(userId, threadId, timestamp)
resultVar0 := a.app.UpdateThreadReadForUser(userId, teamId, threadId, timestamp)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
@@ -15341,7 +15341,7 @@ func (a *OpenTracingAppLayer) UpdateThreadReadForUser(userId string, threadId st
return resultVar0
}
func (a *OpenTracingAppLayer) UpdateThreadsReadForUser(userId string, timestamp int64) *model.AppError {
func (a *OpenTracingAppLayer) UpdateThreadsReadForUser(userId string, teamId string) *model.AppError {
origCtx := a.ctx
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateThreadsReadForUser")
@@ -15353,7 +15353,7 @@ func (a *OpenTracingAppLayer) UpdateThreadsReadForUser(userId string, timestamp
}()
defer span.Finish()
resultVar0 := a.app.UpdateThreadsReadForUser(userId, timestamp)
resultVar0 := a.app.UpdateThreadsReadForUser(userId, teamId)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))

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

@@ -1538,6 +1538,6 @@ func isPostMention(user *model.User, post *model.Post, keywords map[string][]str
return false
}
func (a *App) GetThreadMembershipsForUser(userId string) ([]*model.ThreadMembership, error) {
return a.Srv().Store.Thread().GetMembershipsForUser(userId)
func (a *App) GetThreadMembershipsForUser(userId, teamId string) ([]*model.ThreadMembership, error) {
return a.Srv().Store.Thread().GetMembershipsForUser(userId, teamId)
}

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

@@ -1892,11 +1892,11 @@ func TestThreadMembership(t *testing.T) {
require.Nil(t, err)
// first user should now be part of the thread since they replied to a post
memberships, err2 := th.App.GetThreadMembershipsForUser(user1.Id)
memberships, err2 := th.App.GetThreadMembershipsForUser(user1.Id, th.BasicTeam.Id)
require.Nil(t, err2)
require.Len(t, memberships, 1)
// second user should also be part of a thread since they were mentioned
memberships, err2 = th.App.GetThreadMembershipsForUser(user2.Id)
memberships, err2 = th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
require.Nil(t, err2)
require.Len(t, memberships, 1)
@@ -1916,7 +1916,7 @@ func TestThreadMembership(t *testing.T) {
require.Nil(t, err)
// first user should now be part of two threads
memberships, err2 = th.App.GetThreadMembershipsForUser(user1.Id)
memberships, err2 = th.App.GetThreadMembershipsForUser(user1.Id, th.BasicTeam.Id)
require.Nil(t, err2)
require.Len(t, memberships, 2)
})

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

@@ -2371,8 +2371,8 @@ func (a *App) ConvertBotToUser(bot *model.Bot, userPatch *model.UserPatch, sysad
return user, nil
}
func (a *App) GetThreadsForUser(userId string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError) {
threads, err := a.Srv().Store.Thread().GetThreadsForUser(userId, options)
func (a *App) GetThreadsForUser(userId, teamId string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError) {
threads, err := a.Srv().Store.Thread().GetThreadsForUser(userId, teamId, options)
if err != nil {
return nil, model.NewAppError("GetThreadsForUser", "app.user.get_threads_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -2383,13 +2383,12 @@ func (a *App) GetThreadsForUser(userId string, options model.GetUserThreadsOpts)
return threads, nil
}
func (a *App) UpdateThreadsReadForUser(userId string, timestamp int64) *model.AppError {
nErr := a.Srv().Store.Thread().MarkAllAsRead(userId, timestamp)
func (a *App) UpdateThreadsReadForUser(userId, teamId string) *model.AppError {
nErr := a.Srv().Store.Thread().MarkAllAsRead(userId, teamId)
if nErr != nil {
return model.NewAppError("UpdateThreadsReadForUser", "app.user.update_threads_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_THREAD_READ_CHANGED, "", "", userId, nil)
message.Add("timestamp", timestamp)
a.Publish(message)
return nil
}
@@ -2406,8 +2405,31 @@ func (a *App) UpdateThreadFollowForUser(userId, threadId string, state bool) *mo
return nil
}
func (a *App) UpdateThreadReadForUser(userId, threadId string, timestamp int64) *model.AppError {
nErr := a.Srv().Store.Thread().MarkAsRead(userId, threadId, timestamp)
func (a *App) UpdateThreadReadForUser(userId, teamId, threadId string, timestamp int64) *model.AppError {
user, err := a.GetUser(userId)
if err != nil {
return err
}
membership, nErr := a.Srv().Store.Thread().GetMembershipForUser(userId, threadId)
if nErr != nil {
return model.NewAppError("UpdateThreadsReadForUser", "app.user.update_threads_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
post, err := a.GetSinglePost(threadId)
if err != nil {
return err
}
membership.UnreadMentions, err = a.countThreadMentions(user, post, teamId, timestamp)
if err != nil {
return err
}
membership.Following = true
_, nErr = a.Srv().Store.Thread().UpdateMembership(membership)
if nErr != nil {
return model.NewAppError("UpdateThreadsReadForUser", "app.user.update_threads_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}
nErr = a.Srv().Store.Thread().MarkAsRead(userId, threadId, timestamp)
if nErr != nil {
return model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, nErr.Error(), http.StatusInternalServerError)
}