samedi 21 février 2015

Preload Badges on Discourse in plugin init

My question is related to my answer on loading badges. When a plugin for discourse loads, how can I get the badges for that user during the init method of the plugin?


e.g.



export default {
name: "my_plugin",
initialize: function(container, application) {
Discourse.ShowAds = true;
var currentUser = Discourse.User.current();
if (currentUser) {
//Get badges here or have badges already.
}
}
};


Something like this will not work because the promise will return the badges after the view is loaded.



export default {
name: "my_plugin",
initialize: function(container, application) {
var currentUser = Discourse.User.current();
if (currentUser) {
Discourse.UserBadge.findByUsername(Discourse.User.current().username).then(function(result) {
result.forEach(function(entry) {
if (entry.badge.name == Discourse.SiteSettings.adsense_through_badge){
console.log(entry.badge.name);
}
}
);
});
}
}
};


I'm thinking I need to extend a controller or some other functionality to get the badges prior to the plugin loading so it could be retrieved like trust_level although I'm not sure where I would extend it.



var currentUser = Discourse.User.current();
currentUser.get('trust_level')

Aucun commentaire:

Enregistrer un commentaire