Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

feat(ap): remove featured servers from following lists

Gabe Kangas886799b1ade1
diff --git a/db/query.sql b/db/query.sql
index cf61138323..2c5c4f5544 100644
--- a/db/query.sql
+++ b/db/query.sql
@@ -3,13 +3,19 @@
-- Federation related queries.
-- name: GetFollowerCount :one
-SELECT count(*) FROM ap_followers WHERE approved_at is not null;
+-- Featured-streams follows (another Owncast server following us so it can show
+-- our live status in its directory) are excluded: they are a directory
+-- relationship, not a fan follow, so they must not inflate the follower count.
+SELECT count(*) FROM ap_followers WHERE approved_at is not null AND owncast_server IS NOT 1;
-- name: GetLocalPostCount :one
SELECT count(*) FROM ap_outbox;
-- name: GetFederationFollowersWithOffset :many
-SELECT iri, inbox, shared_inbox, name, username, image, created_at FROM ap_followers WHERE approved_at is not null ORDER BY created_at DESC LIMIT ? OFFSET ?;
+-- Excludes featured-streams (Owncast-server) follows so they don't show up in
+-- the public or admin followers list; they are tracked as a directory
+-- relationship, not surfaced as followers.
+SELECT iri, inbox, shared_inbox, name, username, image, created_at FROM ap_followers WHERE approved_at is not null AND owncast_server IS NOT 1 ORDER BY created_at DESC LIMIT ? OFFSET ?;
-- name: GetRejectedAndBlockedFollowers :many
SELECT iri, name, username, image, created_at, disabled_at FROM ap_followers WHERE disabled_at is not null;
diff --git a/db/query.sql.go b/db/query.sql.go
index 9d79676f0a..141f0283ee 100644
--- a/db/query.sql.go
+++ b/db/query.sql.go
@@ -364,7 +364,7 @@ func (q *Queries) GetFederationFollowerApprovalRequests(ctx context.Context) ([]
}
const getFederationFollowersWithOffset = `-- name: GetFederationFollowersWithOffset :many
-SELECT iri, inbox, shared_inbox, name, username, image, created_at FROM ap_followers WHERE approved_at is not null ORDER BY created_at DESC LIMIT ? OFFSET ?
+SELECT iri, inbox, shared_inbox, name, username, image, created_at FROM ap_followers WHERE approved_at is not null AND owncast_server IS NOT 1 ORDER BY created_at DESC LIMIT ? OFFSET ?
`
type GetFederationFollowersWithOffsetParams struct {
@@ -382,6 +382,9 @@ type GetFederationFollowersWithOffsetRow struct {
CreatedAt sql.NullTime
}
+// Excludes featured-streams (Owncast-server) follows so they don't show up in
+// the public or admin followers list; they are tracked as a directory
+// relationship, not surfaced as followers.
func (q *Queries) GetFederationFollowersWithOffset(ctx context.Context, arg GetFederationFollowersWithOffsetParams) ([]GetFederationFollowersWithOffsetRow, error) {
rows, err := q.db.QueryContext(ctx, getFederationFollowersWithOffset, arg.Limit, arg.Offset)
if err != nil {
@@ -455,11 +458,14 @@ func (q *Queries) GetFollowerByIRI(ctx context.Context, iri string) (GetFollower
const getFollowerCount = `-- name: GetFollowerCount :one
-SELECT count(*) FROM ap_followers WHERE approved_at is not null
+SELECT count(*) FROM ap_followers WHERE approved_at is not null AND owncast_server IS NOT 1
`
// Queries added to query.sql must be compiled into Go code with sqlc. Read README.md for details.
// Federation related queries.
+// Featured-streams follows (another Owncast server following us so it can show
+// our live status in its directory) are excluded: they are a directory
+// relationship, not a fan follow, so they must not inflate the follower count.
func (q *Queries) GetFollowerCount(ctx context.Context) (int64, error) {
row := q.db.QueryRowContext(ctx, getFollowerCount)
var count int64
diff --git a/services/activitypub/inbox/follow.go b/services/activitypub/inbox/follow.go
index a482a4ea20..e6ccc529aa 100644
--- a/services/activitypub/inbox/follow.go
+++ b/services/activitypub/inbox/follow.go
@@ -53,7 +53,18 @@ func (s *Service) handleFollowInboxRequest(c context.Context, activity vocab.Act
log.Errorln("unable to send follow accept", err)
return err
}
- go s.webhooks.SendFediverseEngagementFollowEvent(actorIRI)
+ // Don't fire the follower webhook for featured-streams follows.
+ if !followRequest.IsOwncastServer {
+ go s.webhooks.SendFediverseEngagementFollowEvent(actorIRI)
+ }
+ }
+
+ // A Follow from another Owncast server is a featured-streams directory
+ // relationship, not a fan follow. It is kept and accepted above because we
+ // need it to deliver stream-status pings to that server, but it must not
+ // be surfaced as a new follower in chat or the activity feed.
+ if followRequest.IsOwncastServer {
+ return nil
}
// If this request is approved and we have not previously sent an action to
diff --git a/services/activitypub/persistence/followersrepository/followersrepository.go b/services/activitypub/persistence/followersrepository/followersrepository.go
index 577b371a13..9248356cb5 100644
--- a/services/activitypub/persistence/followersrepository/followersrepository.go
+++ b/services/activitypub/persistence/followersrepository/followersrepository.go
@@ -248,7 +248,7 @@ func (r *SqlFollowersRepository) Add(follow apmodels.ActivityPubActor, approved
return errors.Wrap(err, "error serializing follow request object")
}
- return r.createFollow(follow.ActorIriString(), follow.InboxString(), follow.SharedInboxString(), follow.FollowRequestIriString(), follow.Name, follow.Username, follow.ImageString(), followRequestObject, approved)
+ return r.createFollow(follow.ActorIriString(), follow.InboxString(), follow.SharedInboxString(), follow.FollowRequestIriString(), follow.Name, follow.Username, follow.ImageString(), followRequestObject, approved, follow.IsOwncastServer)
}
// Remove removes a follow from the datastore.
@@ -309,7 +309,7 @@ func (r *SqlFollowersRepository) Update(actorIRI string, inbox string, sharedInb
return tx.Commit()
}
-func (r *SqlFollowersRepository) createFollow(actor, inbox, sharedInbox, request, name, username, image string, requestObject []byte, approved bool) error {
+func (r *SqlFollowersRepository) createFollow(actor, inbox, sharedInbox, request, name, username, image string, requestObject []byte, approved, owncastServer bool) error {
r.datastore.DbLock.Lock()
defer r.datastore.DbLock.Unlock()
@@ -339,6 +339,7 @@ func (r *SqlFollowersRepository) createFollow(actor, inbox, sharedInbox, request
ApprovedAt: approvedAt,
Request: request,
RequestObject: requestObject,
+ OwncastServer: sql.NullBool{Bool: owncastServer, Valid: true},
}); err != nil {
return errors.Wrap(err, "error creating new federation follow")
}
diff --git a/test/automated/activitypub/test-featured-streams.sh b/test/automated/activitypub/test-featured-streams.sh
index c6c5bb4209..d9388fad2e 100755
--- a/test/automated/activitypub/test-featured-streams.sh
+++ b/test/automated/activitypub/test-featured-streams.sh
@@ -32,6 +32,9 @@
# stream and verify it flips back to offline promptly (the core of the
# feature, both directions). Streams automatically under CI; prompts when
# run interactively.
+# 10. Verify a server that features another (by following it) does NOT show up
+# in the followee's followers list or count -- a featured-streams follow is
+# a directory relationship, not a fan follow.
#
# Requirements:
# - Go, C compiler (for building Owncast)
@@ -689,6 +692,39 @@ test_live_status_flip() {
return 0
}
+test_featuring_server_hidden_from_followers() {
+ log_test "TEST 8: A server that features us is not shown as a follower"
+
+ # Instance 1 featured instance 2 by following it (TEST 1-2), so instance 1
+ # is technically a follower of instance 2. Because that is an
+ # Owncast-server (featured-streams) follow, it must NOT appear in instance
+ # 2's public followers list or follower count -- it's a directory
+ # relationship, not a fan. (Both instances only ever feature each other in
+ # this test, so the visible follower count should be zero.)
+ local actor_iri followers total failed=0
+ actor_iri="${OWNCAST_URL}/federation/user/${OWNCAST_FED_USERNAME}"
+ followers=$(curl -s "http://localhost:${OWNCAST2_PORT}/api/followers")
+ total=$(echo "${followers}" | jq -r '.total // 0' 2>/dev/null)
+
+ if echo "${followers}" | jq -e --arg iri "${actor_iri}" '.results[]? | select(.link == $iri)' > /dev/null 2>&1; then
+ log_error "TEST 8 FAILED: featuring server ${actor_iri} appears in instance 2's followers list"
+ failed=1
+ fi
+
+ if [[ "${total}" != "0" ]]; then
+ log_error "TEST 8 FAILED: instance 2 follower count is ${total}, expected 0 (its only follow is a featured-streams follow)"
+ failed=1
+ fi
+
+ if [[ ${failed} -ne 0 ]]; then
+ log_error "Followers response: ${followers}"
+ return 1
+ fi
+
+ log_test "TEST 8 PASSED: the featuring server is hidden from instance 2's followers (count=${total})"
+ return 0
+}
+
# ==========================
# Results
# ==========================
@@ -777,6 +813,8 @@ main() {
echo ""
if test_live_status_flip; then passed=$((passed + 1)); else failed=$((failed + 1)); fi
echo ""
+ if test_featuring_server_hidden_from_followers; then passed=$((passed + 1)); else failed=$((failed + 1)); fi
+ echo ""
print_results "${passed}" "${failed}"