diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-06-01 20:42:25 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-06-02 08:42:25 +0800 |
commit | 4e5ee2b67ac9c54ce2b0e05daf8b61a97cbe743b (patch) | |
tree | 99bb3a3ab373b625cf4ae17f4d9b210d83c1cb9f /routers | |
parent | 5ca6867aaf1d82f21a474d0c65041f21d7b416c3 (diff) | |
download | gitea-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 'routers')
-rw-r--r-- | routers/user/home.go | 23 | ||||
-rw-r--r-- | routers/user/profile.go | 2 |
2 files changed, 12 insertions, 13 deletions
diff --git a/routers/user/home.go b/routers/user/home.go index bafe62754f..0db170bfd8 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -53,19 +53,20 @@ func getDashboardContextUser(ctx *context.Context) *models.User { return ctxUser } -// retrieveFeeds loads feeds from database by given context user. -// The user could be organization so it is not always the logged in user, -// which is why we have to explicitly pass the context user ID. -func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID, offset int64, isProfile bool) { - actions, err := models.GetFeeds(ctxUser, userID, offset, isProfile) +// retrieveFeeds loads feeds for the specified user +func retrieveFeeds(ctx *context.Context, user *models.User, includePrivate, isProfile bool) { + actions, err := models.GetFeeds(models.GetFeedsOptions{ + RequestedUser: user, + RequestingUserID: ctx.User.ID, + IncludePrivate: includePrivate, + OnlyPerformedBy: isProfile, + }) if err != nil { ctx.Handle(500, "GetFeeds", err) return } - // Check access of private repositories. - feeds := make([]*models.Action, 0, len(actions)) - userCache := map[int64]*models.User{ctxUser.ID: ctxUser} + userCache := map[int64]*models.User{user.ID: user} repoCache := map[int64]*models.Repository{} for _, act := range actions { // Cache results to reduce queries. @@ -108,10 +109,8 @@ func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID, offset in } } repo.Owner = repoOwner - - feeds = append(feeds, act) } - ctx.Data["Feeds"] = feeds + ctx.Data["Feeds"] = actions } // Dashboard render the dashborad page @@ -180,7 +179,7 @@ func Dashboard(ctx *context.Context) { ctx.Data["MirrorCount"] = len(mirrors) ctx.Data["Mirrors"] = mirrors - retrieveFeeds(ctx, ctxUser, ctx.User.ID, 0, false) + retrieveFeeds(ctx, ctxUser, true, false) if ctx.Written() { return } diff --git a/routers/user/profile.go b/routers/user/profile.go index eb862d6542..1768cec7b1 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -138,7 +138,7 @@ func Profile(ctx *context.Context) { ctx.Data["Keyword"] = keyword switch tab { case "activity": - retrieveFeeds(ctx, ctxUser, -1, 0, !showPrivate) + retrieveFeeds(ctx, ctxUser, showPrivate, true) if ctx.Written() { return } |