Skip to content

Conversation

pfefferle
Copy link
Member

@pfefferle pfefferle commented Oct 20, 2025

Replaces legacy methods in Blocked_Actors, Followers, Following, and Interactions classes with new unified methods such as query(), get_many(), add(), remove(), and count(). Deprecated old methods and updated all usages throughout the codebase, including handlers, REST controllers, admin tables, integration, CLI, and tests, to use the new APIs. This improves consistency, maintainability, and clarity in collection handling.

Proposed changes:

  • Method renaming for consistency: add_follower()add(), get_followers()get_many(), count_followers()count(), etc.
  • Deprecated old methods are maintained with _deprecated_function() calls
  • All callsites updated across handlers, REST controllers, admin tables, CLI, tests, and integrations

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to '..'

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Replaces legacy methods in Blocked_Actors, Followers, Following, and Interactions classes with new unified methods such as query(), get_many(), add(), remove(), and count(). Deprecated old methods and updated all usages throughout the codebase, including handlers, REST controllers, admin tables, integration, CLI, and tests, to use the new APIs. This improves consistency, maintainability, and clarity in collection handling.
@pfefferle pfefferle self-assigned this Oct 20, 2025
@Copilot Copilot AI review requested due to automatic review settings October 20, 2025 09:45
@pfefferle pfefferle added [Type] Janitorial Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. labels Oct 20, 2025
@pfefferle pfefferle requested a review from obenland October 20, 2025 09:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors collection classes (Blocked_Actors, Followers, Following, and Interactions) to use unified, more consistent method names. The legacy methods are deprecated and replaced with clearer alternatives like query(), get_many(), add(), remove(), and count(). All usages throughout the codebase have been updated to use the new APIs.

Key changes:

  • Method renaming for consistency: add_follower()add(), get_followers()get_many(), count_followers()count(), etc.
  • Deprecated old methods are maintained with _deprecated_function() calls
  • All callsites updated across handlers, REST controllers, admin tables, CLI, tests, and integrations

Reviewed Changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
includes/collection/class-followers.php Refactored to use add(), get_many(), get_by_uri(), query(), count() methods; deprecated old methods
includes/collection/class-following.php Refactored to use query(), get_many(), count() methods; deprecated old methods
includes/collection/class-interactions.php Refactored to use get_by_id(), get_by_actor() methods; deprecated old methods
includes/collection/class-blocked-actors.php Refactored to use add(), remove(), query(), get_many() methods; deprecated old methods
includes/handler/class-follow.php Updated to use Followers::add()
includes/handler/class-delete.php Updated to use Interactions::get_by_actor() and get_by_id()
includes/rest/class-followers-controller.php Updated to use Followers::query()
includes/rest/class-following-controller.php Updated to use Following::query()
includes/wp-admin/table/class-followers.php Updated to use Follower_Collection::query() and count()
includes/wp-admin/table/class-following.php Updated to use Following_Collection::query() with inline meta_query setup
includes/wp-admin/table/class-blocked-actors.php Updated to use Blocked_Actors_Collection::query()
includes/class-moderation.php Updated to use Blocked_Actors::add(), remove(), get_many()
includes/class-migration.php Updated to use Followers::add() and get_many()
includes/functions.php Updated to use Followers::get_many() and count()
local/class-cli.php Updated to use Followers::add()
integration/class-enable-mastodon-apps.php Updated to use Followers::get_many() and count()
src/followers/render.php Updated to use Followers::query()
src/follow-me/render.php Updated to use Followers::count()
build/followers/render.php Updated to use Followers::query()
build/follow-me/render.php Updated to use Followers::count()
tests/phpunit/tests/* Updated all test files to use new method names

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pfefferle
Copy link
Member Author

I let claude analyze the current collections to remove redundant function naming and to unify them over all classes. It came up with query and get_many what I quite like!

Curious about your feedback @obenland

@Jiwoon-Kim
Copy link
Contributor

Jiwoon-Kim commented Oct 20, 2025

I think it’s a good idea to unify all interaction activities under the same logic.
However, Announce and QuoteRequest activities are not idempotent.
In Misskey, for example, users can renote multiple times and selectively undo specific activities.
On the other hand, activities like Like, Follow, and Block are idempotent and should be treated differently.
In Lemmy’s case, a Dislike action cancels out a Like, meaning that an actor should only be able to have either a Like or a Dislike active on a given object at any one time.

I’m not entirely sure how interactions actually work in the Fediverse implementation of Lemmy, but it seems that when you press Dislike after Like, the previous Like is automatically undone.

https://join-lemmy.org/docs/contributors/05-federation.html#undo-like-or-dislike-post-or-comment

@pfefferle
Copy link
Member Author

@Jiwoon-Kim this PR has nothing to do with Activities! Collections are meant to help with DB queries.

Copy link
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it!

For all the _deprecated_function() calls that are added, let's backslashit() and add a blank line after them? That way the return statements also have a blank line ahead of them. (It felt weird to add each instance as a suggestion and give you a wall of suggestions)

pfefferle and others added 9 commits October 20, 2025 16:41
Moved meta_query logic for pending and all followings into dedicated methods in Following_Collection, improving code reuse and clarity. Updated admin table to use these methods instead of duplicating query logic.
Renamed and refactored methods in Following_Collection to use query_pending and query_all for pending and all followings, improving code clarity and reducing duplication. Updated usages in admin table to match new method names.
Introduces get_pending_with_count() and get_all_with_count() methods to retrieve pending and all followings with total count for pagination. These methods are marked as deprecated in favor of query_pending() and query_all().
Replaces calls to Following::count and Following_Collection::count with count_by_status in Heartbeat and Following classes for more accurate status-based counting.
@pfefferle pfefferle merged commit 4c09cb8 into trunk Oct 20, 2025
14 of 15 checks passed
@pfefferle pfefferle deleted the unify-function-names branch October 20, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Follow Me [Block] Followers [Feature] Collections [Feature] REST API [Feature] WP Admin [Focus] Compatibility Ensuring the plugin plays well with other plugins [Focus] Editor Changes to the ActivityPub experience in the block editor Skip Changelog Disables the "Changelog Updated" action for PRs where changelog entries are not necessary. [Tests] Includes Tests [Type] Janitorial

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants