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
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
dd60ad0db7
Коммит
1074a1c7ab
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Ссылка в новой задаче
Block a user