From 37d68fb3e8991e87e1d35c6d12dfd8bc00740f97 Mon Sep 17 00:00:00 2001 From: Kiran Rao Date: Tue, 24 Jan 2017 11:21:31 -0500 Subject: [PATCH] Refactor livechat sidenav --- .../client/views/sideNav/livechat.js | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/rocketchat-livechat/client/views/sideNav/livechat.js b/packages/rocketchat-livechat/client/views/sideNav/livechat.js index d716738f6a5..756a0e0b42b 100644 --- a/packages/rocketchat-livechat/client/views/sideNav/livechat.js +++ b/packages/rocketchat-livechat/client/views/sideNav/livechat.js @@ -1,45 +1,43 @@ /* globals LivechatInquiry, KonchatNotification */ Template.livechat.helpers({ isActive() { - if (ChatSubscription.findOne({ + const query = { t: 'l', - f: { - $ne: true - }, + f: { $ne: true }, open: true, rid: Session.get('openedRoom') - }, { - fields: { - _id: 1 - } - }) != null) { + }; + + const options = { fields: { _id: 1 } }; + + if (ChatSubscription.findOne(query, options)) { return 'active'; } }, + rooms() { - var query = { + const query = { t: 'l', open: true }; - const user = RocketChat.models.Users.findOne(Meteor.userId(), { fields: { 'settings.preferences.unreadRoomsMode': 1 } }); + const user = RocketChat.models.Users.findOne(Meteor.userId(), { + fields: { 'settings.preferences.unreadRoomsMode': 1 } + }); if (user && user.settings && user.settings.preferences && user.settings.preferences.unreadRoomsMode) { - query.alert = { - $ne: true - }; + query.alert = { $ne: true }; } - return ChatSubscription.find(query, { - sort: { - 't': 1, - 'name': 1 - } - }); + return ChatSubscription.find(query, { sort: { + 't': 1, + 'name': 1 + }}); }, + inquiries() { // get all inquiries of the department - var inqs = LivechatInquiry.find({ + const inqs = LivechatInquiry.find({ agents: Meteor.userId(), status: 'open' }, { @@ -49,15 +47,17 @@ Template.livechat.helpers({ }); // for notification sound - inqs.forEach(function(inq) { + inqs.forEach((inq) => { KonchatNotification.newRoom(inq.rid); }); return inqs; }, + guestPool() { return RocketChat.settings.get('Livechat_Routing_Method') === 'Guest_Pool'; }, + available() { const statusLivechat = Template.instance().statusLivechat.get(); @@ -67,6 +67,7 @@ Template.livechat.helpers({ hint: statusLivechat === 'available' ? t('Available') : t('Not_Available') }; }, + livechatAvailable() { return Template.instance().statusLivechat.get(); },