From a83728bca2b77da6978c857b42478529c583ffba Mon Sep 17 00:00:00 2001 From: Giorgi Bochorishvili Date: Fri, 20 Jan 2023 14:48:10 +0400 Subject: [PATCH] Address review comments Switch channel to always use app Remove channel wrapper init from server --- app/channel.go | 29 ++++++++++++++--------------- app/channels.go | 1 - app/server.go | 1 - shared/i18n/i18n.go | 13 +++++++------ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/channel.go b/app/channel.go index d4f67ab3d3..80877f1e93 100644 --- a/app/channel.go +++ b/app/channel.go @@ -26,50 +26,49 @@ import ( // channelsWrapper provides an implementation of `product.ChannelService` to be used by products. type channelsWrapper struct { - srv *Server app *App } func (s *channelsWrapper) GetDirectChannel(userID1, userID2 string) (*model.Channel, *model.AppError) { - return s.srv.getDirectChannel(request.EmptyContext(s.srv.Log()), userID1, userID2) + return s.app.getDirectChannel(request.EmptyContext(s.app.Log()), userID1, userID2) } // GetChannelByID gets a Channel by its ID. func (s *channelsWrapper) GetChannelByID(channelID string) (*model.Channel, *model.AppError) { - return s.srv.getChannel(request.EmptyContext(s.srv.Log()), channelID) + return s.app.GetChannel(request.EmptyContext(s.app.Log()), channelID) } // GetChannelMember gets a channel member by userID. func (s *channelsWrapper) GetChannelMember(channelID string, userID string) (*model.ChannelMember, *model.AppError) { - return s.srv.getChannelMember(request.EmptyContext(s.srv.Log()), channelID, userID) + return s.app.GetChannelMember(request.EmptyContext(s.app.Log()), channelID, userID) } func (s *channelsWrapper) GetChannelsForTeamForUser(teamID string, userID string, opts *model.ChannelSearchOpts) (model.ChannelList, *model.AppError) { - return s.srv.getChannelsForTeamForUser(request.EmptyContext(s.srv.Log()), teamID, userID, opts) + return s.app.GetChannelsForTeamForUser(request.EmptyContext(s.app.Log()), teamID, userID, opts) } func (s *channelsWrapper) GetChannelSidebarCategories(userID, teamID string) (*model.OrderedSidebarCategories, *model.AppError) { - return s.app.GetSidebarCategoriesForTeamForUser(request.EmptyContext(s.srv.Log()), userID, teamID) + return s.app.GetSidebarCategoriesForTeamForUser(request.EmptyContext(s.app.Log()), userID, teamID) } func (s *channelsWrapper) GetChannelMembers(channelID string, page, perPage int) (model.ChannelMembers, *model.AppError) { - return s.app.GetChannelMembersPage(request.EmptyContext(s.srv.Log()), channelID, page, perPage) + return s.app.GetChannelMembersPage(request.EmptyContext(s.app.Log()), channelID, page, perPage) } func (s *channelsWrapper) CreateChannelSidebarCategory(userID, teamID string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) { - return s.app.CreateSidebarCategory(request.EmptyContext(s.srv.Log()), userID, teamID, newCategory) + return s.app.CreateSidebarCategory(request.EmptyContext(s.app.Log()), userID, teamID, newCategory) } func (s *channelsWrapper) UpdateChannelSidebarCategories(userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) { - return s.app.UpdateSidebarCategories(request.EmptyContext(s.srv.Log()), userID, teamID, categories) + return s.app.UpdateSidebarCategories(request.EmptyContext(s.app.Log()), userID, teamID, categories) } func (s *channelsWrapper) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) { - return s.app.CreateChannel(request.EmptyContext(s.srv.Log()), channel, false) + return s.app.CreateChannel(request.EmptyContext(s.app.Log()), channel, false) } func (s *channelsWrapper) AddUserToChannel(channelID, userID, asUserID string) (*model.ChannelMember, *model.AppError) { - ctx := request.EmptyContext(s.srv.Log()) + ctx := request.EmptyContext(s.app.Log()) channel, err := s.app.GetChannel(ctx, channelID) if err != nil { return nil, err @@ -81,11 +80,11 @@ func (s *channelsWrapper) AddUserToChannel(channelID, userID, asUserID string) ( } func (s *channelsWrapper) UpdateChannelMemberRoles(channelID, userID, newRoles string) (*model.ChannelMember, *model.AppError) { - return s.app.UpdateChannelMemberRoles(request.EmptyContext(s.srv.Log()), channelID, userID, newRoles) + return s.app.UpdateChannelMemberRoles(request.EmptyContext(s.app.Log()), channelID, userID, newRoles) } func (s *channelsWrapper) DeleteChannelMember(channelID, userID string) *model.AppError { - return s.app.LeaveChannel(request.EmptyContext(s.srv.Log()), channelID, userID) + return s.app.LeaveChannel(request.EmptyContext(s.app.Log()), channelID, userID) } func (s *channelsWrapper) AddChannelMember(channelID, userID string) (*model.ChannelMember, *model.AppError) { @@ -94,7 +93,7 @@ func (s *channelsWrapper) AddChannelMember(channelID, userID string) (*model.Cha return nil, err } - return s.app.AddChannelMember(request.EmptyContext(s.srv.Log()), userID, channel, ChannelMemberOpts{ + return s.app.AddChannelMember(request.EmptyContext(s.app.Log()), userID, channel, ChannelMemberOpts{ // For now, don't allow overriding these via the plugin API. UserRequestorID: "", PostRootID: "", @@ -102,7 +101,7 @@ func (s *channelsWrapper) AddChannelMember(channelID, userID string) (*model.Cha } func (s *channelsWrapper) GetDirectChannelOrCreate(userID1, userID2 string) (*model.Channel, *model.AppError) { - return s.app.GetOrCreateDirectChannel(request.EmptyContext(s.srv.Log()), userID1, userID2) + return s.app.GetOrCreateDirectChannel(request.EmptyContext(s.app.Log()), userID1, userID2) } // Ensure the wrapper implements the product service. diff --git a/app/channels.go b/app/channels.go index b22bfda2d0..470493ec60 100644 --- a/app/channels.go +++ b/app/channels.go @@ -214,7 +214,6 @@ func NewChannels(services map[product.ServiceKey]any) (*Channels, error) { pluginsRoute.HandleFunc("/{anything:.*}", ch.ServePluginRequest) services[product.ChannelKey] = &channelsWrapper{ - srv: s, app: &App{ch: ch}, } diff --git a/app/server.go b/app/server.go index 46f0b7f6a7..8358ef4986 100644 --- a/app/server.go +++ b/app/server.go @@ -241,7 +241,6 @@ func NewServer(options ...Option) (*Server, error) { app := New(ServerConnector(s.Channels())) serviceMap := map[product.ServiceKey]any{ ServerKey: s, - product.ChannelKey: &channelsWrapper{srv: s, app: app}, product.ConfigKey: s.platform, product.LicenseKey: s.licenseWrapper, product.FilestoreKey: s.platform.FileBackend(), diff --git a/shared/i18n/i18n.go b/shared/i18n/i18n.go index 747b7d9e99..1bf063546b 100644 --- a/shared/i18n/i18n.go +++ b/shared/i18n/i18n.go @@ -85,13 +85,14 @@ func GetTranslationFuncForDir(dir string) (TranslationFuncByLocal, error) { bundle := bundle.New() files, _ := os.ReadDir(dir) for _, f := range files { - if filepath.Ext(f.Name()) == ".json" { - filename := f.Name() - availableLocals[strings.Split(filename, ".")[0]] = filepath.Join(dir, filename) + if filepath.Ext(f.Name()) != ".json" { + continue + } - if err := bundle.LoadTranslationFile(filepath.Join(dir, filename)); err != nil { - return nil, err - } + filename := f.Name() + availableLocals[strings.Split(filename, ".")[0]] = filepath.Join(dir, filename) + if err := bundle.LoadTranslationFile(filepath.Join(dir, filename)); err != nil { + return nil, err } }