self unfollow function return self object promise then function return

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
self.unfollow = function() {
return self.object.$promise.then(function() {
return self.object.$unfollow();
}).then(function() {
self.object.following = false;
return self.followers.$promise;
}).then(function() {
var currentUserObjects = self.followers.filter(function(user) {
return user.id === self.currentUser.id;
});
if (currentUserObjects.length > 0) {
var currentUserIndex = self.followers.indexOf(currentUserObjects[0]);
self.followers.splice(currentUserIndex, 1);
}
});
};