From fcde3824caa6dacc1e52ad47a474397a67c6b781 Mon Sep 17 00:00:00 2001 From: DAB0mB Date: Thu, 28 Apr 2016 13:14:52 +0300 Subject: [PATCH] Step 6.11: Add chat name filter --- src/filters/chat-name.filter.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/filters/chat-name.filter.js diff --git a/src/filters/chat-name.filter.js b/src/filters/chat-name.filter.js new file mode 100644 index 0000000..dbf0de7 --- /dev/null +++ b/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'; + } +} \ No newline at end of file