Chocobozzz / PeerTube

ActivityPub-federated video streaming platform using P2P directly in your web browser
https://joinpeertube.org/
GNU Affero General Public License v3.0
13.07k stars 1.5k forks source link

Plugin support for adding action links to users and comments #6264

Open kontrollanten opened 7 months ago

kontrollanten commented 7 months ago

Describe the problem to be solved

Spam protection plugins, like the akismet plugin, should have the possibility to mark existing users and comments as spam.

Describe the solution you would like

Possibility to add actions in the following places:

kontrollanten commented 7 months ago

I've started looking into this. It's pretty straight forward adding filters to be able to alter the dropdown action menus, but I got stuck onto two issues:

The first issue may not be a big deal, even though it will impair the UX. But the second issue must be handled in some way to solve this.

What about adding a trigger function to the plugin client API? The API could look like:

triggerAction('video-watch.comment-list.reload');
triggerAction('loading-indicator.load-start');
triggerAction('loading-indicator.load-end');

The triggerAction API may be useful in other cases as well. Any thoughts, @Chocobozzz ?

kontrollanten commented 1 month ago

Ping @Chocobozzz

Chocobozzz commented 1 month ago

Sorry for the late feedback! Seems like a good idea. Do you have an example of other plugin systems that use such a method to ask for the core client to perform actions?

kontrollanten commented 1 month ago

Unfortunately not

kontrollanten commented 1 month ago

Wordpress has something similar.

function example_callback( $arg1, $arg2 ) {
    // (maybe) do something with the args.
}
add_action( 'example_action', 'example_callback', 10, 2 );

/*
 * Trigger the actions by calling the 'example_callback()' function
 * that's hooked onto `example_action` above.
 *
 * - 'example_action' is the action hook.
 * - $arg1 and $arg2 are the additional arguments passed to the callback.
do_action( 'example_action', $arg1, $arg2 )

https://developer.wordpress.org/reference/functions/do_action/

In our case it can be translated to:

video-comments.component.ts

  ngOnInit () {
    addAction('video-watch.comment-list.reload', this.resetVideo)
    ...
  }

  ngOnDestroy () {
    removeAction('video-watch.comment-list.reload')
    ...
  }

plugin.js

const onClickSpamButton = () => {
  deleteComment()
  doAction('video-watch.comment-list.reload')
}
Chocobozzz commented 1 month ago

Seems interesting, plugins would also be able to add actions. I agree with the design!