@ -298,32 +298,63 @@ type GetFeedsOptions struct {
// GetFeeds returns actions according to the provided options
// GetFeeds returns actions according to the provided options
func GetFeeds ( opts GetFeedsOptions ) ( [ ] * Action , error ) {
func GetFeeds ( opts GetFeedsOptions ) ( [ ] * Action , error ) {
cond := builder . NewCond ( )
if ! activityReadable ( opts . RequestedUser , opts . Actor ) {
return make ( [ ] * Action , 0 ) , nil
}
var repoIDs [ ] int64
cond , err := activityQueryCondition ( opts )
var actorID int64
if err != nil {
return nil , err
}
if opts . Actor != nil {
actions := make ( [ ] * Action , 0 , setting . UI . FeedPagingNum )
actorID = opts . Actor . ID
if err := x . Limit ( setting . UI . FeedPagingNum ) . Desc ( "id" ) . Where ( cond ) . Find ( & actions ) ; err != nil {
return nil , fmt . Errorf ( "Find: %v" , err )
}
}
if opts . RequestedUser . IsOrganization ( ) {
if err := ActionList ( actions ) . LoadAttributes ( ) ; err != nil {
env , err := opts . RequestedUser . AccessibleReposEnv ( actorID )
return nil , fmt . Errorf ( "LoadAttributes: %v" , err )
if err != nil {
}
return nil , fmt . Errorf ( "AccessibleReposEnv: %v" , err )
}
return actions , nil
if repoIDs , err = env . RepoIDs ( 1 , opts . RequestedUser . NumRepos ) ; err != nil {
}
return nil , fmt . Errorf ( "GetUserRepositories: %v" , err )
func activityReadable ( user * User , doer * User ) bool {
var doerID int64
if doer != nil {
doerID = doer . ID
}
if doer == nil || ! doer . IsAdmin {
if user . KeepActivityPrivate && doerID != user . ID {
return false
}
}
}
return true
}
cond = cond . And ( builder . In ( "repo_id" , repoIDs ) )
func activityQueryCondition ( opts GetFeedsOptions ) ( builder . Cond , error ) {
} else {
cond := builder . NewCond ( )
cond = cond . And ( builder . In ( "repo_id" , AccessibleRepoIDsQuery ( opts . Actor ) ) )
var repoIDs [ ] int64
var actorID int64
if opts . Actor != nil {
actorID = opts . Actor . ID
}
}
// check readable repositories by doer/actor
if opts . Actor == nil || ! opts . Actor . IsAdmin {
if opts . Actor == nil || ! opts . Actor . IsAdmin {
if opts . RequestedUser . KeepActivityPrivate && actorID != opts . RequestedUser . ID {
if opts . RequestedUser . IsOrganization ( ) {
return make ( [ ] * Action , 0 ) , nil
env , err := opts . RequestedUser . AccessibleReposEnv ( actorID )
if err != nil {
return nil , fmt . Errorf ( "AccessibleReposEnv: %v" , err )
}
if repoIDs , err = env . RepoIDs ( 1 , opts . RequestedUser . NumRepos ) ; err != nil {
return nil , fmt . Errorf ( "GetUserRepositories: %v" , err )
}
cond = cond . And ( builder . In ( "repo_id" , repoIDs ) )
} else {
cond = cond . And ( builder . In ( "repo_id" , AccessibleRepoIDsQuery ( opts . Actor ) ) )
}
}
}
}
@ -335,20 +366,9 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
if ! opts . IncludePrivate {
if ! opts . IncludePrivate {
cond = cond . And ( builder . Eq { "is_private" : false } )
cond = cond . And ( builder . Eq { "is_private" : false } )
}
}
if ! opts . IncludeDeleted {
if ! opts . IncludeDeleted {
cond = cond . And ( builder . Eq { "is_deleted" : false } )
cond = cond . And ( builder . Eq { "is_deleted" : false } )
}
}
actions := make ( [ ] * Action , 0 , setting . UI . FeedPagingNum )
return cond , nil
if err := x . Limit ( setting . UI . FeedPagingNum ) . Desc ( "id" ) . Where ( cond ) . Find ( & actions ) ; err != nil {
return nil , fmt . Errorf ( "Find: %v" , err )
}
if err := ActionList ( actions ) . LoadAttributes ( ) ; err != nil {
return nil , fmt . Errorf ( "LoadAttributes: %v" , err )
}
return actions , nil
}
}