From 6607e1c9444d0814b72762a46814ff0812d96343 Mon Sep 17 00:00:00 2001 From: kim Date: Thu, 18 Sep 2025 16:33:23 +0200 Subject: [feature] add paging support to rss feed endpoint, and support JSON / atom feed types (#4442) originally based on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4396 hope this is okay https://codeberg.org/zordsdavini ! closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4411 closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3407 Co-authored-by: Arnas Udovic Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4442 Co-authored-by: kim Co-committed-by: kim --- internal/processing/account/rss.go | 73 +++----- internal/processing/account/rss_test.go | 289 +++++++++++++++++++++++++++++--- internal/processing/account/statuses.go | 11 +- 3 files changed, 299 insertions(+), 74 deletions(-) (limited to 'internal/processing/account') diff --git a/internal/processing/account/rss.go b/internal/processing/account/rss.go index 495aa2e54..205027528 100644 --- a/internal/processing/account/rss.go +++ b/internal/processing/account/rss.go @@ -20,21 +20,19 @@ package account import ( "context" "errors" - "fmt" "time" "code.superseriousbusiness.org/gotosocial/internal/config" "code.superseriousbusiness.org/gotosocial/internal/db" "code.superseriousbusiness.org/gotosocial/internal/gtserror" "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" + "code.superseriousbusiness.org/gotosocial/internal/paging" "github.com/gorilla/feeds" ) -const ( - rssFeedLength = 20 -) +var never time.Time -type GetRSSFeed func() (string, gtserror.WithCode) +type GetRSSFeed func() (*feeds.Feed, gtserror.WithCode) // GetRSSFeedForUsername returns a function to return the RSS feed of a local account // with the given username, and the last-modified time (time that the account last @@ -45,33 +43,30 @@ type GetRSSFeed func() (string, gtserror.WithCode) // // If the account has not yet posted an RSS-eligible status, the returned last-modified // time will be zero, and the GetRSSFeed func will return a valid RSS xml with no items. -func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string) (GetRSSFeed, time.Time, gtserror.WithCode) { - var ( - never = time.Time{} - ) +func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string, page *paging.Page) (GetRSSFeed, time.Time, gtserror.WithCode) { + // Fetch local (i.e. empty domain) account from database by username. account, err := p.state.DB.GetAccountByUsernameDomain(ctx, username, "") if err != nil { - if errors.Is(err, db.ErrNoEntries) { - // Simply no account with this username. - err = gtserror.New("account not found") - return nil, never, gtserror.NewErrorNotFound(err) - } - - // Real db error. - err = gtserror.Newf("db error getting account %s: %w", username, err) + err := gtserror.Newf("db error getting account %s: %w", username, err) return nil, never, gtserror.NewErrorInternalError(err) } + // Check if exists. + if account == nil { + err := gtserror.New("account not found") + return nil, never, gtserror.NewErrorNotFound(err) + } + // Ensure account has rss feed enabled. if !*account.Settings.EnableRSS { - err = gtserror.New("account RSS feed not enabled") + err := gtserror.New("account RSS feed not enabled") return nil, never, gtserror.NewErrorNotFound(err) } - // Ensure account stats populated. + // Ensure account stats populated for last status fetch information. if err := p.state.DB.PopulateAccountStats(ctx, account); err != nil { - err = gtserror.Newf("db error getting account stats %s: %w", username, err) + err := gtserror.Newf("db error getting account stats %s: %w", username, err) return nil, never, gtserror.NewErrorInternalError(err) } @@ -80,14 +75,14 @@ func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string) // eligible to appear in the RSS feed; that's fine. lastPostAt := account.Stats.LastStatusAt - return func() (string, gtserror.WithCode) { + return func() (*feeds.Feed, gtserror.WithCode) { // Assemble author namestring once only. author := "@" + account.Username + "@" + config.GetAccountDomain() - // Derive image/thumbnail for this account (may be nil). + // Derive image/thumbnail for this account (may be nil if no media). image, errWithCode := p.rssImageForAccount(ctx, account, author) if errWithCode != nil { - return "", errWithCode + return nil, errWithCode } feed := &feeds.Feed{ @@ -106,7 +101,7 @@ func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string) // since we already know there's no eligible statuses. if lastPostAt.IsZero() { feed.Updated = account.CreatedAt - return stringifyFeed(feed) + return feed, nil } // Account has posted at least one status that's @@ -120,32 +115,30 @@ func (p *Processor) GetRSSFeedForUsername(ctx context.Context, username string) // // Take into account whether the user wants // their web view laid out in gallery mode. - mediaOnly := account.Settings != nil && - account.Settings.WebLayout == gtsmodel.WebLayoutGallery + mediaOnly := (account.Settings != nil && + account.Settings.WebLayout == gtsmodel.WebLayoutGallery) statuses, err := p.state.DB.GetAccountWebStatuses( ctx, account, + page, mediaOnly, - rssFeedLength, - "", // Latest posts from the top. ) if err != nil && !errors.Is(err, db.ErrNoEntries) { - err = fmt.Errorf("db error getting account web statuses: %w", err) - return "", gtserror.NewErrorInternalError(err) + err := gtserror.Newf("db error getting account web statuses: %w", err) + return nil, gtserror.NewErrorInternalError(err) } // Add each status to the rss feed. for _, status := range statuses { item, err := p.converter.StatusToRSSItem(ctx, status) if err != nil { - err = gtserror.Newf("error converting status to feed item: %w", err) - return "", gtserror.NewErrorInternalError(err) + err := gtserror.Newf("error converting status to feed item: %w", err) + return nil, gtserror.NewErrorInternalError(err) } - feed.Add(item) } - return stringifyFeed(feed) + return feed, nil }, lastPostAt, nil } @@ -177,15 +170,3 @@ func (p *Processor) rssImageForAccount(ctx context.Context, account *gtsmodel.Ac Link: account.URL, }, nil } - -func stringifyFeed(feed *feeds.Feed) (string, gtserror.WithCode) { - // Stringify the feed. Even with no statuses, - // this will still produce valid rss xml. - rss, err := feed.ToRss() - if err != nil { - err := gtserror.Newf("error converting feed to rss string: %w", err) - return "", gtserror.NewErrorInternalError(err) - } - - return rss, nil -} diff --git a/internal/processing/account/rss_test.go b/internal/processing/account/rss_test.go index 0b64e8464..b053a3795 100644 --- a/internal/processing/account/rss_test.go +++ b/internal/processing/account/rss_test.go @@ -19,7 +19,10 @@ package account_test import ( "testing" + "time" + "code.superseriousbusiness.org/gotosocial/internal/paging" + "github.com/gorilla/feeds" "github.com/stretchr/testify/suite" ) @@ -28,13 +31,8 @@ type GetRSSTestSuite struct { } func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() { - getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(suite.T().Context(), "admin") - suite.NoError(err) - suite.EqualValues(1634726497, lastModified.Unix()) - - feed, err := getFeed() - suite.NoError(err) - suite.Equal(` + suite.testGetFeedSerializedAs("admin", &paging.Page{Limit: 20}, (*feeds.Feed).ToRss, 1634726497, + ` Posts from @admin@localhost:8080 http://localhost:8080/@admin @@ -63,17 +61,177 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSAdmin() { http://localhost:8080/@admin/feed.rss -`, feed) +`) +} + +func (suite *GetRSSTestSuite) TestGetAccountAtomAdmin() { + suite.testGetFeedSerializedAs("admin", &paging.Page{Limit: 20}, (*feeds.Feed).ToAtom, 1634726497, + ` + Posts from @admin@localhost:8080 + http://localhost:8080/@admin + 2021-10-20T10:41:37Z + Posts from @admin@localhost:8080 + + + open to see some <strong>puppies</strong> + 2021-10-20T12:36:45Z + http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37 + <p>🐕🐕🐕🐕🐕</p> + + + @admin@localhost:8080 made a new post: "🐕🐕🐕🐕🐕" + + @admin@localhost:8080 + + + + hello world! #welcome ! first post on the instance :rainbow: ! + 2021-10-20T11:36:45Z + http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R + <p>hello world! <a href="http://localhost:8080/tags/welcome" class="mention hashtag" rel="tag nofollow noreferrer noopener" target="_blank">#<span>welcome</span></a> ! first post on the instance <img src="http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png" title=":rainbow:" alt=":rainbow:" width="25" height="25" /> !</p> + + + @admin@localhost:8080 posted 1 attachment: "hello world! #welcome ! first post on the instance :rainbow: !" + + @admin@localhost:8080 + + +`) +} + +func (suite *GetRSSTestSuite) TestGetAccountJSONAdmin() { + suite.testGetFeedSerializedAs("admin", &paging.Page{Limit: 20}, (*feeds.Feed).ToJSON, 1634726497, + `{ + "version": "https://jsonfeed.org/version/1.1", + "title": "Posts from @admin@localhost:8080", + "home_page_url": "http://localhost:8080/@admin", + "description": "Posts from @admin@localhost:8080", + "items": [ + { + "id": "http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37", + "url": "http://localhost:8080/@admin/statuses/01F8MHAAY43M6RJ473VQFCVH37", + "external_url": "http://localhost:8080/@admin/feed.rss", + "title": "open to see some \u003cstrong\u003epuppies\u003c/strong\u003e", + "content_html": "\u003cp\u003e🐕🐕🐕🐕🐕\u003c/p\u003e", + "summary": "@admin@localhost:8080 made a new post: \"🐕🐕🐕🐕🐕\"", + "date_published": "2021-10-20T12:36:45Z", + "author": { + "name": "@admin@localhost:8080" + }, + "authors": [ + { + "name": "@admin@localhost:8080" + } + ] + }, + { + "id": "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R", + "url": "http://localhost:8080/@admin/statuses/01F8MH75CBF9JFX4ZAD54N0W0R", + "external_url": "http://localhost:8080/@admin/feed.rss", + "title": "hello world! #welcome ! first post on the instance :rainbow: !", + "content_html": "\u003cp\u003ehello world! \u003ca href=\"http://localhost:8080/tags/welcome\" class=\"mention hashtag\" rel=\"tag nofollow noreferrer noopener\" target=\"_blank\"\u003e#\u003cspan\u003ewelcome\u003c/span\u003e\u003c/a\u003e ! first post on the instance \u003cimg src=\"http://localhost:8080/fileserver/01AY6P665V14JJR0AFVRT7311Y/emoji/original/01F8MH9H8E4VG3KDYJR9EGPXCQ.png\" title=\":rainbow:\" alt=\":rainbow:\" width=\"25\" height=\"25\" /\u003e !\u003c/p\u003e", + "summary": "@admin@localhost:8080 posted 1 attachment: \"hello world! #welcome ! first post on the instance :rainbow: !\"", + "image": "http://localhost:8080/fileserver/01F8MH17FWEB39HZJ76B6VXSKF/attachment/original/01F8MH6NEM8D7527KZAECTCR76.jpg", + "date_published": "2021-10-20T11:36:45Z", + "author": { + "name": "@admin@localhost:8080" + }, + "authors": [ + { + "name": "@admin@localhost:8080" + } + ] + } + ] +}`) } func (suite *GetRSSTestSuite) TestGetAccountRSSZork() { - getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(suite.T().Context(), "the_mighty_zork") - suite.NoError(err) - suite.EqualValues(1730451600, lastModified.Unix()) + suite.testGetFeedSerializedAs("the_mighty_zork", &paging.Page{Limit: 20}, (*feeds.Feed).ToRss, 1730451600, + ` + + Posts from @the_mighty_zork@localhost:8080 + http://localhost:8080/@the_mighty_zork + Posts from @the_mighty_zork@localhost:8080 + Fri, 01 Nov 2024 09:00:00 +0000 + Fri, 01 Nov 2024 09:00:00 +0000 + + http://localhost:8080/fileserver/01F8MH1H7YV1Z7D2C8K2730QBF/avatar/small/01F8MH58A357CV5K7R7TJMSH6S.webp + Avatar for @the_mighty_zork@localhost:8080 + http://localhost:8080/@the_mighty_zork + + + edited status + http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR + @the_mighty_zork@localhost:8080 made a new post: "this is the latest revision of the status, with a content-warning" + this is the latest revision of the status, with a content-warning

]]>
+ @the_mighty_zork@localhost:8080 + http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR + Fri, 01 Nov 2024 09:00:00 +0000 + http://localhost:8080/@the_mighty_zork/feed.rss +
+ + HTML in post + http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40 + @the_mighty_zork@localhost:8080 made a new post: "Here's a bunch of HTML, read it and weep, weep then! `+"```"+`html <section class="about-user"> <div class="col-header"> <h2>About</h2> </div> <div class="fields"> <h3 class="sr-only">Fields</h3> <dl> ... + Here's a bunch of HTML, read it and weep, weep then!

