Permalink
Browse files

Refactor for some juicy fat models.

  • Loading branch information...
queso committed May 25, 2015
1 parent 80e65bc commit 85b39a63734dec32148773e063420a7c91004528
@@ -5,7 +5,7 @@
<ul id="userList" class="hidden">
{{#each allUsersExceptMe}}
<li class="list-users">
- <a class="createDirectChannel" href="#"><b class="user-circle-{{userStatusLabel}}">&#8226;</b> {{username}}</a>
+ <a class="createDirectChannel" href="#"><b class="user-circle-{{online}}">&#8226;</b> {{username}}</a>
</li>
{{/each}}
</ul>
@@ -23,7 +23,7 @@
<ul>
{{#each directChannels}}
<li class="{{activeChannelClass}}">
- <a href="{{pathFor 'channel' team=currentTeam.slug channel=slug}}">{{channelName}}</a>
+ <a href="{{pathFor 'channel' team=currentTeam.slug channel=slug}}"><b class="user-circle-{{otherUser.online}}">&#8226; </b>{{channelName}}</a>
</li>
{{/each}}
</ul>
@@ -46,7 +46,7 @@
</ul>
</div>
<div class="left-sidebar-user">
- <img src="{{currentUserAvatar}}" class="user-avatar">
+ <img src="{{currentUser.avatar}}" class="user-avatar">
<a href="#">{{currentUser.username}}</a>
<button type="button" class="left-sidebar-user-show-dropdown"><i class="fa fa-angle-up"></i></button>
</div>
@@ -5,16 +5,8 @@ LeftSidebar = BlazeComponent.extendComponent({
directChannels: function() {
return Channels.find( { teamId: currentTeamId(), direct: true } );
},
- userStatusLabel: function () {
- var parent = this.currentData();
- var statusLabel = parent.status.online ? 'online' : parent.status.idle ? 'idle' : 'offline';
- return statusLabel;
- },
- currentUserAvatar: function () {
- var user = Meteor.user();
- if (user && user.emails) {
- return Gravatar.imageUrl(user.emails[0].address);
- }
+ currentUser: function () {
+ return Meteor.user();
},
activeChannelClass: function () {
return currentChannelId() == this.currentData()._id ? 'active' : '';
View
@@ -2,9 +2,12 @@ Channels = new Mongo.Collection('channels');
Channels.friendlySlugs();
Channels.helpers({
- directChannelName: function() {
+ otherUser: function() {
otherNameId = _.reject(this.allowedUsers, function(u) {return u === Meteor.userId();})[0];
- user = Meteor.users.findOne(otherNameId);
+ return Meteor.users.findOne(otherNameId);
+ },
+ directChannelName: function() {
+ user = this.otherUser();
if (user) {
return user.username;
}
@@ -15,14 +18,5 @@ Channels.helpers({
} else {
return this.name;
}
- }
-});
-
-Channels.allow({
- insert: function (userId, doc) {
- if (userId) {
- // Shouldn't this be locked down now that we are using a method?
- return true;
- }
- }
+ },
});
View
@@ -0,0 +1,18 @@
+Users = Meteor.users
+
+Users.helpers({
+ avatar: function() {
+ if (this.emails) {
+ return Gravatar.imageUrl(this.emails[0].address);
+ }
+ },
+ online: function() {
+ if (this.status.online) {
+ return "online";
+ } else if (this.status.idle) {
+ return 'idle';
+ } else {
+ return 'offline';
+ }
+ }
+});

0 comments on commit 85b39a6

Please sign in to comment.