summaryrefslogtreecommitdiffstats
path: root/models/action.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-06-01 20:42:25 -0400
committerLunny Xiao <xiaolunwen@gmail.com>2017-06-02 08:42:25 +0800
commit4e5ee2b67ac9c54ce2b0e05daf8b61a97cbe743b (patch)
tree99bb3a3ab373b625cf4ae17f4d9b210d83c1cb9f /models/action.go
parent5ca6867aaf1d82f21a474d0c65041f21d7b416c3 (diff)
downloadgitea-4e5ee2b67ac9c54ce2b0e05daf8b61a97cbe743b.tar.gz
gitea-4e5ee2b67ac9c54ce2b0e05daf8b61a97cbe743b.zip
Fix user profile activity feed (#1848)
* Fix user profile activity feed * gofmt, and avoid overlapping database connections
Diffstat (limited to 'models/action.go')
-rw-r--r--models/action.go50
1 files changed, 28 insertions, 22 deletions
diff --git a/models/action.go b/models/action.go
index a09e420660..fa610ff5cd 100644
--- a/models/action.go
+++ b/models/action.go
@@ -672,33 +672,39 @@ func MergePullRequestAction(actUser *User, repo *Repository, pull *Issue) error
return mergePullRequestAction(x, actUser, repo, pull)
}
-// GetFeeds returns action list of given user in given context.
-// actorID is the user who's requesting, ctxUserID is the user/org that is requested.
-// actorID can be -1 when isProfile is true or to skip the permission check.
-func GetFeeds(ctxUser *User, actorID, offset int64, isProfile bool) ([]*Action, error) {
- actions := make([]*Action, 0, 20)
- sess := x.
- Limit(20, int(offset)).
- Desc("id").
- Where("user_id = ?", ctxUser.ID)
- if isProfile {
- sess.
- And("is_private = ?", false).
- And("act_user_id = ?", ctxUser.ID)
- } else if actorID != -1 && ctxUser.IsOrganization() {
- env, err := ctxUser.AccessibleReposEnv(actorID)
+// GetFeedsOptions options for retrieving feeds
+type GetFeedsOptions struct {
+ RequestedUser *User
+ RequestingUserID int64
+ IncludePrivate bool // include private actions
+ OnlyPerformedBy bool // only actions performed by requested user
+}
+
+// GetFeeds returns actions according to the provided options
+func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
+ var repoIDs []int64
+ if opts.RequestedUser.IsOrganization() {
+ env, err := opts.RequestedUser.AccessibleReposEnv(opts.RequestingUserID)
if err != nil {
return nil, fmt.Errorf("AccessibleReposEnv: %v", err)
}
- repoIDs, err := env.RepoIDs(1, ctxUser.NumRepos)
- if err != nil {
+ if repoIDs, err = env.RepoIDs(1, opts.RequestedUser.NumRepos); err != nil {
return nil, fmt.Errorf("GetUserRepositories: %v", err)
}
- if len(repoIDs) > 0 {
- sess.In("repo_id", repoIDs)
- }
}
- err := sess.Find(&actions)
- return actions, err
+ actions := make([]*Action, 0, 20)
+ sess := x.Limit(20).
+ Desc("id").
+ Where("user_id = ?", opts.RequestedUser.ID)
+ if opts.OnlyPerformedBy {
+ sess.And("act_user_id = ?", opts.RequestedUser.ID)
+ }
+ if !opts.IncludePrivate {
+ sess.And("is_private = ?", false)
+ }
+ if opts.RequestedUser.IsOrganization() {
+ sess.In("repo_id", repoIDs)
+ }
+ return actions, sess.Find(&actions)
}