app: add channels wrapper (#19861)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
6da1d90c4a
Коммит
54cb6d889f
@@ -21,6 +21,24 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/utils"
|
"github.com/mattermost/mattermost-server/v6/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type channelsWrapper struct {
|
||||||
|
srv *Server
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *channelsWrapper) GetDirectChannel(userID1, userID2 string) (*model.Channel, error) {
|
||||||
|
return s.srv.getDirectChannel(userID1, userID2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChannelByID gets a Channel by its ID.
|
||||||
|
func (s *channelsWrapper) GetChannelByID(channelID string) (*model.Channel, error) {
|
||||||
|
return s.srv.getChannel(channelID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetChannelMember gets a channel member by userID.
|
||||||
|
func (s *channelsWrapper) GetChannelMember(channelID string, userID string) (*model.ChannelMember, error) {
|
||||||
|
return s.srv.getChannelMember(context.Background(), channelID, userID)
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultChannelNames returns the list of system-wide default channel names.
|
// DefaultChannelNames returns the list of system-wide default channel names.
|
||||||
//
|
//
|
||||||
// By default the list will be (not necessarily in this order):
|
// By default the list will be (not necessarily in this order):
|
||||||
@@ -1701,7 +1719,11 @@ func (a *App) PostUpdateChannelDisplayNameMessage(c *request.Context, userID str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannel(channelID string) (*model.Channel, *model.AppError) {
|
func (a *App) GetChannel(channelID string) (*model.Channel, *model.AppError) {
|
||||||
channel, err := a.Srv().Store.Channel().Get(channelID, true)
|
return a.Srv().getChannel(channelID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) getChannel(channelID string) (*model.Channel, *model.AppError) {
|
||||||
|
channel, err := s.Store.Channel().Get(channelID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -1919,7 +1941,11 @@ func (a *App) GetPrivateChannelsForTeam(teamID string, offset int, limit int) (m
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
func (a *App) GetChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
channelMember, err := a.Srv().Store.Channel().GetMember(ctx, channelID, userID)
|
return a.Srv().getChannelMember(ctx, channelID, userID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) getChannelMember(ctx context.Context, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
|
||||||
|
channelMember, err := s.Store.Channel().GetMember(ctx, channelID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
switch {
|
switch {
|
||||||
@@ -3383,7 +3409,11 @@ func (a *App) GetMemberCountsByGroup(ctx context.Context, channelID string, incl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) getDirectChannel(userID, otherUserID string) (*model.Channel, *model.AppError) {
|
func (a *App) getDirectChannel(userID, otherUserID string) (*model.Channel, *model.AppError) {
|
||||||
channel, nErr := a.Srv().Store.Channel().GetByName("", model.GetDMNameFromIds(userID, otherUserID), true)
|
return a.Srv().getDirectChannel(userID, otherUserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) getDirectChannel(userID, otherUserID string) (*model.Channel, *model.AppError) {
|
||||||
|
channel, nErr := s.Store.Channel().GetByName("", model.GetDMNameFromIds(userID, otherUserID), true)
|
||||||
if nErr != nil {
|
if nErr != nil {
|
||||||
var nfErr *store.ErrNotFound
|
var nfErr *store.ErrNotFound
|
||||||
if errors.As(nErr, &nfErr) {
|
if errors.As(nErr, &nfErr) {
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ var SentryDSN = "placeholder_sentry_dsn"
|
|||||||
type ServiceKey string
|
type ServiceKey string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
ChannelKey ServiceKey = "channel"
|
||||||
ConfigKey ServiceKey = "config"
|
ConfigKey ServiceKey = "config"
|
||||||
LicenseKey ServiceKey = "license"
|
LicenseKey ServiceKey = "license"
|
||||||
FilestoreKey ServiceKey = "filestore"
|
FilestoreKey ServiceKey = "filestore"
|
||||||
@@ -363,6 +364,10 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
}
|
}
|
||||||
s.filestore = backend
|
s.filestore = backend
|
||||||
|
|
||||||
|
channelWrapper := &channelsWrapper{
|
||||||
|
srv: s,
|
||||||
|
}
|
||||||
|
|
||||||
s.licenseWrapper = &licenseWrapper{
|
s.licenseWrapper = &licenseWrapper{
|
||||||
srv: s,
|
srv: s,
|
||||||
}
|
}
|
||||||
@@ -385,6 +390,7 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serviceMap := map[ServiceKey]interface{}{
|
serviceMap := map[ServiceKey]interface{}{
|
||||||
|
ChannelKey: channelWrapper,
|
||||||
ConfigKey: s.configStore,
|
ConfigKey: s.configStore,
|
||||||
LicenseKey: s.licenseWrapper,
|
LicenseKey: s.licenseWrapper,
|
||||||
FilestoreKey: s.filestore,
|
FilestoreKey: s.filestore,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user