Add preferences service API for products (#20869)
Этот коммит содержится в:
@@ -226,6 +226,10 @@ func NewChannels(s *Server, services map[ServiceKey]any) (*Channels, error) {
|
|||||||
|
|
||||||
services[UserKey] = &App{ch: ch}
|
services[UserKey] = &App{ch: ch}
|
||||||
|
|
||||||
|
services[PreferencesKey] = &preferencesServiceWrapper{
|
||||||
|
app: &App{ch: ch},
|
||||||
|
}
|
||||||
|
|
||||||
return ch, nil
|
return ch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,29 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/product"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Ensure preferences service wrapper implements `product.PreferencesService`
|
||||||
|
var _ product.PreferencesService = (*preferencesServiceWrapper)(nil)
|
||||||
|
|
||||||
|
// preferencesServiceWrapper provides an implementation of `product.PreferencesService` for use by products.
|
||||||
|
type preferencesServiceWrapper struct {
|
||||||
|
app AppIface
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *preferencesServiceWrapper) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) {
|
||||||
|
return w.app.GetPreferencesForUser(userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *preferencesServiceWrapper) UpdatePreferencesForUser(userID string, preferences model.Preferences) *model.AppError {
|
||||||
|
return w.app.UpdatePreferences(userID, preferences)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *preferencesServiceWrapper) DeletePreferencesForUser(userID string, preferences model.Preferences) *model.AppError {
|
||||||
|
return w.app.DeletePreferences(userID, preferences)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) {
|
func (a *App) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) {
|
||||||
preferences, err := a.Srv().Store.Preference().GetAll(userID)
|
preferences, err := a.Srv().Store.Preference().GetAll(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ const (
|
|||||||
KVStoreKey ServiceKey = "kvstore"
|
KVStoreKey ServiceKey = "kvstore"
|
||||||
StoreKey ServiceKey = "storekey"
|
StoreKey ServiceKey = "storekey"
|
||||||
SystemKey ServiceKey = "systemkey"
|
SystemKey ServiceKey = "systemkey"
|
||||||
|
PreferencesKey ServiceKey = "preferenceskey"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|||||||
@@ -179,3 +179,12 @@ type StoreService interface {
|
|||||||
type SystemService interface {
|
type SystemService interface {
|
||||||
GetDiagnosticId() string
|
GetDiagnosticId() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PreferencesService is the API for accessing the Preferences service APIs.
|
||||||
|
//
|
||||||
|
// The service shall be registered via app.PreferencesKey service key.
|
||||||
|
type PreferencesService interface {
|
||||||
|
GetPreferencesForUser(userID string) (model.Preferences, *model.AppError)
|
||||||
|
UpdatePreferencesForUser(userID string, preferences model.Preferences) *model.AppError
|
||||||
|
DeletePreferencesForUser(userID string, preferences model.Preferences) *model.AppError
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user