How to know if user is using a default avatar

I want to encourage my users to upload an avatar via api.
How can I know a user is using default avatar in discourse? because I don’t want to warn users that already have gravatars or their custom avatars set.

I don’t know if its a good solution, but my solution for now is to look for gravatar_avatar_upload_id and custom_avatar_upload_id in /users/{username}.json and to see if they are both set to null.

Any idea?

2 Likes

I think it is the correct solution for you. For my knowledge only three types of avatars are there in Discourse (letter, gravatar and custom avatars). So it must work.

Out of curiosity: do you know we already show a JIT message to users with default avatar?

https://github.com/discourse/discourse/blob/d27575176a274ddee7513fb2d43aa9e453f9a68b/lib/composer_messages_finder.rb#L58-L81

3 Likes

Yes I know. But I have implemented discourse in my application and users mostly post there. So i don’t know If this JIT message could be get with an api call. If it could be, I can call it when users perform some actions inside the application. But if it couldn’t be called with api call, I need to write a custom code for it.

These education messages are associated with the composer. I don’t know the exact endpoint, but I’m pretty sure you can get them via the API since it’s working in Discourse :wink:

So how should I reverse engineer it? Any idea? I need to make an account without avatar and wait for this message to appear? This is somehow awkward.

The endpoint is /composer_messages.json :wink:

1 Like

Thank you very much. But how I can actually use it? :thinking:
For example when user write their first topic in my app, I want to call this JIT and show the message.

You might want to look at the ComposerMessagesControllers’ source code :wink:

https://github.com/discourse/discourse/blob/master/app/controllers/composer_messages_controller.rb

3 Likes

To figure out the list you can use data explorer:

SELECT id user_id from users
WHERE uploaded_avatar_id IS NULL 
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.