Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toot a limited number of old toots when first creating an account for a feed. #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/server/logic/feed_follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package logic

import (
"fmt"
"github.com/PuerkitoBio/goquery"
"github.com/microcosm-cc/bluemonday"
"github.com/mmcdole/gofeed"
"github.com/spaolacci/murmur3"
"html"
"math/rand"
"net/http"
Expand All @@ -18,6 +14,11 @@ import (
"strings"
"sync"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/microcosm-cc/bluemonday"
"github.com/mmcdole/gofeed"
"github.com/spaolacci/murmur3"
)

//go:generate mockgen --build_flags=--mod=mod -destination ../test/mocks/mock_feed_follower.go -package mocks rss_parrot/logic IFeedFollower
Expand Down Expand Up @@ -303,9 +304,17 @@ func (ff *feedFollower) updateAccountPosts(
// Deal with feed items newer than our last seen
// This goes from older to newer
keepers, newLastUpdated := getSortedPosts(feed.Items, lastKnownFeedUpdated)

// We still send toots from before the account was created,
// but limit their number to prevent sending a crazy number of toots.
oldTootsToSend := 5
if !tootNew && len(keepers) > oldTootsToSend {
keepers = keepers[len(keepers)-oldTootsToSend:]
}

for _, k := range keepers {
fixPodcastLink(k.itm)
if err = ff.storePostIfNew(accountId, accountHandle, k.postTime, k.itm, tootNew); err != nil {
if err = ff.storePostIfNew(accountId, accountHandle, k.postTime, k.itm); err != nil {
return
}
}
Expand Down Expand Up @@ -420,7 +429,6 @@ func (ff *feedFollower) storePostIfNew(
accountHandle string,
postTime time.Time,
itm *gofeed.Item,
tootNew bool,
) (err error) {
var isNew bool
plainTitle := stripHtml(itm.Title)
Expand All @@ -437,14 +445,14 @@ func (ff *feedFollower) storePostIfNew(
}
if isNew {
ff.metrics.NewPostSaved()
if err = ff.createToot(accountId, accountHandle, itm, tootNew); err != nil {
if err = ff.createToot(accountId, accountHandle, itm); err != nil {
return
}
}
return
}

func (ff *feedFollower) createToot(accountId int, accountHandle string, itm *gofeed.Item, sendToot bool) error {
func (ff *feedFollower) createToot(accountId int, accountHandle string, itm *gofeed.Item) error {
prettyUrl := itm.Link
prettyUrl = strings.TrimPrefix(prettyUrl, "http://")
prettyUrl = strings.TrimPrefix(prettyUrl, "https://")
Expand All @@ -471,10 +479,8 @@ func (ff *feedFollower) createToot(accountId int, accountHandle string, itm *gof
if err != nil {
return err
}
if sendToot {
if err = ff.messenger.EnqueueBroadcast(accountHandle, statusId, tootedAt, content); err != nil {
return err
}
if err = ff.messenger.EnqueueBroadcast(accountHandle, statusId, tootedAt, content); err != nil {
return err
}
return nil
}
Expand Down