Skip to content

Commit

Permalink
fix error when profile.friends was undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman committed Jul 13, 2014
1 parent 1500513 commit c4b86e7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions client/views/userProfile.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
Template.userProfile.isOwner = function() {
return Meteor.userId() == this._id;
}
};

Template.userProfile.rendered = function() {
Session.setDefault("showEditAvatarBar",false);
}
};

Template.userProfile.userFriends = function() {
return Meteor.users.find({_id: {$in: this.profile.friends}});
}
var friends = this.profile.friends || [];
return Meteor.users.find({_id: {$in: friends}});
};

Template.userProfile.avatarUrl = function() {
if(this.profile.avatar) {
if(this.profile.avatar) {
return this.profile.avatar;
} else {
return "/img/avatar.jpg";
}
}
};

Template.userProfile.events = {
'click [data-action="set-username"]': function() {
Expand All @@ -32,7 +34,7 @@ Template.userProfile.events = {
'click div.avatar': function() {
Router.go('userProfile', {_id: this._id});
}
}
};

Template.userPlaylist.songCount = function() {
if(this.songs) {
Expand All @@ -42,7 +44,7 @@ Template.userPlaylist.songCount = function() {
return this.songs.length + " songs";
}
}
}
};

Template.editAvatar.events = {
'click [data-action="update-avatar"]': function() {
Expand All @@ -53,11 +55,11 @@ Template.editAvatar.events = {
{$set: {'profile.avatar':avatar}});
Session.set("showEditAvatarBar",false);
}
}
};

Template.addRemoveFriend.isFriend = function() {
return _.contains(Meteor.user().profile.friends,this._id);
}
};

Template.addRemoveFriend.events = {
'click [data-action="add-friend"]': function() {
Expand All @@ -72,4 +74,4 @@ Template.addRemoveFriend.events = {
{ $pull : { 'profile.friends': this._id }}
);
}
}
};

0 comments on commit c4b86e7

Please sign in to comment.