summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hodan <daniel.hodan@czertbytes.de>2018-10-17 23:06:14 +0200
committerJesse Hallam <jesse.hallam@gmail.com>2018-10-17 17:06:14 -0400
commit77f3da1eaf5b7ca7d53fd324e3c669ed4f87003e (patch)
tree9b6496d5fed9f2b765cce24b60a47eda7482f8b5
parent819ab451f1806db640698f8e0513a7269f32c307 (diff)
downloadchat-77f3da1eaf5b7ca7d53fd324e3c669ed4f87003e.tar.gz
chat-77f3da1eaf5b7ca7d53fd324e3c669ed4f87003e.tar.bz2
chat-77f3da1eaf5b7ca7d53fd324e3c669ed4f87003e.zip
GH-9608: Add GetUsersInChannel to plugin API (#9643)
* add GetUsersInChannel to plugin api * compute offset value instead of page * Add version comment
-rw-r--r--app/plugin_api.go4
-rw-r--r--plugin/api.go5
-rw-r--r--plugin/client_rpc_generated.go31
-rw-r--r--plugin/plugintest/api.go25
4 files changed, 65 insertions, 0 deletions
diff --git a/app/plugin_api.go b/app/plugin_api.go
index 85bcc0660..3574c0298 100644
--- a/app/plugin_api.go
+++ b/app/plugin_api.go
@@ -294,6 +294,10 @@ func (api *PluginAPI) DeleteChannelMember(channelId, userId string) *model.AppEr
return api.app.LeaveChannel(channelId, userId)
}
+func (api *PluginAPI) GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError) {
+ return api.app.GetUsersInChannel(channelId, page*perPage, perPage)
+}
+
func (api *PluginAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
return api.app.CreatePostMissingChannel(post, true)
}
diff --git a/plugin/api.go b/plugin/api.go
index c2429538d..186e74e44 100644
--- a/plugin/api.go
+++ b/plugin/api.go
@@ -176,6 +176,11 @@ type API interface {
// DeleteChannelMember deletes a channel membership for a user.
DeleteChannelMember(channelId, userId string) *model.AppError
+ // GetUsersInChannel gets users in given channel.
+ //
+ // Minimum server version: 5.6
+ GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError)
+
// CreatePost creates a post.
CreatePost(post *model.Post) (*model.Post, *model.AppError)
diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go
index 5c14f4d4a..f7db87e2e 100644
--- a/plugin/client_rpc_generated.go
+++ b/plugin/client_rpc_generated.go
@@ -1899,6 +1899,37 @@ func (s *apiRPCServer) DeleteChannelMember(args *Z_DeleteChannelMemberArgs, retu
return nil
}
+type Z_GetUsersInChannelArgs struct {
+ A string
+ B int
+ C int
+}
+
+type Z_GetUsersInChannelReturns struct {
+ A []*model.User
+ B *model.AppError
+}
+
+func (g *apiRPCClient) GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError) {
+ _args := &Z_GetUsersInChannelArgs{channelId, page, perPage}
+ _returns := &Z_GetUsersInChannelReturns{}
+ if err := g.client.Call("Plugin.GetUsersInChannel", _args, _returns); err != nil {
+ log.Printf("RPC call to GetUsersInChannel API failed: %s", err.Error())
+ }
+ return _returns.A, _returns.B
+}
+
+func (s *apiRPCServer) GetUsersInChannel(args *Z_GetUsersInChannelArgs, returns *Z_GetUsersInChannelReturns) error {
+ if hook, ok := s.impl.(interface {
+ GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError)
+ }); ok {
+ returns.A, returns.B = hook.GetUsersInChannel(args.A, args.B, args.C)
+ } else {
+ return encodableError(fmt.Errorf("API GetUsersInChannel called but not implemented."))
+ }
+ return nil
+}
+
type Z_CreatePostArgs struct {
A *model.Post
}
diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go
index 066cdfa7e..0fe2ab0ea 100644
--- a/plugin/plugintest/api.go
+++ b/plugin/plugintest/api.go
@@ -1163,6 +1163,31 @@ func (_m *API) GetUsersInTeam(teamId string, page int, perPage int) ([]*model.Us
return r0, r1
}
+// GetUsersInChannel provides a mock function with given fields: channelId, page, perPage
+func (_m *API) GetUsersInChannel(channelId string, page int, perPage int) ([]*model.User, *model.AppError) {
+ ret := _m.Called(channelId, page, perPage)
+
+ var r0 []*model.User
+ if rf, ok := ret.Get(0).(func(string, int, int) []*model.User); ok {
+ r0 = rf(channelId, page, perPage)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*model.User)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok {
+ r1 = rf(channelId, page, perPage)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
+
// HasPermissionTo provides a mock function with given fields: userId, permission
func (_m *API) HasPermissionTo(userId string, permission *model.Permission) bool {
ret := _m.Called(userId, permission)