In my application, I have several users who can be friends. Now I'm trying to create a function that receives "friendShipStatus" from the current logged in user to another user. This is the next question from this: Intersection of promises and dependent computed properties
friendShipStatus: function() {
return this.container.lookup('user:current').then(function(user){
if(this.get('friends').contains(user)){
return 2;
} else if(this.get('friendsWithMe').contains(user)){
return 4;
} else if(this.get('myFriends').contains(user)){
return 1;
} else if (this.get('id') === user.get('id')){
return 3;
} else {
return 0;
}
});
}.property('friends.@each')
Promise is already an attempt, but it does not work. I would rather have currentUser enter and observe the property then, that as soon as the current user is allowed, the property will change. Therefore, my attempt:
Ember.Application.initializer({
name: "currentUser",
initialize: function(container, application) {
var store = container.lookup('store:main');
container.register('user:current', store.find('user', 1), { instantiate: false, singleton: true });
}
});
Ember.Application.initializer({
name: "injectCurrentUser",
after: 'currentUser',
initialize: function(container) {
container.typeInjection('route', 'currentUser', 'user:current');
container.typeInjection('controller', 'currentUser', 'user:current');
container.typeInjection('model', 'currentUser', 'user:current');
container.injection('user:model', 'currentUser', 'user:current');
}
});
I already tried this with type injection and regular injection. But in my usermodel, the currentUser property is always undefined.
How can I insert the current user into my user model?