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

Add like handler #804

Merged
merged 28 commits into from
Aug 16, 2024
Merged

Add like handler #804

merged 28 commits into from
Aug 16, 2024

Conversation

janboddez
Copy link
Contributor

@janboddez janboddez commented Jul 10, 2024

Adds basic support for incoming likes (see #235).

Probably needs to go through a couple more iterations before it could be merged! For instance, the ActivityPub plugin should maybe also get a pre_get_comments filter, similar to the Webmention plugin, so that these "likes" don't show up among "regular comments." Should be "rather easy" to implement.

But it's a "first draft."

I originally wanted to also add "repost" support but noticed an announce handler already exists. I'm going to have to check that out later. Maybe in a different PR.

Edit: This won't actually display, e.g., a facepile. Though it currently is compatible with IndieBlocks' Facepile block. I can imagine you'd want to eventually add a block of your own ...

Proposed changes:

  • Adds a incoming like handler, and extends the existing undo handler to handle undoing of previous likes.

Note: I kept some of the actions from other reaction handlers and also set some comment meta to be able to later on display the like in a "facepile" kind of way. I also set some "dummy" content; feel free to change it in order to have it behave the same as, e.g., the Webmention plugin.

Other information:

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

Testing instructions:

  • Upload patched version
  • Search for a local URL from, e.g., your Mastodon instance
  • Like the corresponding post
  • Watch the "like" appear as a new comment with comment type "like"
  • Undo like
  • Watch the "like" comment move to trash

@janboddez
Copy link
Contributor Author

[T]he ActivityPub plugin should maybe also get a pre_get_comments filter, similar to the Webmention plugin, so that these "likes" don't show up among "regular comments."

On my personal site I don't need this, as I have my own such filter and block. But I thought I'd mention it.

@pfefferle
Copy link
Member

@janboddez thanks a lot!

Do you think we need a UI/setting for that? It might be confusing if "Like" comments will simply show up in the comment section after the next update!?!

@janboddez
Copy link
Contributor Author

janboddez commented Jul 11, 2024

Yes, I do think you will need a pre_get_comments filter to hide likes from the front end. And only show them through a shortcode or block (similar to IndieBlocks' Facepile block, or the Followers block), which could be added in a later version.

I'm not sure about showing/hiding them in WP-Admin. It could be confusing (for people who aren't familiar with, e.g., webmentions) to see "comments" in WP-Admin but not see them show up anywhere on the site. Hmm, maybe we need a completely separate WP-Admin (sub)menu for "likes"?

Or you could put the whole functionality behind a constant or something, so that "advanced" users (who might have their own means of displaying likes) can choose to enable it at their own risk.

@janboddez janboddez marked this pull request as draft July 11, 2024 13:38
@pfefferle
Copy link
Member

@janboddez I refactored the code a bit and also added Announce support!

What do you think?

I am not very happy with the add_reaction method in the Interactions class, because I think this could be simplified a lot, but it should work for now!

Maybe we also hide it behind a feature flag, to run some tests and think about a nicer UI?

/cc @mattwiebe

@pfefferle pfefferle marked this pull request as ready for review August 9, 2024 15:06
@janboddez
Copy link
Contributor Author

Cool!

Feature flag (like a PHP constant?) seems like a good idea! I can imagine most people wanting to have this disabled or at least not show the likes/reposts until there's something like a Facepile block (or some other way of displaying likes/reposts, like a counter of sorts). Not everyone will want to install IndieBlocks either, haha!

Are the register_comment_type() calls compatible with, e.g., the Webmention plugin? Won't it complain if the same type is registered "twice"? (Just asking, I honestly have no clue.)

@pfefferle
Copy link
Member

Feature flag (like a PHP constant?) seems like a good idea! I can imagine most people wanting to have this disabled or at least not show the likes/reposts until there's something like a Facepile block (or some other way of displaying likes/reposts, like a counter of sorts). Not everyone will want to install IndieBlocks either, haha!

Yes!

Are the register_comment_type() calls compatible with, e.g., the Webmention plugin? Won't it complain if the same type is registered "twice"? (Just asking, I honestly have no clue.)

Kind of both! The ActivityPub version is stripped down a lot, so they are not completely identical, but they use the same vocabulary, so that there is no difference between a Webmention Like and an ActivityPub Like in the end.

@pfefferle pfefferle requested a review from mattwiebe August 14, 2024 08:29
@pfefferle pfefferle merged commit dabff80 into Automattic:master Aug 16, 2024
11 checks passed
@janboddez
Copy link
Contributor Author

Silly question: Do we also need some custom CSS to make likes look "good" in WP's dashboard? Like in pfefferle/wordpress-webmention#396.

Didn't yet have a chance to test, but basically the question is: How do [likes and reposts] look (in the dashboard) with the Webmention plugin turned off?

@pfefferle
Copy link
Member

The Webmention Plugin does not change the UI of the dashboard!

@janboddez
Copy link
Contributor Author

Oh, I thought we added a bit of CSS to make like and reposts avatars behave.

@pfefferle
Copy link
Member

You are totally right! I will add that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants