summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-07-16 15:49:26 -0400
committerGitHub <noreply@github.com>2018-07-16 15:49:26 -0400
commit275731578e72d2c6e12cfb2fc315d3446474faec (patch)
tree25df7525ed2244c7dec5be44495b45ffc0ae1023 /plugin
parent88eef609ab712097ff2b13a2ca45c31ea6fa7df2 (diff)
downloadchat-275731578e72d2c6e12cfb2fc315d3446474faec.tar.gz
chat-275731578e72d2c6e12cfb2fc315d3446474faec.tar.bz2
chat-275731578e72d2c6e12cfb2fc315d3446474faec.zip
MM-10254 Add plugin APIs for getting/updating user statuses (#9101)
* Add plugin APIs for getting/updating user statuses * Add and update tests * Updates per feedback
Diffstat (limited to 'plugin')
-rw-r--r--plugin/api.go10
-rw-r--r--plugin/client_rpc_generated.go88
-rw-r--r--plugin/mock_api_test.go77
-rw-r--r--plugin/plugintest/api.go77
-rw-r--r--plugin/plugintest/hooks.go2
5 files changed, 251 insertions, 3 deletions
diff --git a/plugin/api.go b/plugin/api.go
index 76df9377a..70a3e7ab5 100644
--- a/plugin/api.go
+++ b/plugin/api.go
@@ -49,6 +49,16 @@ type API interface {
// UpdateUser updates a user.
UpdateUser(user *model.User) (*model.User, *model.AppError)
+ // GetUserStatus will get a user's status.
+ GetUserStatus(userId string) (*model.Status, *model.AppError)
+
+ // GetUserStatusesByIds will return a list of user statuses based on the provided slice of user IDs.
+ GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)
+
+ // UpdateUserStatus will set a user's status until the user, or another integration/plugin, sets it back to online.
+ // The status parameter can be: "online", "away", "dnd", or "offline".
+ UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)
+
// CreateTeam creates a team.
CreateTeam(team *model.Team) (*model.Team, *model.AppError)
diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go
index ab884e647..a96ff33e5 100644
--- a/plugin/client_rpc_generated.go
+++ b/plugin/client_rpc_generated.go
@@ -716,6 +716,94 @@ func (s *apiRPCServer) UpdateUser(args *Z_UpdateUserArgs, returns *Z_UpdateUserR
return nil
}
+type Z_GetUserStatusArgs struct {
+ A string
+}
+
+type Z_GetUserStatusReturns struct {
+ A *model.Status
+ B *model.AppError
+}
+
+func (g *apiRPCClient) GetUserStatus(userId string) (*model.Status, *model.AppError) {
+ _args := &Z_GetUserStatusArgs{userId}
+ _returns := &Z_GetUserStatusReturns{}
+ if err := g.client.Call("Plugin.GetUserStatus", _args, _returns); err != nil {
+ g.log.Error("RPC call to GetUserStatus API failed.", mlog.Err(err))
+ }
+ return _returns.A, _returns.B
+}
+
+func (s *apiRPCServer) GetUserStatus(args *Z_GetUserStatusArgs, returns *Z_GetUserStatusReturns) error {
+ if hook, ok := s.impl.(interface {
+ GetUserStatus(userId string) (*model.Status, *model.AppError)
+ }); ok {
+ returns.A, returns.B = hook.GetUserStatus(args.A)
+ } else {
+ return fmt.Errorf("API GetUserStatus called but not implemented.")
+ }
+ return nil
+}
+
+type Z_GetUserStatusesByIdsArgs struct {
+ A []string
+}
+
+type Z_GetUserStatusesByIdsReturns struct {
+ A []*model.Status
+ B *model.AppError
+}
+
+func (g *apiRPCClient) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) {
+ _args := &Z_GetUserStatusesByIdsArgs{userIds}
+ _returns := &Z_GetUserStatusesByIdsReturns{}
+ if err := g.client.Call("Plugin.GetUserStatusesByIds", _args, _returns); err != nil {
+ g.log.Error("RPC call to GetUserStatusesByIds API failed.", mlog.Err(err))
+ }
+ return _returns.A, _returns.B
+}
+
+func (s *apiRPCServer) GetUserStatusesByIds(args *Z_GetUserStatusesByIdsArgs, returns *Z_GetUserStatusesByIdsReturns) error {
+ if hook, ok := s.impl.(interface {
+ GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError)
+ }); ok {
+ returns.A, returns.B = hook.GetUserStatusesByIds(args.A)
+ } else {
+ return fmt.Errorf("API GetUserStatusesByIds called but not implemented.")
+ }
+ return nil
+}
+
+type Z_UpdateUserStatusArgs struct {
+ A string
+ B string
+}
+
+type Z_UpdateUserStatusReturns struct {
+ A *model.Status
+ B *model.AppError
+}
+
+func (g *apiRPCClient) UpdateUserStatus(userId, status string) (*model.Status, *model.AppError) {
+ _args := &Z_UpdateUserStatusArgs{userId, status}
+ _returns := &Z_UpdateUserStatusReturns{}
+ if err := g.client.Call("Plugin.UpdateUserStatus", _args, _returns); err != nil {
+ g.log.Error("RPC call to UpdateUserStatus API failed.", mlog.Err(err))
+ }
+ return _returns.A, _returns.B
+}
+
+func (s *apiRPCServer) UpdateUserStatus(args *Z_UpdateUserStatusArgs, returns *Z_UpdateUserStatusReturns) error {
+ if hook, ok := s.impl.(interface {
+ UpdateUserStatus(userId, status string) (*model.Status, *model.AppError)
+ }); ok {
+ returns.A, returns.B = hook.UpdateUserStatus(args.A, args.B)
+ } else {
+ return fmt.Errorf("API UpdateUserStatus called but not implemented.")
+ }
+ return nil
+}
+
type Z_CreateTeamArgs struct {
A *model.Team
}
diff --git a/plugin/mock_api_test.go b/plugin/mock_api_test.go
index 1ffa3aa46..07b1c1277 100644
--- a/plugin/mock_api_test.go
+++ b/plugin/mock_api_test.go
@@ -1,4 +1,4 @@
-// Code generated by mockery v1.0.0. DO NOT EDIT.
+// Code generated by mockery v1.0.0
// Regenerate this file using `make plugin-mocks`.
@@ -674,6 +674,56 @@ func (_m *MockAPI) GetUserByUsername(name string) (*model.User, *model.AppError)
return r0, r1
}
+// GetUserStatus provides a mock function with given fields: userId
+func (_m *MockAPI) GetUserStatus(userId string) (*model.Status, *model.AppError) {
+ ret := _m.Called(userId)
+
+ var r0 *model.Status
+ if rf, ok := ret.Get(0).(func(string) *model.Status); ok {
+ r0 = rf(userId)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*model.Status)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
+ r1 = rf(userId)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
+
+// GetUserStatusesByIds provides a mock function with given fields: userIds
+func (_m *MockAPI) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) {
+ ret := _m.Called(userIds)
+
+ var r0 []*model.Status
+ if rf, ok := ret.Get(0).(func([]string) []*model.Status); ok {
+ r0 = rf(userIds)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*model.Status)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok {
+ r1 = rf(userIds)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
+
// KVDelete provides a mock function with given fields: key
func (_m *MockAPI) KVDelete(key string) *model.AppError {
ret := _m.Called(key)
@@ -1016,3 +1066,28 @@ func (_m *MockAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
return r0, r1
}
+
+// UpdateUserStatus provides a mock function with given fields: status, userId
+func (_m *MockAPI) UpdateUserStatus(status string, userId string) (*model.Status, *model.AppError) {
+ ret := _m.Called(status, userId)
+
+ var r0 *model.Status
+ if rf, ok := ret.Get(0).(func(string, string) *model.Status); ok {
+ r0 = rf(status, userId)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*model.Status)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
+ r1 = rf(status, userId)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go
index 3ce1d0145..06ab02560 100644
--- a/plugin/plugintest/api.go
+++ b/plugin/plugintest/api.go
@@ -1,4 +1,4 @@
-// Code generated by mockery v1.0.0. DO NOT EDIT.
+// Code generated by mockery v1.0.0
// Regenerate this file using `make plugin-mocks`.
@@ -674,6 +674,56 @@ func (_m *API) GetUserByUsername(name string) (*model.User, *model.AppError) {
return r0, r1
}
+// GetUserStatus provides a mock function with given fields: userId
+func (_m *API) GetUserStatus(userId string) (*model.Status, *model.AppError) {
+ ret := _m.Called(userId)
+
+ var r0 *model.Status
+ if rf, ok := ret.Get(0).(func(string) *model.Status); ok {
+ r0 = rf(userId)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*model.Status)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
+ r1 = rf(userId)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
+
+// GetUserStatusesByIds provides a mock function with given fields: userIds
+func (_m *API) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.AppError) {
+ ret := _m.Called(userIds)
+
+ var r0 []*model.Status
+ if rf, ok := ret.Get(0).(func([]string) []*model.Status); ok {
+ r0 = rf(userIds)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).([]*model.Status)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func([]string) *model.AppError); ok {
+ r1 = rf(userIds)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
+
// KVDelete provides a mock function with given fields: key
func (_m *API) KVDelete(key string) *model.AppError {
ret := _m.Called(key)
@@ -1016,3 +1066,28 @@ func (_m *API) UpdateUser(user *model.User) (*model.User, *model.AppError) {
return r0, r1
}
+
+// UpdateUserStatus provides a mock function with given fields: status, userId
+func (_m *API) UpdateUserStatus(status string, userId string) (*model.Status, *model.AppError) {
+ ret := _m.Called(status, userId)
+
+ var r0 *model.Status
+ if rf, ok := ret.Get(0).(func(string, string) *model.Status); ok {
+ r0 = rf(status, userId)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*model.Status)
+ }
+ }
+
+ var r1 *model.AppError
+ if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
+ r1 = rf(status, userId)
+ } else {
+ if ret.Get(1) != nil {
+ r1 = ret.Get(1).(*model.AppError)
+ }
+ }
+
+ return r0, r1
+}
diff --git a/plugin/plugintest/hooks.go b/plugin/plugintest/hooks.go
index d88792f58..61268c299 100644
--- a/plugin/plugintest/hooks.go
+++ b/plugin/plugintest/hooks.go
@@ -1,4 +1,4 @@
-// Code generated by mockery v1.0.0. DO NOT EDIT.
+// Code generated by mockery v1.0.0
// Regenerate this file using `make plugin-mocks`.