How to know if user is using a default avatar


(Hosein Naseri) #1

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.


(Hosein Naseri) #2

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?


(Vinoth Kannan) #3

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.


(Régis Hanol) #4

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


(Hosein Naseri) #5

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.


(Régis Hanol) #6

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:


(Hosein Naseri) #7

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.


(Régis Hanol) #8

The endpoint is /composer_messages.json :wink:


(Hosein Naseri) #9

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.


(Régis Hanol) #10

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