Skip to content
Snippets Groups Projects
Commit 42780a40 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #1818 from RocketChat/livechat-visitor-info

Livechat visitor info tabbar
parents 9c54bfa3 ac94b0a7
No related branches found
No related tags found
No related merge requests found
Showing
with 341 additions and 9 deletions
var api = {
pageVisited: function(info) {
Triggers.processRequest(info);
Meteor.call('livechat:pageVisited', visitor.getToken(), info);
}
};
......
......@@ -54,7 +54,7 @@ this.Triggers = (function() {
trigger.conditions.forEach(function(condition) {
switch (condition.name) {
case 'page-url':
if (request.href.match(new RegExp(condition.value))) {
if (request.location.href.match(new RegExp(condition.value))) {
fire(trigger.actions);
}
break;
......
......@@ -15,4 +15,4 @@
"Survey_instructions" : "Rate each question according to your satisfaction, 1 meaning you are completely unsatisfied and 5 meaning you are completely satisfied.",
"Thank_you_for_your_feedback" : "Thank you for your feedback",
"We_are_offline_Sorry_for_the_inconvenience" : "We are offline. Sorry for the inconvenience."
}
\ No newline at end of file
}
......@@ -19,6 +19,14 @@
<body style="background-color: #EFEFEF">
<h1 style="color:#000">test</h1>
<p style="color:#000">Talk to us.</p>
<a href="#page-0" onclick="document.title='page-0'">page 0</a><br>
<a href="#page-1" onclick="document.title='page-1'">page 1</a><br>
<a href="#page-2" onclick="document.title='page-2'">page 2</a><br>
<a href="#page-3" onclick="document.title='page-3'">page 3</a><br>
<a href="#page-4" onclick="document.title='page-4'">page 4</a><br>
<a href="#page-5" onclick="document.title='page-5'">page 5</a><br>
<a href="#page-6" onclick="document.title='page-6'">page 6</a><br>
</body>
</html>
......@@ -70,7 +70,10 @@
};
var pageVisited = function() {
callHook('pageVisited', JSON.parse(JSON.stringify(document.location)));
callHook('pageVisited', {
location: JSON.parse(JSON.stringify(document.location)),
title: document.title
});
};
var currentPage = {
......@@ -79,13 +82,13 @@
};
var trackNavigation = function() {
setInterval(function() {
if (document.title !== currentPage.title) {
if (document.location.href !== currentPage.href) {
pageVisited();
currentPage.href = document.location.href;
currentPage.title = document.title;
}
}, 500);
}, 800);
};
var initRocket = function(url) {
......
this.LivechatPageVisited = new Mongo.Collection('rocketchat_livechat_page_visited');
/**
* UAParser.js v0.7.10
* Lightweight JavaScript-based User-Agent string parser
* https://github.com/faisalman/ua-parser-js
*
* Copyright © 2012-2015 Faisal Salman <fyzlman@gmail.com>
* Dual licensed under GPLv2 & MIT
*/(function(e,t){"use strict";var n="0.7.10",r="",i="?",s="function",o="undefined",u="object",a="string",f="major",l="model",c="name",h="type",p="vendor",d="version",v="architecture",m="console",g="mobile",y="tablet",b="smarttv",w="wearable",E="embedded",S={extend:function(e,t){for(var n in t)"browser cpu device engine os".indexOf(n)!==-1&&t[n].length%2===0&&(e[n]=t[n].concat(e[n]));return e},has:function(e,t){return typeof e=="string"?t.toLowerCase().indexOf(e.toLowerCase())!==-1:!1},lowerize:function(e){return e.toLowerCase()},major:function(e){return typeof e===a?e.split(".")[0]:t}},x={rgx:function(){var e,n=0,r,i,a,f,l,c,h=arguments;while(n<h.length&&!l){var p=h[n],d=h[n+1];if(typeof e===o){e={};for(a in d)d.hasOwnProperty(a)&&(f=d[a],typeof f===u?e[f[0]]=t:e[f]=t)}r=i=0;while(r<p.length&&!l){l=p[r++].exec(this.getUA());if(!!l)for(a=0;a<d.length;a++)c=l[++i],f=d[a],typeof f===u&&f.length>0?f.length==2?typeof f[1]==s?e[f[0]]=f[1].call(this,c):e[f[0]]=f[1]:f.length==3?typeof f[1]===s&&(!f[1].exec||!f[1].test)?e[f[0]]=c?f[1].call(this,c,f[2]):t:e[f[0]]=c?c.replace(f[1],f[2]):t:f.length==4&&(e[f[0]]=c?f[3].call(this,c.replace(f[1],f[2])):t):e[f]=c?c:t}n+=2}return e},str:function(e,n){for(var r in n)if(typeof n[r]===u&&n[r].length>0){for(var s=0;s<n[r].length;s++)if(S.has(n[r][s],e))return r===i?t:r}else if(S.has(n[r],e))return r===i?t:r;return e}},T={browser:{oldsafari:{version:{"1.0":"/8",1.2:"/1",1.3:"/3","2.0":"/412","2.0.2":"/416","2.0.3":"/417","2.0.4":"/419","?":"/"}}},device:{amazon:{model:{"Fire Phone":["SD","KF"]}},sprint:{model:{"Evo Shift 4G":"7373KT"},vendor:{HTC:"APA",Sprint:"Sprint"}}},os:{windows:{version:{ME:"4.90","NT 3.11":"NT3.51","NT 4.0":"NT4.0",2e3:"NT 5.0",XP:["NT 5.1","NT 5.2"],Vista:"NT 6.0",7:"NT 6.1",8:"NT 6.2",8.1:"NT 6.3",10:["NT 6.4","NT 10.0"],RT:"ARM"}}}},N={browser:[[/(opera\smini)\/([\w\.-]+)/i,/(opera\s[mobiletab]+).+version\/([\w\.-]+)/i,/(opera).+version\/([\w\.]+)/i,/(opera)[\/\s]+([\w\.]+)/i],[c,d],[/\s(opr)\/([\w\.]+)/i],[[c,"Opera"],d],[/(kindle)\/([\w\.]+)/i,/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?([\w\.]+)*/i,/(avant\s|iemobile|slim|baidu)(?:browser)?[\/\s]?([\w\.]*)/i,/(?:ms|\()(ie)\s([\w\.]+)/i,/(rekonq)\/([\w\.]+)*/i,/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt|iron|vivaldi|iridium|phantomjs)\/([\w\.-]+)/i],[c,d],[/(trident).+rv[:\s]([\w\.]+).+like\sgecko/i],[[c,"IE"],d],[/(edge)\/((\d+)?[\w\.]+)/i],[c,d],[/(yabrowser)\/([\w\.]+)/i],[[c,"Yandex"],d],[/(comodo_dragon)\/([\w\.]+)/i],[[c,/_/g," "],d],[/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?([\w\.]+)/i,/(qqbrowser)[\/\s]?([\w\.]+)/i],[c,d],[/(uc\s?browser)[\/\s]?([\w\.]+)/i,/ucweb.+(ucbrowser)[\/\s]?([\w\.]+)/i,/JUC.+(ucweb)[\/\s]?([\w\.]+)/i],[[c,"UCBrowser"],d],[/(dolfin)\/([\w\.]+)/i],[[c,"Dolphin"],d],[/((?:android.+)crmo|crios)\/([\w\.]+)/i],[[c,"Chrome"],d],[/XiaoMi\/MiuiBrowser\/([\w\.]+)/i],[d,[c,"MIUI Browser"]],[/android.+version\/([\w\.]+)\s+(?:mobile\s?safari|safari)/i],[d,[c,"Android Browser"]],[/FBAV\/([\w\.]+);/i],[d,[c,"Facebook"]],[/fxios\/([\w\.-]+)/i],[d,[c,"Firefox"]],[/version\/([\w\.]+).+?mobile\/\w+\s(safari)/i],[d,[c,"Mobile Safari"]],[/version\/([\w\.]+).+?(mobile\s?safari|safari)/i],[d,c],[/webkit.+?(mobile\s?safari|safari)(\/[\w\.]+)/i],[c,[d,x.str,T.browser.oldsafari.version]],[/(konqueror)\/([\w\.]+)/i,/(webkit|khtml)\/([\w\.]+)/i],[c,d],[/(navigator|netscape)\/([\w\.-]+)/i],[[c,"Netscape"],d],[/(swiftfox)/i,/(icedragon|iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?([\w\.\+]+)/i,/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/([\w\.-]+)/i,/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i,/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|sleipnir)[\/\s]?([\w\.]+)/i,/(links)\s\(([\w\.]+)/i,/(gobrowser)\/?([\w\.]+)*/i,/(ice\s?browser)\/v?([\w\._]+)/i,/(mosaic)[\/\s]([\w\.]+)/i],[c,d]],cpu:[[/(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i],[[v,"amd64"]],[/(ia32(?=;))/i],[[v,S.lowerize]],[/((?:i[346]|x)86)[;\)]/i],[[v,"ia32"]],[/windows\s(ce|mobile);\sppc;/i],[[v,"arm"]],[/((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i],[[v,/ower/,"",S.lowerize]],[/(sun4\w)[;\)]/i],[[v,"sparc"]],[/((?:avr32|ia64(?=;))|68k(?=\))|arm(?:64|(?=v\d+;))|(?=atmel\s)avr|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i],[[v,S.lowerize]]],device:[[/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i],[l,p,[h,y]],[/applecoremedia\/[\w\.]+ \((ipad)/],[l,[p,"Apple"],[h,y]],[/(apple\s{0,1}tv)/i],[[l,"Apple TV"],[p,"Apple"]],[/(archos)\s(gamepad2?)/i,/(hp).+(touchpad)/i,/(kindle)\/([\w\.]+)/i,/\s(nook)[\w\s]+build\/(\w+)/i,/(dell)\s(strea[kpr\s\d]*[\dko])/i],[p,l,[h,y]],[/(kf[A-z]+)\sbuild\/[\w\.]+.*silk\//i],[l,[p,"Amazon"],[h,y]],[/(sd|kf)[0349hijorstuw]+\sbuild\/[\w\.]+.*silk\//i],[[l,x.str,T.device.amazon.model],[p,"Amazon"],[h,g]],[/\((ip[honed|\s\w*]+);.+(apple)/i],[l,p,[h,g]],[/\((ip[honed|\s\w*]+);/i],[l,[p,"Apple"],[h,g]],[/(blackberry)[\s-]?(\w+)/i,/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola|polytron)[\s_-]?([\w-]+)*/i,/(hp)\s([\w\s]+\w)/i,/(asus)-?(\w+)/i],[p,l,[h,g]],[/\(bb10;\s(\w+)/i],[l,[p,"BlackBerry"],[h,g]],[/android.+(transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+|nexus 7)/i],[l,[p,"Asus"],[h,y]],[/(sony)\s(tablet\s[ps])\sbuild\//i,/(sony)?(?:sgp.+)\sbuild\//i],[[p,"Sony"],[l,"Xperia Tablet"],[h,y]],[/(?:sony)?(?:(?:(?:c|d)\d{4})|(?:so[-l].+))\sbuild\//i],[[p,"Sony"],[l,"Xperia Phone"],[h,g]],[/\s(ouya)\s/i,/(nintendo)\s([wids3u]+)/i],[p,l,[h,m]],[/android.+;\s(shield)\sbuild/i],[l,[p,"Nvidia"],[h,m]],[/(playstation\s[34portablevi]+)/i],[l,[p,"Sony"],[h,m]],[/(sprint\s(\w+))/i],[[p,x.str,T.device.sprint.vendor],[l,x.str,T.device.sprint.model],[h,g]],[/(lenovo)\s?(S(?:5000|6000)+(?:[-][\w+]))/i],[p,l,[h,y]],[/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i,/(zte)-(\w+)*/i,/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]+)*/i],[p,[l,/_/g," "],[h,g]],[/(nexus\s9)/i],[l,[p,"HTC"],[h,y]],[/[\s\(;](xbox(?:\sone)?)[\s\);]/i],[l,[p,"Microsoft"],[h,m]],[/(kin\.[onetw]{3})/i],[[l,/\./g," "],[p,"Microsoft"],[h,g]],[/\s(milestone|droid(?:[2-4x]|\s(?:bionic|x2|pro|razr))?(:?\s4g)?)[\w\s]+build\//i,/mot[\s-]?(\w+)*/i,/(XT\d{3,4}) build\//i,/(nexus\s[6])/i],[l,[p,"Motorola"],[h,g]],[/android.+\s(mz60\d|xoom[\s2]{0,2})\sbuild\//i],[l,[p,"Motorola"],[h,y]],[/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9|nexus 10))/i,/((SM-T\w+))/i],[[p,"Samsung"],l,[h,y]],[/((s[cgp]h-\w+|gt-\w+|galaxy\snexus|sm-n900))/i,/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,/sec-((sgh\w+))/i],[[p,"Samsung"],l,[h,g]],[/(samsung);smarttv/i],[p,l,[h,b]],[/\(dtv[\);].+(aquos)/i],[l,[p,"Sharp"],[h,b]],[/sie-(\w+)*/i],[l,[p,"Siemens"],[h,g]],[/(maemo|nokia).*(n900|lumia\s\d+)/i,/(nokia)[\s_-]?([\w-]+)*/i],[[p,"Nokia"],l,[h,g]],[/android\s3\.[\s\w;-]{10}(a\d{3})/i],[l,[p,"Acer"],[h,y]],[/android\s3\.[\s\w;-]{10}(lg?)-([06cv9]{3,4})/i],[[p,"LG"],l,[h,y]],[/(lg) netcast\.tv/i],[p,l,[h,b]],[/(nexus\s[45])/i,/lg[e;\s\/-]+(\w+)*/i],[l,[p,"LG"],[h,g]],[/android.+(ideatab[a-z0-9\-\s]+)/i],[l,[p,"Lenovo"],[h,y]],[/linux;.+((jolla));/i],[p,l,[h,g]],[/((pebble))app\/[\d\.]+\s/i],[p,l,[h,w]],[/android.+;\s(glass)\s\d/i],[l,[p,"Google"],[h,w]],[/android.+(\w+)\s+build\/hm\1/i,/android.+(hm[\s\-_]*note?[\s_]*(?:\d\w)?)\s+build/i,/android.+(mi[\s\-_]*(?:one|one[\s_]plus)?[\s_]*(?:\d\w)?)\s+build/i],[[l,/_/g," "],[p,"Xiaomi"],[h,g]],[/\s(tablet)[;\/\s]/i,/\s(mobile)[;\/\s]/i],[[h,S.lowerize],p,l]],engine:[[/windows.+\sedge\/([\w\.]+)/i],[d,[c,"EdgeHTML"]],[/(presto)\/([\w\.]+)/i,/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i,/(khtml|tasman|links)[\/\s]\(?([\w\.]+)/i,/(icab)[\/\s]([23]\.[\d\.]+)/i],[c,d],[/rv\:([\w\.]+).*(gecko)/i],[d,c]],os:[[/microsoft\s(windows)\s(vista|xp)/i],[c,d],[/(windows)\snt\s6\.2;\s(arm)/i,/(windows\sphone(?:\sos)*|windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i],[c,[d,x.str,T.os.windows.version]],[/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i],[[c,"Windows"],[d,x.str,T.os.windows.version]],[/\((bb)(10);/i],[[c,"BlackBerry"],d],[/(blackberry)\w*\/?([\w\.]+)*/i,/(tizen)[\/\s]([\w\.]+)/i,/(android|webos|palm\sos|qnx|bada|rim\stablet\sos|meego|contiki)[\/\s-]?([\w\.]+)*/i,/linux;.+(sailfish);/i],[c,d],[/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i],[[c,"Symbian"],d],[/\((series40);/i],[c],[/mozilla.+\(mobile;.+gecko.+firefox/i],[[c,"Firefox OS"],d],[/(nintendo|playstation)\s([wids34portablevu]+)/i,/(mint)[\/\s\(]?(\w+)*/i,/(mageia|vectorlinux)[;\s]/i,/(joli|[kxln]?ubuntu|debian|[open]*suse|gentoo|(?=\s)arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk|linpus)[\/\s-]?([\w\.-]+)*/i,/(hurd|linux)\s?([\w\.]+)*/i,/(gnu)\s?([\w\.]+)*/i],[c,d],[/(cros)\s[\w]+\s([\w\.]+\w)/i],[[c,"Chromium OS"],d],[/(sunos)\s?([\w\.]+\d)*/i],[[c,"Solaris"],d],[/\s([frentopc-]{0,4}bsd|dragonfly)\s?([\w\.]+)*/i],[c,d],[/(ip[honead]+)(?:.*os\s([\w]+)*\slike\smac|;\sopera)/i],[[c,"iOS"],[d,/_/g,"."]],[/(mac\sos\sx)\s?([\w\s\.]+\w)*/i,/(macintosh|mac(?=_powerpc)\s)/i],[[c,"Mac OS"],[d,/_/g,"."]],[/((?:open)?solaris)[\/\s-]?([\w\.]+)*/i,/(haiku)\s(\w+)/i,/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i,/(plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos|openvms)/i,/(unix)\s?([\w\.]+)*/i],[c,d]]},C=function(t,n){if(this instanceof C){var i=t||(e&&e.navigator&&e.navigator.userAgent?e.navigator.userAgent:r),s=n?S.extend(N,n):N;return this.getBrowser=function(){var e=x.rgx.apply(this,s.browser);return e.major=S.major(e.version),e},this.getCPU=function(){return x.rgx.apply(this,s.cpu)},this.getDevice=function(){return x.rgx.apply(this,s.device)},this.getEngine=function(){return x.rgx.apply(this,s.engine)},this.getOS=function(){return x.rgx.apply(this,s.os)},this.getResult=function(){return{ua:this.getUA(),browser:this.getBrowser(),engine:this.getEngine(),os:this.getOS(),device:this.getDevice(),cpu:this.getCPU()}},this.getUA=function(){return i},this.setUA=function(e){return i=e,this},this.setUA(i),this}return(new C(t,n)).getResult()};C.VERSION=n,C.BROWSER={NAME:c,MAJOR:f,VERSION:d},C.CPU={ARCHITECTURE:v},C.DEVICE={MODEL:l,VENDOR:p,TYPE:h,CONSOLE:m,MOBILE:g,SMARTTV:b,TABLET:y,WEARABLE:w,EMBEDDED:E},C.ENGINE={NAME:c,VERSION:d},C.OS={NAME:c,VERSION:d},typeof exports!==o?(typeof module!==o&&module.exports&&(exports=module.exports=C),exports.UAParser=C):typeof define===s&&define.amd?define(function(){return C}):e.UAParser=C;var k=e.jQuery||e.Zepto;if(typeof k!==o){var L=new C;k.ua=L.getResult(),k.ua.get=function(){return L.getUA()},k.ua.set=function(e){L.setUA(e);var t=L.getResult();for(var n in t)k.ua[n]=t[n]}}})(typeof window=="object"?window:this);
......@@ -437,3 +437,56 @@
height: 24px;
}
}
.user-view {
li {
color: @secondary-font-color;
line-height: 18px;
font-size: 12px;
font-weight: 300;
}
}
.icon-chat-empty.status-offline {
color: @status-offline;
}
.icon-chat-empty.status-online {
color: @status-online;
}
.icon-chat-empty.status-busy {
color: @status-busy;
}
.icon-chat-empty.status-away {
color: @status-away;
}
.visitor-navigation {
height: 130px;
overflow-y: auto;
border: 1px solid #E7E7E7;
border-radius: 4px;
padding: 4px;
margin-top: 4px;
ul {
li {
white-space: nowrap;
a {
text-overflow: ellipsis;
display: block;
overflow: hidden;
color: @secondary-font-color;
text-decoration: underline;
&:hover {
text-decoration: none;
}
}
}
}
}
RocketChat.theme.addPackageAsset(() => {
return Assets.getText('client/stylesheets/livechat.less');
});
......@@ -7,6 +7,7 @@ RocketChat.roomTypes.add('l', 5, {
action: (params, queryParams) => {
Session.set('showUserInfo');
openRoom('l', params.name);
RocketChat.TabBar.showGroup('livechat', 'search');
},
link: (sub) => {
return {
......@@ -28,3 +29,16 @@ AccountBox.addItem({
return RocketChat.settings.get('Livechat_enabled') && RocketChat.authz.hasAllPermission('view-livechat-manager');
},
});
RocketChat.TabBar.addButton({
groups: ['livechat'],
id: 'visitor-info',
i18nTitle: 'Visitor_Info',
icon: 'octicon octicon-info',
template: 'visitorInfo',
order: 0
});
RocketChat.TabBar.addGroup('message-search', ['livechat']);
RocketChat.TabBar.addGroup('starred-messages', ['livechat']);
RocketChat.TabBar.addGroup('uploaded-files-list', ['livechat']);
<template name="visitorInfo">
<div class="content">
<div class="user-view">
{{#with user}}
<div class="about clearfix">
<div class="thumb">
{{> avatar username=username}}
</div>
<div class="info">
<h3 title="{{username}}"><i class="status-{{status}}"></i> {{username}}</h3>
<p>{{name}}</p>
<ul>
{{#if utc}}<li><i class="icon-clock"></i>{{userTime}} (UTC {{utc}})</li>{{/if}}
{{#each emails}} <li><i class="icon-mail"></i> {{address}}{{#if verified}}&nbsp;<i class="icon-ok"></i>{{/if}}</li> {{/each}}
{{#each phone}} <li><i class="icon-phone"></i> {{phoneNumber}}</li> {{/each}}
{{#if lastLogin}} <li><i class="icon-calendar"></i> {{_ "Created_at"}}: {{createdAt}}</li> {{/if}}
{{#if lastLogin}} <li><i class="icon-calendar"></i> {{_ "Last_login"}}: {{lastLogin}}</li> {{/if}}
{{#if ip}}<li><i class="icon-laptop"></i><span>{{ip}}</span></li>{{/if}}
{{#if os}}<li><i class="{{osIcon}}"></i><span>{{os}}</span></li>{{/if}}
{{#if browser}}<li><i class="{{browserIcon}}"></i><span>{{browser}}</span></li>{{/if}}
</ul>
</div>
</div>
{{/with}}
<nav>
<!-- <button class="button pvt-msg"><span><i class="icon-forward"></i> {{_ "Forward"}}</span></button> -->
</nav>
<h4>{{_ "Navigation_History_20_last_pages"}}</h4>
<div class="visitor-navigation">
{{#if loadingNavigation}}
{{_ "Loading..."}}
{{else}}
<ul>
{{#each pageVisited}}
<li><a href="{{page.location.href}}" target="_blank" title="{{accessDateTime}}">{{pageTitle}}</a></li>
{{/each}}
</ul>
{{/if}}
</div>
</div>
</div>
</template>
Template.visitorInfo.helpers({
user() {
var user = Meteor.users.findOne({ "profile.token": Template.instance().visitorToken.get() });
if (user && user.userAgent) {
var ua = new UAParser();
ua.setUA(user.userAgent);
user.os = ua.getOS().name + ' ' + ua.getOS().version;
if (['Mac OS', 'iOS'].indexOf(ua.getOS().name) !== -1) {
user.osIcon = 'icon-apple';
} else {
user.osIcon = 'icon-' + ua.getOS().name.toLowerCase();
}
user.browser = ua.getBrowser().name + ' ' + ua.getBrowser().version;
user.browserIcon = 'icon-' + ua.getBrowser().name.toLowerCase();
}
return user;
},
loadingNavigation() {
return !Template.instance().pageVisited.ready();
},
pageVisited() {
return LivechatPageVisited.find({ token: Template.instance().visitorToken.get() }, { sort: { ts: -1 } });
},
pageTitle() {
return this.page.title || t('Empty_title');
},
accessDateTime() {
return moment(this.ts).format('L LTS');
},
createdAt() {
if (!this.createdAt) {
return '';
}
return moment(this.createdAt).format('L LTS');
},
lastLogin() {
if (!this.lastLogin) {
return '';
}
return moment(this.lastLogin).format('L LTS');
}
});
Template.visitorInfo.onCreated(function() {
this.visitorToken = new ReactiveVar(null);
var currentData = Template.currentData();
if (currentData && currentData.rid) {
this.autorun(() => {
var room = ChatRoom.findOne(currentData.rid);
if (room && room.v && room.v.token) {
this.visitorToken.set(room.v.token);
} else {
this.visitorToken.set();
}
});
this.subscribe('livechat:visitorInfo', currentData.rid);
this.pageVisited = this.subscribe('livechat:visitorPageVisited', currentData.rid);
}
})
......@@ -15,6 +15,7 @@
"Departments" : "Departments",
"Description" : "Description",
"Edit_Department" : "Edit Department",
"Empty_title" : "Empty title",
"Enable" : "Enable",
"Enabled" : "Enabled",
"Enter_a_regex" : "Enter a regex",
......@@ -31,6 +32,7 @@
"Manager_added" : "Manager added",
"Manager_removed" : "Manager removed",
"Name_of_agent" : "Name of agent",
"Navigation_History_20_last_pages" : "Navigation History (20 last pages)",
"New_Department" : "New Department",
"Num_Agents" : "# Agents",
"Opened" : "Opened",
......@@ -53,4 +55,4 @@
"Username_not_found" : "Username not found",
"Visitor_page_URL" : "Visitor page URL",
"Visitor_time_on_site" : "Visitor time on site"
}
\ No newline at end of file
}
......@@ -36,12 +36,15 @@ Package.onUse(function(api) {
api.addFiles('client/ui.js', 'client');
api.addFiles('client/route.js', 'client');
api.addFiles('client/stylesheets/livechat.less', 'client');
// add stylesheets to theme compiler
api.addAssets('client/stylesheets/livechat.less', 'server');
api.addFiles('client/stylesheets/load.js', 'server');
// collections
api.addFiles('client/collections/AgentUsers.js', 'client');
api.addFiles('client/collections/LivechatDepartment.js', 'client');
api.addFiles('client/collections/LivechatDepartmentAgents.js', 'client');
api.addFiles('client/collections/LivechatPageVisited.js', 'client');
api.addFiles('client/collections/LivechatTrigger.js', 'client');
// client views
......@@ -58,6 +61,10 @@ Package.onUse(function(api) {
api.addFiles('client/views/app/livechatTriggers.js', 'client');
api.addFiles('client/views/app/livechatUsers.html', 'client');
api.addFiles('client/views/app/livechatUsers.js', 'client');
api.addFiles('client/views/app/tabbar/visitorInfo.html', 'client');
api.addFiles('client/views/app/tabbar/visitorInfo.js', 'client');
api.addFiles('client/views/sideNav/livechat.html', 'client');
api.addFiles('client/views/sideNav/livechat.js', 'client');
api.addFiles('client/views/sideNav/livechatFlex.html', 'client');
......@@ -71,6 +78,7 @@ Package.onUse(function(api) {
// methods
api.addFiles('server/methods/addAgent.js', 'server');
api.addFiles('server/methods/addManager.js', 'server');
api.addFiles('server/methods/pageVisited.js', 'server');
api.addFiles('server/methods/registerGuest.js', 'server');
api.addFiles('server/methods/removeAgent.js', 'server');
api.addFiles('server/methods/removeDepartment.js', 'server');
......@@ -87,6 +95,7 @@ Package.onUse(function(api) {
api.addFiles('server/models/Rooms.js', 'server');
api.addFiles('server/models/LivechatDepartment.js', 'server');
api.addFiles('server/models/LivechatDepartmentAgents.js', 'server');
api.addFiles('server/models/LivechatPageVisited.js', 'server');
api.addFiles('server/models/LivechatTrigger.js', 'server');
// server lib
......@@ -96,9 +105,11 @@ Package.onUse(function(api) {
api.addFiles('server/publications/availableDepartments.js', 'server');
api.addFiles('server/publications/departmentAgents.js', 'server');
api.addFiles('server/publications/livechatAgents.js', 'server');
api.addFiles('server/publications/livechatManagers.js', 'server');
api.addFiles('server/publications/livechatDepartments.js', 'server');
api.addFiles('server/publications/livechatManagers.js', 'server');
api.addFiles('server/publications/trigger.js', 'server');
api.addFiles('server/publications/visitorInfo.js', 'server');
api.addFiles('server/publications/visitorPageVisited.js', 'server');
api.addFiles('server/publications/visitorRoom.js', 'server');
// livechat app
......
Meteor.methods({
'livechat:pageVisited' (token, pageInfo) {
return RocketChat.models.LivechatPageVisitied.saveByToken(token, pageInfo);
}
});
......@@ -20,7 +20,9 @@ Meteor.methods({
qt = Meteor.users.find({
'profile.guest': true
}).count() + 1;
user = 'guest-' + (qt + inc++);
userExists = Meteor.users.findOne({
'username': user
}, {
......@@ -28,7 +30,7 @@ Meteor.methods({
_id: 1
}
});
console.log('userExists ->',userExists);
if (!userExists) {
break;
}
......@@ -38,6 +40,11 @@ Meteor.methods({
globalRoles: ['livechat-guest'],
department: department
};
userData.userAgent = this.connection.httpHeaders['user-agent'];
userData.ip = this.connection.httpHeaders['x-real-ip'] || this.connection.clientAddress;
userData.host = this.connection.httpHeaders['host'];
userId = Accounts.insertUserDoc({}, userData);
updateUser = {
......@@ -62,6 +69,10 @@ Meteor.methods({
Meteor.users.update(userId, {
$set: updateUser
});
// update visited page history to not expire
RocketChat.models.LivechatPageVisitied.keepHistoryForToken(token);
return {
userId: userId,
token: stampedToken.token
......
/**
* Livechat Page Visited model
*/
class LivechatPageVisitied extends RocketChat.models._Base {
constructor() {
super();
this._initModel('livechat_page_visited');
this.tryEnsureIndex({ 'token': 1 });
this.tryEnsureIndex({ 'ts': 1 });
// keep history for 1 month if the visitor does not register
this.tryEnsureIndex({ 'expireAt': 1 }, { sparse: 1, expireAfterSeconds: 0 });
}
saveByToken(token, pageInfo) {
// keep history of unregistered visitors for 1 month
var keepHistoryMiliseconds = 2592000000;
return this.insert({
token: token,
page: pageInfo,
ts: new Date(),
expireAt: new Date().getTime() + keepHistoryMiliseconds
});
}
findByToken(token) {
return this.find({ token: token }, { sort : { ts: -1 }, limit: 20 });
}
keepHistoryForToken(token) {
return this.update({
token: token,
expireAt: {
$exists: true
}
}, {
$unset: {
expireAt: 1
}
}, {
multi: true
});
}
}
RocketChat.models.LivechatPageVisitied = new LivechatPageVisitied();
......@@ -92,3 +92,16 @@ RocketChat.models.Users.getVisitorByToken = function(token, options) {
return this.findOne(query, options);
};
/**
* Gets visitor by token
* @param {string} token - Visitor token
*/
RocketChat.models.Users.findVisitorByToken = function(token) {
var query = {
"profile.guest": true,
"profile.token": token
};
return this.find(query);
};
Meteor.publish('livechat:visitorInfo', function(roomId) {
if (!this.userId) {
throw new Meteor.Error('not-authorized');
}
if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
throw new Meteor.Error('not-authorized');
}
var room = RocketChat.models.Rooms.findOneById(roomId);
if (room && room.v && room.v.token) {
return RocketChat.models.Users.findVisitorByToken(room.v.token);
} else {
return this.ready();
}
});
Meteor.publish('livechat:visitorPageVisited', function(roomId) {
if (!this.userId) {
throw new Meteor.Error('not-authorized');
}
if (!RocketChat.authz.hasPermission(this.userId, 'view-l-room')) {
throw new Meteor.Error('not-authorized');
}
var room = RocketChat.models.Rooms.findOneById(roomId);
if (room && room.v && room.v.token) {
return RocketChat.models.LivechatPageVisitied.findByToken(room.v.token);
} else {
return this.ready();
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment