Skip to content

Commit b839c84

Browse files
committed
wip
1 parent e8fba1f commit b839c84

File tree

17 files changed

+1293
-0
lines changed

17 files changed

+1293
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ require (
5454
github.com/google/go-querystring v1.1.0 // indirect
5555
github.com/google/uuid v1.2.0
5656
github.com/gorilla/context v1.1.1
57+
github.com/gorilla/feeds v1.1.1
5758
github.com/gorilla/mux v1.8.0 // indirect
5859
github.com/gorilla/sessions v1.2.1 // indirect
5960
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,8 @@ github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8
555555
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
556556
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
557557
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
558+
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
559+
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
558560
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
559561
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
560562
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=

routers/web/user/profile.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"path"
1212
"strings"
13+
"time"
1314

1415
"code.gitea.io/gitea/models"
1516
"code.gitea.io/gitea/modules/context"
@@ -18,6 +19,8 @@ import (
1819
"code.gitea.io/gitea/modules/setting"
1920
"code.gitea.io/gitea/modules/util"
2021
"code.gitea.io/gitea/routers/web/org"
22+
23+
"github.com/gorilla/feeds"
2124
)
2225

2326
// GetUserByName get user by name
@@ -70,6 +73,12 @@ func Profile(ctx *context.Context) {
7073
uname = strings.TrimSuffix(uname, ".gpg")
7174
}
7275

76+
isShowRSS := false
77+
if strings.HasSuffix(uname, ".rss") {
78+
isShowRSS = true
79+
uname = strings.TrimSuffix(uname, ".rss")
80+
}
81+
7382
ctxUser := GetUserByName(ctx, uname)
7483
if ctx.Written() {
7584
return
@@ -87,6 +96,12 @@ func Profile(ctx *context.Context) {
8796
return
8897
}
8998

99+
// Show User RSS feed
100+
if isShowRSS {
101+
ShowRSS(ctx, ctxUser)
102+
return
103+
}
104+
90105
if ctxUser.IsOrganization() {
91106
org.Home(ctx)
92107
return
@@ -306,6 +321,53 @@ func Profile(ctx *context.Context) {
306321
ctx.HTML(http.StatusOK, tplProfile)
307322
}
308323

324+
// ShowRSS show user activity as RSS feed
325+
func ShowRSS(ctx *context.Context, ctxUser *models.User) {
326+
actions := retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
327+
Actor: ctx.User,
328+
IncludePrivate: false,
329+
OnlyPerformedBy: true,
330+
IncludeDeleted: false,
331+
Date: ctx.Query("date"),
332+
})
333+
if ctx.Written() {
334+
return
335+
}
336+
337+
now := time.Now()
338+
feed := &feeds.Feed{
339+
Title: ctxUser.FullName,
340+
Link: &feeds.Link{Href: ctxUser.HTMLURL()},
341+
Description: ctxUser.Description,
342+
Created: now,
343+
}
344+
345+
feed.Items = feedActionsToFeedItems(actions)
346+
347+
//atom, err := feed.ToAtom()
348+
if rss, err := feed.ToRss(); err != nil {
349+
ctx.ServerError("ToRss", err)
350+
} else {
351+
ctx.PlainText(http.StatusOK, []byte(rss))
352+
}
353+
354+
}
355+
356+
func feedActionsToFeedItems(actions []*models.Action) (items []*feeds.Item) {
357+
for i := range actions {
358+
actions[i].LoadActUser()
359+
360+
items = append(items, &feeds.Item{
361+
Title: string(actions[i].GetOpType()),
362+
Link: &feeds.Link{Href: actions[i].GetCommentLink(), Rel: actions[i].ActUser.AvatarLink()},
363+
Description: "A discussion on controlled parallelism in golang",
364+
Author: &feeds.Author{Name: actions[i].ActUser.FullName, Email: actions[i].ActUser.GetEmail()},
365+
Created: actions[i].CreatedUnix.AsTime(),
366+
})
367+
}
368+
return
369+
}
370+
309371
// Action response for follow/unfollow user request
310372
func Action(ctx *context.Context) {
311373
u := GetUserByParams(ctx)

vendor/github.com/gorilla/feeds/.travis.yml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gorilla/feeds/AUTHORS

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gorilla/feeds/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/gorilla/feeds/README.md

Lines changed: 185 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)