summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Mojica <jason@jasonmojica.net>2018-10-25 17:24:43 +0000
committerJesse Hallam <jesse.hallam@gmail.com>2018-10-25 13:24:43 -0400
commit1074a1c7ab0769b0da3525282fcabf961e2ddfce (patch)
tree4fc4f2701ccc6dc4f40c22f604e6581a168aa9d0
parentdd60ad0db76a00a92d25d7923bf8fb54ebf4a531 (diff)
downloadchat-1074a1c7ab0769b0da3525282fcabf961e2ddfce.tar.gz
chat-1074a1c7ab0769b0da3525282fcabf961e2ddfce.tar.bz2
chat-1074a1c7ab0769b0da3525282fcabf961e2ddfce.zip
GH-9612 Add plugin API for GetChannelStats method (#9627)
* Add GetChannelStats plugin api * Fix to return channel stats correctly * Add server version; Handle error idiomatically
-rw-r--r--app/plugin_api.go8
-rw-r--r--plugin/api.go5
-rw-r--r--plugin/client_rpc_generated.go29
-rw-r--r--plugin/plugintest/api.go25
4 files changed, 67 insertions, 0 deletions
diff --git a/app/plugin_api.go b/app/plugin_api.go
index c409a88f8..a07a07652 100644
--- a/app/plugin_api.go
+++ b/app/plugin_api.go
@@ -261,6 +261,14 @@ func (api *PluginAPI) GetChannelsForTeamForUser(teamId, userId string, includeDe
return api.app.GetChannelsForUser(teamId, userId, includeDeleted)
}
+func (api *PluginAPI) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
+ memberCount, err := api.app.GetChannelMemberCount(channelId)
+ if err != nil {
+ return nil, err
+ }
+ return &model.ChannelStats{ChannelId: channelId, MemberCount: memberCount}, nil
+}
+
func (api *PluginAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) {
return api.app.GetDirectChannel(userId1, userId2)
}
diff --git a/plugin/api.go b/plugin/api.go
index 93b5a6d2e..f1b9ec01f 100644
--- a/plugin/api.go
+++ b/plugin/api.go
@@ -155,6 +155,11 @@ type API interface {
// Minimum server version: 5.6
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
+ // GetChannelStats gets statistics for a channel.
+ //
+ // Minimum server version: 5.6
+ GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError)
+
// GetDirectChannel gets a direct message channel.
GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)
diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go
index b3886dcb3..81469a20f 100644
--- a/plugin/client_rpc_generated.go
+++ b/plugin/client_rpc_generated.go
@@ -1660,6 +1660,35 @@ func (s *apiRPCServer) GetChannelsForTeamForUser(args *Z_GetChannelsForTeamForUs
return nil
}
+type Z_GetChannelStatsArgs struct {
+ A string
+}
+
+type Z_GetChannelStatsReturns struct {
+ A *model.ChannelStats
+ B *model.AppError
+}
+
+func (g *apiRPCClient) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
+ _args := &Z_GetChannelStatsArgs{channelId}
+ _returns := &Z_GetChannelStatsReturns{}
+ if err := g.client.Call("Plugin.GetChannelStats", _args, _returns); err != nil {
+ log.Printf("RPC call to GetChannelStats API failed: %s", err.Error())
+ }
+ return _returns.A, _returns.B
+}
+
+func (s *apiRPCServer) GetChannelStats(args *Z_GetChannelStatsArgs, returns *Z_GetChannelStatsReturns) error {
+ if hook, ok := s.impl.(interface {
+ GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError)
+ }); ok {
+ returns.A, returns.B = hook.GetChannelStats(args.A)
+ } else {
+ return encodableError(fmt.Errorf("API GetChannelStats called but not implemented."))
+ }
+ return nil
+}
+
type Z_GetDirectChannelArgs struct {
A string
B string
diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go
index 81462e58d..d24b955ae 100644
--- a/plugin/plugintest/api.go
+++ b/plugin/plugintest/api.go
@@ -483,6 +483,31 @@ func (_m *API) GetChannelsForTeamForUser(teamId string, userId string, includeDe
return r0, r1
}
+// GetChannelStats provides a mock function with given fields: channelId
+func (_m *API) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
+ ret := _m.Called(channelId)
+
+ var r0 *model.ChannelStats
+ if rf, ok := ret.Get(0).(func(string) *model.ChannelStats); ok {
+ r0 = rf(channelId)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*model.ChannelStats)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
+ r1 = rf(channelId)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
+
// GetConfig provides a mock function with given fields:
func (_m *API) GetConfig() *model.Config {
ret := _m.Called()