Hey all, I’m trying to work through an issue in the user-private-messages
controller in a theme.
Here’s what I’m trying to do.
- In the
user/messages
template, add content if there are fewer than 5 private messages in the list.
Example:
{{#if showMessagesCTA}}
<p>Hey here I am!</p>
{{/if}}
- I’m modifying the
user-private-messages
controller to add theshowMessagesCTA
method, as this appears where the template pulls logic from. The data I need is in theuser-topics-list
model, in particular thetopics
array.
Example:
api.modifyClass("controller:user-private-messages", {
showMessagesCTA: function() {
let userTopicsListModel = api.container.lookup("controller:user-topics-list").get('model');
if (userTopicsListModel && userTopicsListModel.topics){
return userTopicsListModel.topics.length() < 5;
} else {
return false;
}
}.property()
});
The problem I’m running into is the model always returns null
. I’m guessing this is a timing issue because the user-private-messages
controller loads prior to user-topic-list
. When I log just the user-topics-list
controller, it shows up but is greyed out. Clicking into it shows all the data, but it’s clearly not accessible in the app.
Is there a better way to approach accessing this data I’m not accounting for?