<section class="about-user">
+    <div class="col-header">
+        <h2>About</h2>
+    </div>            
+    <div class="fields">
+        <h3 class="sr-only">Fields</h3>
+        <dl>
+            <div class="field">
+                <dt>should you follow me?</dt>
+                <dd>maybe!</dd>
+            </div>
+            <div class="field">
+                <dt>age</dt>
+                <dd>120</dd>
+            </div>
+        </dl>
+    </div>
+    <div class="bio">
+        <h3 class="sr-only">Bio</h3>
+        <p>i post about things that concern me</p>
+    </div>
+    <div class="sr-only" role="group">
+        <h3 class="sr-only">Stats</h3>
+        <span>Joined in Jun, 2022.</span>
+        <span>8 posts.</span>
+        <span>Followed by 1.</span>
+        <span>Following 1.</span>
+    </div>
+    <div class="accountstats" aria-hidden="true">
+        <b>Joined</b><time datetime="2022-06-04T13:12:00.000Z">Jun, 2022</time>
+        <b>Posts</b><span>8</span>
+        <b>Followed by</b><span>1</span>
+        <b>Following</b><span>1</span>
+    </div>
+</section>
+

There, hope you liked that!

]]>
+ @the_mighty_zork@localhost:8080 + http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40 + Sun, 10 Dec 2023 09:24:00 +0000 + http://localhost:8080/@the_mighty_zork/feed.rss +
+ + introduction post + http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY + @the_mighty_zork@localhost:8080 made a new post: "hello everyone!" + hello everyone!

]]>
+ @the_mighty_zork@localhost:8080 + http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY + Wed, 20 Oct 2021 10:40:37 +0000 + http://localhost:8080/@the_mighty_zork/feed.rss +
+
+
`) +} - feed, err := getFeed() - suite.NoError(err) - suite.Equal(` +func (suite *GetRSSTestSuite) TestGetAccountAtomZork() { + suite.testGetFeedSerializedAs("the_mighty_zork", &paging.Page{Limit: 20}, (*feeds.Feed).ToRss, 1730451600, + ` Posts from @the_mighty_zork@localhost:8080 http://localhost:8080/@the_mighty_zork @@ -151,7 +309,71 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSZork() { http://localhost:8080/@the_mighty_zork/feed.rss -`, feed) +`) +} + +func (suite *GetRSSTestSuite) TestGetAccountJSONZork() { + suite.testGetFeedSerializedAs("the_mighty_zork", &paging.Page{Limit: 20}, (*feeds.Feed).ToJSON, 1730451600, + `{ + "version": "https://jsonfeed.org/version/1.1", + "title": "Posts from @the_mighty_zork@localhost:8080", + "home_page_url": "http://localhost:8080/@the_mighty_zork", + "description": "Posts from @the_mighty_zork@localhost:8080", + "items": [ + { + "id": "http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR", + "url": "http://localhost:8080/@the_mighty_zork/statuses/01JDPZC707CKDN8N4QVWM4Z1NR", + "external_url": "http://localhost:8080/@the_mighty_zork/feed.rss", + "title": "edited status", + "content_html": "\u003cp\u003ethis is the latest revision of the status, with a content-warning\u003c/p\u003e", + "summary": "@the_mighty_zork@localhost:8080 made a new post: \"this is the latest revision of the status, with a content-warning\"", + "date_published": "2024-11-01T09:00:00Z", + "date_modified": "2024-11-01T09:02:00Z", + "author": { + "name": "@the_mighty_zork@localhost:8080" + }, + "authors": [ + { + "name": "@the_mighty_zork@localhost:8080" + } + ] + }, + { + "id": "http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40", + "url": "http://localhost:8080/@the_mighty_zork/statuses/01HH9KYNQPA416TNJ53NSATP40", + "external_url": "http://localhost:8080/@the_mighty_zork/feed.rss", + "title": "HTML in post", + "content_html": "\u003cp\u003eHere's a bunch of HTML, read it and weep, weep then!\u003c/p\u003e\u003cpre\u003e\u003ccode class=\"language-html\"\u003e\u0026lt;section class=\u0026#34;about-user\u0026#34;\u0026gt;\n \u0026lt;div class=\u0026#34;col-header\u0026#34;\u0026gt;\n \u0026lt;h2\u0026gt;About\u0026lt;/h2\u0026gt;\n \u0026lt;/div\u0026gt; \n \u0026lt;div class=\u0026#34;fields\u0026#34;\u0026gt;\n \u0026lt;h3 class=\u0026#34;sr-only\u0026#34;\u0026gt;Fields\u0026lt;/h3\u0026gt;\n \u0026lt;dl\u0026gt;\n \u0026lt;div class=\u0026#34;field\u0026#34;\u0026gt;\n \u0026lt;dt\u0026gt;should you follow me?\u0026lt;/dt\u0026gt;\n \u0026lt;dd\u0026gt;maybe!\u0026lt;/dd\u0026gt;\n \u0026lt;/div\u0026gt;\n \u0026lt;div class=\u0026#34;field\u0026#34;\u0026gt;\n \u0026lt;dt\u0026gt;age\u0026lt;/dt\u0026gt;\n \u0026lt;dd\u0026gt;120\u0026lt;/dd\u0026gt;\n \u0026lt;/div\u0026gt;\n \u0026lt;/dl\u0026gt;\n \u0026lt;/div\u0026gt;\n \u0026lt;div class=\u0026#34;bio\u0026#34;\u0026gt;\n \u0026lt;h3 class=\u0026#34;sr-only\u0026#34;\u0026gt;Bio\u0026lt;/h3\u0026gt;\n \u0026lt;p\u0026gt;i post about things that concern me\u0026lt;/p\u0026gt;\n \u0026lt;/div\u0026gt;\n \u0026lt;div class=\u0026#34;sr-only\u0026#34; role=\u0026#34;group\u0026#34;\u0026gt;\n \u0026lt;h3 class=\u0026#34;sr-only\u0026#34;\u0026gt;Stats\u0026lt;/h3\u0026gt;\n \u0026lt;span\u0026gt;Joined in Jun, 2022.\u0026lt;/span\u0026gt;\n \u0026lt;span\u0026gt;8 posts.\u0026lt;/span\u0026gt;\n \u0026lt;span\u0026gt;Followed by 1.\u0026lt;/span\u0026gt;\n \u0026lt;span\u0026gt;Following 1.\u0026lt;/span\u0026gt;\n \u0026lt;/div\u0026gt;\n \u0026lt;div class=\u0026#34;accountstats\u0026#34; aria-hidden=\u0026#34;true\u0026#34;\u0026gt;\n \u0026lt;b\u0026gt;Joined\u0026lt;/b\u0026gt;\u0026lt;time datetime=\u0026#34;2022-06-04T13:12:00.000Z\u0026#34;\u0026gt;Jun, 2022\u0026lt;/time\u0026gt;\n \u0026lt;b\u0026gt;Posts\u0026lt;/b\u0026gt;\u0026lt;span\u0026gt;8\u0026lt;/span\u0026gt;\n \u0026lt;b\u0026gt;Followed by\u0026lt;/b\u0026gt;\u0026lt;span\u0026gt;1\u0026lt;/span\u0026gt;\n \u0026lt;b\u0026gt;Following\u0026lt;/b\u0026gt;\u0026lt;span\u0026gt;1\u0026lt;/span\u0026gt;\n \u0026lt;/div\u0026gt;\n\u0026lt;/section\u0026gt;\n\u003c/code\u003e\u003c/pre\u003e\u003cp\u003eThere, hope you liked that!\u003c/p\u003e", + "summary": "@the_mighty_zork@localhost:8080 made a new post: \"Here's a bunch of HTML, read it and weep, weep then!\n\n`+"```"+`html\n\u003csection class=\"about-user\"\u003e\n \u003cdiv class=\"col-header\"\u003e\n \u003ch2\u003eAbout\u003c/h2\u003e\n \u003c/div\u003e \n \u003cdiv class=\"fields\"\u003e\n \u003ch3 class=\"sr-only\"\u003eFields\u003c/h3\u003e\n \u003cdl\u003e\n...", + "date_published": "2023-12-10T09:24:00Z", + "author": { + "name": "@the_mighty_zork@localhost:8080" + }, + "authors": [ + { + "name": "@the_mighty_zork@localhost:8080" + } + ] + }, + { + "id": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", + "url": "http://localhost:8080/@the_mighty_zork/statuses/01F8MHAMCHF6Y650WCRSCP4WMY", + "external_url": "http://localhost:8080/@the_mighty_zork/feed.rss", + "title": "introduction post", + "content_html": "\u003cp\u003ehello everyone!\u003c/p\u003e", + "summary": "@the_mighty_zork@localhost:8080 made a new post: \"hello everyone!\"", + "date_published": "2021-10-20T10:40:37Z", + "author": { + "name": "@the_mighty_zork@localhost:8080" + }, + "authors": [ + { + "name": "@the_mighty_zork@localhost:8080" + } + ] + } + ] +}`) } func (suite *GetRSSTestSuite) TestGetAccountRSSZorkNoPosts() { @@ -170,13 +392,10 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSZorkNoPosts() { } } - getFeed, lastModified, err := suite.accountProcessor.GetRSSFeedForUsername(ctx, "the_mighty_zork") - suite.NoError(err) - suite.Empty(lastModified) + var zeroTime time.Time - feed, err := getFeed() - suite.NoError(err) - suite.Equal(` + suite.testGetFeedSerializedAs("the_mighty_zork", &paging.Page{Limit: 20}, (*feeds.Feed).ToRss, zeroTime.Unix(), + ` Posts from @the_mighty_zork@localhost:8080 http://localhost:8080/@the_mighty_zork @@ -189,7 +408,33 @@ func (suite *GetRSSTestSuite) TestGetAccountRSSZorkNoPosts() { http://localhost:8080/@the_mighty_zork -`, feed) +`) +} + +// func (suite *GetRSSTestSuite) testGetAccountRSSPaging(username string, page *paging.Page, expectIDs []string) { +// ctx := suite.T().Context() + +// getFeed, _, errWithCode := suite.accountProcessor.GetRSSFeedForUsername(ctx, username, page) +// suite.NoError(errWithCode) + +// feed, errWithCode := getFeed() +// suite.NoError(errWithCode) + +// } + +func (suite *GetRSSTestSuite) testGetFeedSerializedAs(username string, page *paging.Page, serialize func(*feeds.Feed) (string, error), expectLastMod int64, expectSerialized string) { + ctx := suite.T().Context() + + getFeed, lastMod, errWithCode := suite.accountProcessor.GetRSSFeedForUsername(ctx, username, page) + suite.NoError(errWithCode) + suite.Equal(expectLastMod, lastMod.Unix()) + + feed, errWithCode := getFeed() + suite.NoError(errWithCode) + + feedStr, err := serialize(feed) + suite.NoError(err) + suite.Equal(expectSerialized, feedStr) } func TestGetRSSTestSuite(t *testing.T) { diff --git a/internal/processing/account/statuses.go b/internal/processing/account/statuses.go index e55c1e81c..870019f41 100644 --- a/internal/processing/account/statuses.go +++ b/internal/processing/account/statuses.go @@ -27,6 +27,7 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/gtserror" "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" "code.superseriousbusiness.org/gotosocial/internal/log" + "code.superseriousbusiness.org/gotosocial/internal/paging" "code.superseriousbusiness.org/gotosocial/internal/util" ) @@ -156,9 +157,8 @@ func (p *Processor) StatusesGet( func (p *Processor) WebStatusesGet( ctx context.Context, targetAccountID string, + page *paging.Page, mediaOnly bool, - limit int, - maxID string, ) (*apimodel.PageableResponse, gtserror.WithCode) { account, err := p.state.DB.GetAccountByID(ctx, targetAccountID) if err != nil { @@ -174,14 +174,13 @@ func (p *Processor) WebStatusesGet( return nil, gtserror.NewErrorNotFound(err) } - statuses, err := p.state.DB.GetAccountWebStatuses( - ctx, + statuses, err := p.state.DB.GetAccountWebStatuses(ctx, account, + page, mediaOnly, - limit, - maxID, ) if err != nil && !errors.Is(err, db.ErrNoEntries) { + err := gtserror.Newf("db error getting statuses: %w", err) return nil, gtserror.NewErrorInternalError(err) } -- cgit v1.2.3