pixelfed / pixelfed

Photo Sharing. For Everyone.
https://pixelfed.org
GNU Affero General Public License v3.0
5.65k stars 677 forks source link

Pixelfed is reporting 0 posts, following, and followers via the ActivityPub collections #4082

Open AlternateRT opened 1 year ago

AlternateRT commented 1 year ago

I recently began following the official Pixelfed account from pixelfed.social in my Mastodon instance (social.vivaldi.net) when I realised that the posts, following, and followers counts were all weirdly wrong. This is what I see from my instance:

Screenshot 2023-01-12 at 21 44 51

Instead, it should be displaying the same numbers that are displayed when viewing the profile from pixelfed.social:

Screenshot 2023-01-12 at 21 57 29
mitexleo commented 1 year ago

It's displaying the followers count from Vivaldi Social. I mean How many people are interacting with Pixelfed Account from that instance...

AlternateRT commented 1 year ago

@neonota Ok, sure, but that doesn't explain why the post count is wrong (my instance is aware of the 10 posts the accopunt has made). And why not display the same followers count for the account like it is done in pixelfed.social, or how other Mastodon accounts do so when viewed in another different Mastodon instances?

Additionally, if I force fetch this account by searching for it with its URL, the three counts are all reset back to 0 :/

trwnh commented 1 year ago

hm, the reason that pixelfed@pixelfed.social is being set to 0 is because the collections seem to be advertising 0 totalItems:

$ curl -H 'Accept: application/ld+json; profile="https://www.w3.org/ns/activitystreams"' https://pixelfed.social/users/pixelfed/followers

{"@context":"https:\/\/www.w3.org\/ns\/activitystreams","id":"https:\/\/pixelfed.social\/users\/pixelfed\/followers","type":"OrderedCollectionPage","totalItems":0,"orderedItems":[]}

if i had to guess, something isn't wired up right -- this is expected behaviour for profiles that hide their followers, but not expected for profiles that don't hide their network. the outbox thing is just an oversight though

silsha commented 1 year ago

I looked into this problem today. The reason seems to be that it is hardcoded as 0.

https://github.com/pixelfed/pixelfed/blob/d5baf2627a6292c253d9cb2d4d271003de81891c/app/Http/Controllers/FederationController.php#L238-L265

I got it working by replacing the functions with this code:

public function userFollowing(Request $request, $username)
{
    abort_if(!config_cache('federation.activitypub.enabled'), 404);

    $profile = Profile::whereNull('domain')->whereUsername($username)->first();

    if (!$profile) {
        abort(404);  // No profile found
    }

    $following = $profile->following;
    $followingCount = $following->count();
    $followingUsernames = $following->pluck('remote_url')->toArray();

    $obj = [
        '@context' => 'https://www.w3.org/ns/activitystreams',
        'id'       => $request->getUri(),
        'type'     => 'OrderedCollectionPage',
        'totalItems' => $followingCount,
        'orderedItems' => $followingUsernames
    ];

    return response()->json($obj);
}

public function userFollowers(Request $request, $username)
{
    abort_if(!config_cache('federation.activitypub.enabled'), 404);

    $profile = Profile::whereNull('domain')->whereUsername($username)->first();

    if (!$profile) {
        abort(404);  // No profile found
    }

    $followers = $profile->followers;
    $followersCount = $followers->count();
    $followersUsernames = $followers->pluck('remote_url')->toArray();

    $obj = [
        '@context' => 'https://www.w3.org/ns/activitystreams',
        'id'       => $request->getUri(),
        'type'     => 'OrderedCollectionPage',
        'totalItems' => $followersCount,
        'orderedItems' => $followersUsernames
    ];

    return response()->json($obj);
}

This seems to work for Mastodon grafik

I don't know anything about ActivityPub in general or the pixelfed codebase, so I don't feel comfortable opening a pull request for this. I don't know if I'm breaking anything or revealing information I shouldn't be revealing. But maybe this will help someone else to try and fix this problem.

Edit: Looks like this feature broke in this commit https://github.com/pixelfed/pixelfed/commit/7f4213924f9fdb14bb36043d17615e838b85b733#diff-b5309ee63eb1e5952f25c891ab227586940466a8b775b68e293f1b11ed865ed6R135-R180