[MM-34076] Add Plugin API User custom status (#17435)

* add missing client for custom user status

* add custom user status plugin api

* update based on feedback review

* add GetCustomStatus

* update interfaces
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2021-11-10 17:11:20 +01:00
коммит произвёл GitHub
родитель 0a3e7f4d55
Коммит bb5a74a42b
13 изменённых файлов: 290 добавлений и 4 удалений

Просмотреть файл

@@ -257,6 +257,19 @@ type API interface {
// Minimum server version: 5.8
UpdateUserActive(userID string, active bool) *model.AppError
// UpdateUserCustomStatus will set a user's custom status until the user, or another integration/plugin, clear it or update the custom status.
// The custom status have two parameters: emoji icon and custom text.
//
// @tag User
// Minimum server version: 5.36
UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError
// RemoveUserCustomStatus will remove a user's custom status.
//
// @tag User
// Minimum server version: 5.36
RemoveUserCustomStatus(userID string) *model.AppError
// GetUsersInChannel returns a page of users in a channel. Page counting starts at 0.
// The sortBy parameter can be: "username" or "status".
//

Просмотреть файл

@@ -301,6 +301,20 @@ func (api *apiTimerLayer) UpdateUserActive(userID string, active bool) *model.Ap
return _returnsA
}
func (api *apiTimerLayer) UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError {
startTime := timePkg.Now()
_returnsA := api.apiImpl.UpdateUserCustomStatus(userID, customStatus)
api.recordTime(startTime, "UpdateUserCustomStatus", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) RemoveUserCustomStatus(userID string) *model.AppError {
startTime := timePkg.Now()
_returnsA := api.apiImpl.RemoveUserCustomStatus(userID)
api.recordTime(startTime, "RemoveUserCustomStatus", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) GetUsersInChannel(channelID, sortBy string, page, perPage int) ([]*model.User, *model.AppError) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.GetUsersInChannel(channelID, sortBy, page, perPage)

Просмотреть файл

@@ -1755,6 +1755,63 @@ func (s *apiRPCServer) UpdateUserActive(args *Z_UpdateUserActiveArgs, returns *Z
return nil
}
type Z_UpdateUserCustomStatusArgs struct {
A string
B *model.CustomStatus
}
type Z_UpdateUserCustomStatusReturns struct {
A *model.AppError
}
func (g *apiRPCClient) UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError {
_args := &Z_UpdateUserCustomStatusArgs{userID, customStatus}
_returns := &Z_UpdateUserCustomStatusReturns{}
if err := g.client.Call("Plugin.UpdateUserCustomStatus", _args, _returns); err != nil {
log.Printf("RPC call to UpdateUserCustomStatus API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) UpdateUserCustomStatus(args *Z_UpdateUserCustomStatusArgs, returns *Z_UpdateUserCustomStatusReturns) error {
if hook, ok := s.impl.(interface {
UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError
}); ok {
returns.A = hook.UpdateUserCustomStatus(args.A, args.B)
} else {
return encodableError(fmt.Errorf("API UpdateUserCustomStatus called but not implemented."))
}
return nil
}
type Z_RemoveUserCustomStatusArgs struct {
A string
}
type Z_RemoveUserCustomStatusReturns struct {
A *model.AppError
}
func (g *apiRPCClient) RemoveUserCustomStatus(userID string) *model.AppError {
_args := &Z_RemoveUserCustomStatusArgs{userID}
_returns := &Z_RemoveUserCustomStatusReturns{}
if err := g.client.Call("Plugin.RemoveUserCustomStatus", _args, _returns); err != nil {
log.Printf("RPC call to RemoveUserCustomStatus API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) RemoveUserCustomStatus(args *Z_RemoveUserCustomStatusArgs, returns *Z_RemoveUserCustomStatusReturns) error {
if hook, ok := s.impl.(interface {
RemoveUserCustomStatus(userID string) *model.AppError
}); ok {
returns.A = hook.RemoveUserCustomStatus(args.A)
} else {
return encodableError(fmt.Errorf("API RemoveUserCustomStatus called but not implemented."))
}
return nil
}
type Z_GetUsersInChannelArgs struct {
A string
B string

Просмотреть файл

@@ -2918,6 +2918,22 @@ func (_m *API) RemoveTeamIcon(teamID string) *model.AppError {
return r0
}
// RemoveUserCustomStatus provides a mock function with given fields: userID
func (_m *API) RemoveUserCustomStatus(userID string) *model.AppError {
ret := _m.Called(userID)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
r0 = rf(userID)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
}
return r0
}
// RequestTrialLicense provides a mock function with given fields: requesterID, users, termsAccepted, receiveEmailsAccepted
func (_m *API) RequestTrialLicense(requesterID string, users int, termsAccepted bool, receiveEmailsAccepted bool) *model.AppError {
ret := _m.Called(requesterID, users, termsAccepted, receiveEmailsAccepted)
@@ -3531,6 +3547,22 @@ func (_m *API) UpdateUserActive(userID string, active bool) *model.AppError {
return r0
}
// UpdateUserCustomStatus provides a mock function with given fields: userID, customStatus
func (_m *API) UpdateUserCustomStatus(userID string, customStatus *model.CustomStatus) *model.AppError {
ret := _m.Called(userID, customStatus)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, *model.CustomStatus) *model.AppError); ok {
r0 = rf(userID, customStatus)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
}
}
return r0
}
// UpdateUserStatus provides a mock function with given fields: userID, status
func (_m *API) UpdateUserStatus(userID string, status string) (*model.Status, *model.AppError) {
ret := _m.Called(userID, status)