Skip to content

Commit

Permalink
Mm 55298 generic integration action (mattermost#25320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Stern authored Nov 7, 2023
1 parent f8f50ca commit 9596c46
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions server/channels/app/integration_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,24 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se

// See if the post exists in the DB, if so ignore the cookie.
// Start all queries here for parallel execution
pchan := make(chan store.StoreResult, 1)
pchan := make(chan store.GenericStoreResult[*model.Post], 1)
go func() {
post, err := a.Srv().Store().Post().GetSingle(postID, false)
pchan <- store.StoreResult{Data: post, NErr: err}
pchan <- store.GenericStoreResult[*model.Post]{Data: post, NErr: err}
close(pchan)
}()

cchan := make(chan store.StoreResult, 1)
cchan := make(chan store.GenericStoreResult[*model.Channel], 1)
go func() {
channel, err := a.Srv().Store().Channel().GetForPost(postID)
cchan <- store.StoreResult{Data: channel, NErr: err}
cchan <- store.GenericStoreResult[*model.Channel]{Data: channel, NErr: err}
close(cchan)
}()

userChan := make(chan store.StoreResult, 1)
userChan := make(chan store.GenericStoreResult[*model.User], 1)
go func() {
user, err := a.Srv().Store().User().Get(context.Background(), upstreamRequest.UserId)
userChan <- store.StoreResult{Data: user, NErr: err}
userChan <- store.GenericStoreResult[*model.User]{Data: user, NErr: err}
close(userChan)
}()

Expand Down Expand Up @@ -133,12 +133,12 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
rootPostId = cookie.RootPostId
upstreamURL = cookie.Integration.URL
} else {
post := result.Data.(*model.Post)
result = <-cchan
if result.NErr != nil {
post := result.Data
chResult := <-cchan
if chResult.NErr != nil {
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr)
}
channel := result.Data.(*model.Channel)
channel := chResult.Data

action := post.GetAction(actionId)
if action == nil || action.Integration == nil {
Expand Down Expand Up @@ -175,7 +175,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
upstreamURL = action.Integration.URL
}

teamChan := make(chan store.StoreResult, 1)
teamChan := make(chan store.GenericStoreResult[*model.Team], 1)

go func() {
defer close(teamChan)
Expand All @@ -186,7 +186,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
}

team, err := a.Srv().Store().Team().Get(upstreamRequest.TeamId)
teamChan <- store.StoreResult{Data: team, NErr: err}
teamChan <- store.GenericStoreResult[*model.Team]{Data: team, NErr: err}
}()

ur := <-userChan
Expand All @@ -199,7 +199,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
return "", model.NewAppError("DoPostActionWithCookie", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(ur.NErr)
}
}
user := ur.Data.(*model.User)
user := ur.Data
upstreamRequest.UserName = user.Username

tr, ok := <-teamChan
Expand All @@ -214,7 +214,7 @@ func (a *App) DoPostActionWithCookie(c request.CTX, postID, actionId, userID, se
}
}

team := tr.Data.(*model.Team)
team := tr.Data
upstreamRequest.TeamName = team.Name
}

Expand Down

0 comments on commit 9596c46

Please sign in to comment.