Hello.
I'm trying to understand how the plugins work (there are a lot of messages ans indirection here and I'm kinda lost) so, decided to try to prototype a simple Gravatar plugin.
As I can see, this can be done in some ways.
1 - Start from the hello World Plugin and override the js/Components/PostUser and PostCard. The worst as there is no way to do this without coping the view and changing the avatarUrl value. Not OK.
2 - Start from the Hello World plugin, but change avatarUrl from js/helpers/avatar.js. A better option as we are not direct injecting things in the view, but we are calculating a md5 on the fly every request. Not OK.
3 - Go away from javascript and create and store the avatarUrl in gravatar format in the database. As Gravatar provides a fallback image we can simply update user.avatarUrl like this:
$avatarUrl = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($user->email))) . ".jpg";
$user->avatarUrl = $avatarUrl;
This sould be OK.
So, I think I need to:
a1 - trigger the operation for all users when the plug in is activated. So, I would to create a event in Gravatar/Event/GravatarActivated.php and register a subscriber in the bootstrap.php
a2 - trigger the operation when a user is created or updates his email. So, watches Flarum\Event\UserEmailWasChanged andregister a subscriber in the bootstrap.php
b - perform the operation, so put the snippet in the subscribed listener in Gravatar/Listener/UpdateAvatarUrl.php
This is the right way to do this or I lost something?