in my application I have several Users that can be friends. Now I am trying to build a function that gets the "friendShipStatus" from the current logged in user to another User. This is a follow up question from this one: Intersection of promises and dependent computed properties
/**
* Gives the relation between two User
* 4: has requested your friendship
* 3: Yourself
* 2: Friends
* 1: FriendShip Request
*/
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')
The Promise stuff is already an attempt, but not working. I would rather prefer to have the currentUser injected and observe then the property, that as soon as the current user is resolved the property changes. My attempt therefore:
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.injection('controller:application', 'currentUser', 'user:current');
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 have already tried it with a type injection and a regular injection. But within my usermodel my currentUser property is always undefined.
How can I inject the current User into my User Model?