Skip to content

Commit

Permalink
Step 6.11: Add chat name filter
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 22, 2016
1 parent 1f24459 commit fcde382
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/filters/chat-name.filter.js
@@ -0,0 +1,17 @@
import { _ } from 'meteor/underscore';
import { Meteor } from 'meteor/meteor';
import { Filter } from 'angular-ecmascript/module-helpers';

export default class ChatNameFilter extends Filter {
static $name = 'chatName'

filter(chat) {
if (!chat) return;

let otherId = _.without(chat.userIds, Meteor.userId())[0];
let otherUser = Meteor.users.findOne(otherId);
let hasName = otherUser && otherUser.profile && otherUser.profile.name;

return hasName ? otherUser.profile.name : chat.name || 'NO NAME';
}
}

0 comments on commit fcde382

Please sign in to comment.