mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-55096] Introduce generic StoreResult (#25086)
This commit is contained in:
@@ -1401,18 +1401,18 @@ func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (*
|
||||
}
|
||||
|
||||
func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string) *model.AppError {
|
||||
ihc := make(chan store.StoreResult, 1)
|
||||
ohc := make(chan store.StoreResult, 1)
|
||||
ihc := make(chan store.GenericStoreResult[[]*model.IncomingWebhook], 1)
|
||||
ohc := make(chan store.GenericStoreResult[[]*model.OutgoingWebhook], 1)
|
||||
|
||||
go func() {
|
||||
webhooks, err := a.Srv().Store().Webhook().GetIncomingByChannel(channel.Id)
|
||||
ihc <- store.StoreResult{Data: webhooks, NErr: err}
|
||||
ihc <- store.GenericStoreResult[[]*model.IncomingWebhook]{Data: webhooks, NErr: err}
|
||||
close(ihc)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
outgoingHooks, err := a.Srv().Store().Webhook().GetOutgoingByChannel(channel.Id, -1, -1)
|
||||
ohc <- store.StoreResult{Data: outgoingHooks, NErr: err}
|
||||
ohc <- store.GenericStoreResult[[]*model.OutgoingWebhook]{Data: outgoingHooks, NErr: err}
|
||||
close(ohc)
|
||||
}()
|
||||
|
||||
@@ -1441,9 +1441,6 @@ func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string
|
||||
return model.NewAppError("DeleteChannel", "app.webhooks.get_outgoing_by_channel.app_error", nil, "", http.StatusInternalServerError).Wrap(ohcresult.NErr)
|
||||
}
|
||||
|
||||
incomingHooks := ihcresult.Data.([]*model.IncomingWebhook)
|
||||
outgoingHooks := ohcresult.Data.([]*model.OutgoingWebhook)
|
||||
|
||||
if channel.DeleteAt > 0 {
|
||||
err := model.NewAppError("deleteChannel", "api.channel.delete_channel.deleted.app_error", nil, "", http.StatusBadRequest)
|
||||
return err
|
||||
@@ -1492,14 +1489,14 @@ func (a *App) DeleteChannel(c request.CTX, channel *model.Channel, userID string
|
||||
}
|
||||
|
||||
now := model.GetMillis()
|
||||
for _, hook := range incomingHooks {
|
||||
for _, hook := range ihcresult.Data {
|
||||
if err := a.Srv().Store().Webhook().DeleteIncoming(hook.Id, now); err != nil {
|
||||
c.Logger().Warn("Encountered error deleting incoming webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
||||
}
|
||||
a.Srv().Platform().InvalidateCacheForWebhook(hook.Id)
|
||||
}
|
||||
|
||||
for _, hook := range outgoingHooks {
|
||||
for _, hook := range ohcresult.Data {
|
||||
if err := a.Srv().Store().Webhook().DeleteOutgoing(hook.Id, now); err != nil {
|
||||
c.Logger().Warn("Encountered error deleting outgoing webhook", mlog.String("hook_id", hook.Id), mlog.Err(err))
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/product"
|
||||
)
|
||||
|
||||
// Deprecated: Use GenericStoreResult instead.
|
||||
type StoreResult struct {
|
||||
Data any
|
||||
|
||||
@@ -22,6 +23,15 @@ type StoreResult struct {
|
||||
NErr error
|
||||
}
|
||||
|
||||
// GenericStoreResult is a type safe version of StoreResult.
|
||||
// Once all the code is migrated to use GenericStoreResult, it should be renamed to StoreResult.
|
||||
type GenericStoreResult[T any] struct {
|
||||
Data T
|
||||
|
||||
// NErr a temporary field used by the new code for the AppError migration. This will later become Err when the entire store is migrated.
|
||||
NErr error
|
||||
}
|
||||
|
||||
type Store interface {
|
||||
Team() TeamStore
|
||||
Channel() ChannelStore
|
||||
|
||||
Reference in New Issue
Block a user