Getting data for the widget

I don’t want to use this approach in widgets:

$.ajax({
  url: "/u/"+ username +".json", 
  dataType: 'json',
  async: false,
  success: function(data) {
	
  ....data.user.time_read;

Is there any other way to get this variable: time_read? This is an example.

from the template

discourse/app/assets/javascripts/discourse/templates/discovery.hbs

through

{{plugin-outlet name="discovery-list-container-top"
                        args=(hash category=category listLoading=loading)}}

no data is transmitted.

Is there any other way (other than json) to get this data (time_read, badge_count etc.)

Extras. currentUser does not have this data.

Thank

Do you only need it for the current user?

Yes. Only for this user.

You might try something like this:

DiscoursePluginRegistry.serialized_current_user_fields << 'recent_time_read'

to add it to the serialized current user.

User.current().recent_time_read

Keep in mind that this will only be serialized once, on app load, and that to get an updated value you’ll either need to query for it directly, or use MessageBus to ‘live update’ the user’s read_time.

1 Like

What is the best way to do that is with minimal load.?

This method is not quite suitable.