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