add GetDirectChannelOrCreate to product API (#22112)

Этот коммит содержится в:
Doug Lauder
2023-01-20 07:51:44 -05:00
коммит произвёл GitHub
родитель 51e5c9b36c
Коммит 3c1f63d41b
4 изменённых файлов: 15 добавлений и 2 удалений

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

@@ -13,6 +13,7 @@ import (
"time" "time"
"github.com/mattermost/logr/v2" "github.com/mattermost/logr/v2"
"github.com/mattermost/mattermost-server/v6/app/request" "github.com/mattermost/mattermost-server/v6/app/request"
"github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin" "github.com/mattermost/mattermost-server/v6/plugin"
@@ -27,6 +28,7 @@ import (
// channelsWrapper provides an implementation of `product.ChannelService` to be used by products. // channelsWrapper provides an implementation of `product.ChannelService` to be used by products.
type channelsWrapper struct { type channelsWrapper struct {
srv *Server srv *Server
app *App
} }
func (s *channelsWrapper) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) { func (s *channelsWrapper) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) {
@@ -47,6 +49,10 @@ func (s *channelsWrapper) GetChannelsForTeamForUser(teamID string, userID string
return s.srv.getChannelsForTeamForUser(request.EmptyContext(s.srv.Log()), teamID, userID, opts) return s.srv.getChannelsForTeamForUser(request.EmptyContext(s.srv.Log()), teamID, userID, opts)
} }
func (s *channelsWrapper) GetDirectChannelOrCreate(userID1, userID2 string) (*model.Channel, *model.AppError) {
return s.app.GetOrCreateDirectChannel(request.EmptyContext(s.srv.Log()), userID1, userID2)
}
// Ensure the wrapper implements the product service. // Ensure the wrapper implements the product service.
var _ product.ChannelService = (*channelsWrapper)(nil) var _ product.ChannelService = (*channelsWrapper)(nil)

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

@@ -213,6 +213,11 @@ func NewChannels(services map[product.ServiceKey]any) (*Channels, error) {
pluginsRoute.HandleFunc("/public/{public_file:.*}", ch.ServePluginPublicRequest) pluginsRoute.HandleFunc("/public/{public_file:.*}", ch.ServePluginPublicRequest)
pluginsRoute.HandleFunc("/{anything:.*}", ch.ServePluginRequest) pluginsRoute.HandleFunc("/{anything:.*}", ch.ServePluginRequest)
services[product.ChannelKey] = &channelsWrapper{
srv: s,
app: &App{ch: ch},
}
services[product.PostKey] = &postServiceWrapper{ services[product.PostKey] = &postServiceWrapper{
app: &App{ch: ch}, app: &App{ch: ch},
} }

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

@@ -238,15 +238,16 @@ func NewServer(options ...Option) (*Server, error) {
// ensure app implements `product.UserService` // ensure app implements `product.UserService`
var _ product.UserService = (*App)(nil) var _ product.UserService = (*App)(nil)
app := New(ServerConnector(s.Channels()))
serviceMap := map[product.ServiceKey]any{ serviceMap := map[product.ServiceKey]any{
ServerKey: s, ServerKey: s,
product.ChannelKey: &channelsWrapper{srv: s}, product.ChannelKey: &channelsWrapper{srv: s, app: app},
product.ConfigKey: s.platform, product.ConfigKey: s.platform,
product.LicenseKey: s.licenseWrapper, product.LicenseKey: s.licenseWrapper,
product.FilestoreKey: s.platform.FileBackend(), product.FilestoreKey: s.platform.FileBackend(),
product.FileInfoStoreKey: &fileInfoWrapper{srv: s}, product.FileInfoStoreKey: &fileInfoWrapper{srv: s},
product.ClusterKey: s.platform, product.ClusterKey: s.platform,
product.UserKey: New(ServerConnector(s.Channels())), product.UserKey: app,
product.LogKey: s.platform.Log(), product.LogKey: s.platform.Log(),
product.CloudKey: &cloudWrapper{cloud: s.Cloud}, product.CloudKey: &cloudWrapper{cloud: s.Cloud},
product.KVStoreKey: s.platform, product.KVStoreKey: s.platform,

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

@@ -62,6 +62,7 @@ type ClusterService interface {
// The service shall be registered via app.ChannelKey service key. // The service shall be registered via app.ChannelKey service key.
type ChannelService interface { type ChannelService interface {
GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError)
GetDirectChannelOrCreate(userID1, userID2 string) (*model.Channel, *model.AppError)
GetChannelByID(channelID string) (*model.Channel, *model.AppError) GetChannelByID(channelID string) (*model.Channel, *model.AppError)
GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError) GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError)
GetChannelsForTeamForUser(teamID string, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, *model.AppError) GetChannelsForTeamForUser(teamID string, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, *model.AppError)