MM-35298: Follow thread when added to channel (#19311)
* MM-35298: Follow thread when added to channel * return better error if thread doesn't exist * update test for possible race * use correct comparision operator
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e2e049e05e
Коммит
7026818f80
@@ -1063,6 +1063,7 @@ type AppIface interface {
|
||||
UpdateTeamPrivacy(teamID string, teamType string, allowOpenInvite bool) *model.AppError
|
||||
UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError)
|
||||
UpdateThreadFollowForUser(userID, teamID, threadID string, state bool) *model.AppError
|
||||
UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID string) *model.AppError
|
||||
UpdateThreadReadForUser(currentSessionId, userID, teamID, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError)
|
||||
UpdateThreadsReadForUser(userID, teamID string) *model.AppError
|
||||
UpdateUser(user *model.User, sendNotifications bool) (*model.User, *model.AppError)
|
||||
|
||||
@@ -16634,6 +16634,28 @@ func (a *OpenTracingAppLayer) UpdateThreadFollowForUser(userID string, teamID st
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateThreadFollowForUserFromChannelAdd(userID string, teamID string, threadID string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateThreadFollowForUserFromChannelAdd")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateThreadReadForUser(currentSessionId string, userID string, teamID string, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateThreadReadForUser")
|
||||
|
||||
58
app/user.go
58
app/user.go
@@ -2301,6 +2301,64 @@ func (a *App) UpdateThreadFollowForUser(userID, teamID, threadID string, state b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID string) *model.AppError {
|
||||
opts := store.ThreadMembershipOpts{
|
||||
Following: true,
|
||||
IncrementMentions: false,
|
||||
UpdateFollowing: true,
|
||||
UpdateViewedTimestamp: false,
|
||||
UpdateParticipants: false,
|
||||
}
|
||||
tm, err := a.Srv().Store.Thread().MaintainMembership(userID, threadID, opts)
|
||||
if err != nil {
|
||||
return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
post, appErr := a.GetSinglePost(threadID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
user, appErr := a.GetUser(userID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
tm.UnreadMentions, appErr = a.countThreadMentions(user, post, teamID, post.CreateAt-1)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
tm.LastViewed = post.CreateAt - 1
|
||||
_, err = a.Srv().Store.Thread().UpdateMembership(tm)
|
||||
if err != nil {
|
||||
return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, teamID, "", userID, nil)
|
||||
userThread, err := a.Srv().Store.Thread().GetThreadForUser(teamID, tm, true)
|
||||
if err != nil {
|
||||
var errNotFound *store.ErrNotFound
|
||||
if errors.As(err, &errNotFound) {
|
||||
return nil
|
||||
}
|
||||
return model.NewAppError("UpdateThreadFollowForUserFromChannelAdd", "app.user.update_thread_follow_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
a.sanitizeProfiles(userThread.Participants, false)
|
||||
userThread.Post.SanitizeProps()
|
||||
sanitizedPost, appErr := a.SanitizePostMetadataForUser(userThread.Post, userID)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
userThread.Post = sanitizedPost
|
||||
|
||||
payload, jsonErr := json.Marshal(userThread)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode thread to JSON")
|
||||
}
|
||||
message.Add("thread", string(payload))
|
||||
|
||||
a.Publish(message)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateThreadReadForUser(currentSessionId, userID, teamID, threadID string, timestamp int64) (*model.ThreadResponse, *model.AppError) {
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user