Add RSS/Atom feed support for user actions (#16002)

Return rss/atom feed for user based on rss url suffix or Content-Type header.
This commit is contained in:
6543 2021-10-16 16:21:16 +02:00 committed by GitHub
parent 8edda8b446
commit 3728f1daa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1521 additions and 39 deletions

View file

@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/web/feed"
"code.gitea.io/gitea/routers/web/org"
)
@ -71,12 +72,35 @@ func Profile(ctx *context.Context) {
uname = strings.TrimSuffix(uname, ".gpg")
}
showFeedType := ""
if strings.HasSuffix(uname, ".rss") {
showFeedType = "rss"
uname = strings.TrimSuffix(uname, ".rss")
} else if strings.Contains(ctx.Req.Header.Get("Accept"), "application/rss+xml") {
showFeedType = "rss"
}
if strings.HasSuffix(uname, ".atom") {
showFeedType = "atom"
uname = strings.TrimSuffix(uname, ".atom")
} else if strings.Contains(ctx.Req.Header.Get("Accept"), "application/atom+xml") {
showFeedType = "atom"
}
ctxUser := GetUserByName(ctx, uname)
if ctx.Written() {
return
}
if ctxUser.IsOrganization() {
/*
// TODO: enable after rss.RetrieveFeeds() do handle org correctly
// Show Org RSS feed
if len(showFeedType) != 0 {
rss.ShowUserFeed(ctx, ctxUser, showFeedType)
return
}
*/
org.Home(ctx)
return
}
@ -99,6 +123,12 @@ func Profile(ctx *context.Context) {
return
}
// Show User RSS feed
if len(showFeedType) != 0 {
feed.ShowUserFeed(ctx, ctxUser, showFeedType)
return
}
// Show OpenID URIs
openIDs, err := models.GetUserOpenIDs(ctxUser.ID)
if err != nil {
@ -217,7 +247,7 @@ func Profile(ctx *context.Context) {
total = ctxUser.NumFollowing
case "activity":
retrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser,
Actor: ctx.User,
IncludePrivate: showPrivate,
OnlyPerformedBy: true,