diff --git a/app/plugin_api.go b/app/plugin_api.go index b9b06a3458..ef297694f3 100644 --- a/app/plugin_api.go +++ b/app/plugin_api.go @@ -107,6 +107,10 @@ func (api *PluginAPI) GetTeamByName(name string) (*model.Team, *model.AppError) return api.app.GetTeamByName(name) } +func (api *PluginAPI) GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError) { + return api.app.GetTeamsUnreadForUser("", userId) +} + func (api *PluginAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) { return api.app.UpdateTeam(team) } diff --git a/plugin/api.go b/plugin/api.go index 8f4c5dadeb..7d95006efa 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -106,6 +106,11 @@ type API interface { // GetTeamByName gets a team by its name. GetTeamByName(name string) (*model.Team, *model.AppError) + // GetTeamsUnreadForUser gets the unread message and mention counts for each team to which the given user belongs. + // + // Minimum server version: 5.6 + GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError) + // UpdateTeam updates a team. UpdateTeam(team *model.Team) (*model.Team, *model.AppError) diff --git a/plugin/client_rpc_generated.go b/plugin/client_rpc_generated.go index 5171f3ec66..864d60a89c 100644 --- a/plugin/client_rpc_generated.go +++ b/plugin/client_rpc_generated.go @@ -1209,6 +1209,35 @@ func (s *apiRPCServer) GetTeamByName(args *Z_GetTeamByNameArgs, returns *Z_GetTe return nil } +type Z_GetTeamsUnreadForUserArgs struct { + A string +} + +type Z_GetTeamsUnreadForUserReturns struct { + A []*model.TeamUnread + B *model.AppError +} + +func (g *apiRPCClient) GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError) { + _args := &Z_GetTeamsUnreadForUserArgs{userId} + _returns := &Z_GetTeamsUnreadForUserReturns{} + if err := g.client.Call("Plugin.GetTeamsUnreadForUser", _args, _returns); err != nil { + log.Printf("RPC call to GetTeamsUnreadForUser API failed: %s", err.Error()) + } + return _returns.A, _returns.B +} + +func (s *apiRPCServer) GetTeamsUnreadForUser(args *Z_GetTeamsUnreadForUserArgs, returns *Z_GetTeamsUnreadForUserReturns) error { + if hook, ok := s.impl.(interface { + GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError) + }); ok { + returns.A, returns.B = hook.GetTeamsUnreadForUser(args.A) + } else { + return encodableError(fmt.Errorf("API GetTeamsUnreadForUser called but not implemented.")) + } + return nil +} + type Z_UpdateTeamArgs struct { A *model.Team } diff --git a/plugin/plugintest/api.go b/plugin/plugintest/api.go index 6b9184156e..9b03ed0b7b 100644 --- a/plugin/plugintest/api.go +++ b/plugin/plugintest/api.go @@ -1193,6 +1193,31 @@ func (_m *API) GetTeamsForUser(userId string) ([]*model.Team, *model.AppError) { return r0, r1 } +// GetTeamsUnreadForUser provides a mock function with given fields: userId +func (_m *API) GetTeamsUnreadForUser(userId string) ([]*model.TeamUnread, *model.AppError) { + ret := _m.Called(userId) + + var r0 []*model.TeamUnread + if rf, ok := ret.Get(0).(func(string) []*model.TeamUnread); ok { + r0 = rf(userId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*model.TeamUnread) + } + } + + 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 +} + // GetUser provides a mock function with given fields: userId func (_m *API) GetUser(userId string) (*model.User, *model.AppError) { ret := _m.Called(userId)