From 9da4aba3f2757bcbc2ebec2b1f95b6ef22b21912 Mon Sep 17 00:00:00 2001 From: Jason Mojica Date: Mon, 15 Oct 2018 12:23:46 -0400 Subject: Add SearchChannels plugin api (#9657) --- app/plugin_api.go | 4 ++++ plugin/api.go | 3 +++ plugin/client_rpc_generated.go | 30 ++++++++++++++++++++++++++++++ plugin/plugintest/api.go | 25 +++++++++++++++++++++++++ 4 files changed, 62 insertions(+) diff --git a/app/plugin_api.go b/app/plugin_api.go index 4b2fa0447..f3d588e08 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -245,6 +245,10 @@ func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *mo return api.app.UpdateChannel(channel) } +func (api *PluginAPI) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) { + return api.app.SearchChannels(teamId, term) +} + func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) { // For now, don't allow overriding these via the plugin API. userRequestorId := "" diff --git a/plugin/api.go b/plugin/api.go index 2531bf96a..7034cf3d0 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -134,6 +134,9 @@ type API interface { // UpdateChannel updates a channel. UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) + // SearchChannels returns the channels on a team matching the provided search term. + SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) + // AddChannelMember creates a channel membership for a user. AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go index 1039e254e..b50f422fe 100644 --- a/plugin/client_rpc_generated.go +++ b/plugin/client_rpc_generated.go @@ -1596,6 +1596,36 @@ func (s *apiRPCServer) UpdateChannel(args *Z_UpdateChannelArgs, returns *Z_Updat return nil } +type Z_SearchChannelsArgs struct { + A string + B string +} + +type Z_SearchChannelsReturns struct { + A *model.ChannelList + B *model.AppError +} + +func (g *apiRPCClient) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) { + _args := &Z_SearchChannelsArgs{teamId, term} + _returns := &Z_SearchChannelsReturns{} + if err := g.client.Call("Plugin.SearchChannels", _args, _returns); err != nil { + log.Printf("RPC call to SearchChannels API failed: %s", err.Error()) + } + return _returns.A, _returns.B +} + +func (s *apiRPCServer) SearchChannels(args *Z_SearchChannelsArgs, returns *Z_SearchChannelsReturns) error { + if hook, ok := s.impl.(interface { + SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) + }); ok { + returns.A, returns.B = hook.SearchChannels(args.A, args.B) + } else { + return encodableError(fmt.Errorf("API SearchChannels called but not implemented.")) + } + return nil +} + type Z_AddChannelMemberArgs struct { A string B string diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go index 64fc55c31..9040f994e 100644 --- a/plugin/plugintest/api.go +++ b/plugin/plugintest/api.go @@ -1316,6 +1316,31 @@ func (_m *API) SaveConfig(config *model.Config) *model.AppError { return r0 } +// SearchChannels provides a mock function with given fields: teamId, term +func (_m *API) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) { + ret := _m.Called(teamId, term) + + var r0 *model.ChannelList + if rf, ok := ret.Get(0).(func(string, string) *model.ChannelList); ok { + r0 = rf(teamId, term) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ChannelList) + } + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + r1 = rf(teamId, term) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 +} + // SendEphemeralPost provides a mock function with given fields: userId, post func (_m *API) SendEphemeralPost(userId string, post *model.Post) *model.Post { ret := _m.Called(userId, post) -- cgit v1.2.3-1-g7c22