feat(account/preferences): Adds enableAutoAway and idleTimeLimit

Adds enableAutoAway and idleTimeLimit to the account preferences, and configures the startup.js to
these settings as well..
pull/8029/head
Armando Magalhaes 8 years ago
parent 078c38bcfc
commit 8a60466104
  1. 38
      client/startup/startup.js
  2. 4
      packages/rocketchat-ui-account/client/accountPreferences.html
  3. 40
      packages/rocketchat-ui-account/client/accountPreferences.js
  4. 5
      server/methods/saveUserPreferences.js
  5. 2
      server/publications/userData.js
  6. 105
      tests/end-to-end/ui/14-user-presence.js

@ -17,8 +17,18 @@ if (window.DISABLE_ANIMATION) {
Meteor.startup(function() {
TimeSync.loggingEnabled = false;
UserPresence.awayTime = 300000;
UserPresence.start();
const userHasPreferences = (user) => {
const userHasSettings = user.hasOwnProperty("settings");
if (!userHasSettings) {
return false;
}
return user.settings.hasOwnProperty("preferences");
};
// UserPresence.awayTime = 300000;
// UserPresence.start();
Meteor.subscribe('activeUsers');
Session.setDefault('AvatarRandom', 0);
@ -30,7 +40,7 @@ Meteor.startup(function() {
const defaultAppLanguage = function() {
let lng = window.navigator.userLanguage || window.navigator.language || 'en';
// Fix browsers having all-lowercase language settings eg. pt-br, en-us
// Fix browsers having all-lowercase language settings eg. pt-br, en-usbb
const re = /([a-z]{2}-)([a-z]{2})/;
if (re.test(lng)) {
lng = lng.replace(re, (match, ...parts) => {
@ -79,8 +89,24 @@ Meteor.startup(function() {
}
};
const defaultIdleTimeLimit = 300000;
Meteor.subscribe('userData', function() {
const userLanguage = Meteor.user() && Meteor.user().language ? Meteor.user().language : window.defaultUserLanguage();
const user = Meteor.user();
const userLanguage = user && user.language ? user.language : window.defaultUserLanguage();
console.log('Reconfiguring userpresence')
if (!userHasPreferences(user)) {
UserPresence.awayTime = 300000;
UserPresence.start();
} else {
UserPresence.awayTime = user.settings.preferences.idleTimeLimit || 300000;
if (user.settings.preferences.hasOwnProperty("enableAutoAway")) {
user.settings.preferences.enableAutoAway && UserPresence.start();
} else {
UserPresence.start();
}
}
if (localStorage.getItem('userLanguage') !== userLanguage) {
localStorage.setItem('userLanguage', userLanguage);
@ -94,8 +120,8 @@ Meteor.startup(function() {
return;
}
if (Meteor.user() && Meteor.user().status !== status) {
status = Meteor.user().status;
if (user && user.status !== status) {
status = user.status;
fireGlobalEvent('status-changed', status);
}
});

@ -30,8 +30,8 @@
<div class="input-line double-col" id="enableAutoAway">
<label>{{_ "Enable_Auto_Away"}}</label>
<div>
<label><input type="radio" name="enableAutoAway" value="1" checked="{{checked 'enableAutoAway' true true}}"/> {{_ "True"}}</label>
<label><input type="radio" name="enableAutoAway" value="0" checked="{{checked 'enableAutoAway' false}}"/> {{_ "False"}}</label>
<label><input type="radio" name="enableAutoAway" value="1" checked="{{ checked 'enableAutoAway' true true }}"/> {{_ "True"}}</label>
<label><input type="radio" name="enableAutoAway" value="0" checked="{{ checked 'enableAutoAway' false }}"/> {{_ "False"}}</label>
</div>
</div>

@ -7,6 +7,18 @@ const notificationLabels = {
nothing: 'Nothing'
};
const DEFAULT_IDLE_TIME_LIMIT = 300000;
const userHasPreferences = (user) => {
const userHasSettings = user.hasOwnProperty("settings");
if (!userHasSettings) {
return false;
}
return user.settings.hasOwnProperty("preferences");
};
Template.accountPreferences.helpers({
showMergedChannels() {
return ['category', 'unread'].includes(Template.instance().roomsListExhibitionMode.get()) ? '' : 'disabled';
@ -44,14 +56,18 @@ Template.accountPreferences.helpers({
},
checked(property, value, defaultValue) {
const user = Meteor.user();
const propertyeExists = !!(user && user.settings && user.settings.preferences && user.settings.preferences[property]);
let currentValue;
if (propertyeExists) {
currentValue = !!user.settings.preferences[property];
} else if (!propertyeExists && defaultValue === true) {
currentValue = value;
if (!userHasPreferences(user)) {
return defaultValue;
}
const userPreferences = user.settings.preferences;
if (userPreferences.hasOwnProperty(property)) {
return value === userPreferences[property];
}
return currentValue === value;
return defaultValue;
},
selected(property, value, defaultValue) {
const user = Meteor.user();
@ -85,8 +101,12 @@ Template.accountPreferences.helpers({
defaultDesktopNotificationDuration() {
return RocketChat.settings.get('Desktop_Notifications_Duration');
},
idleTimeLimit() {
const user = Meteor.user();
return (user && user.settings && user.settings.preferences && user.settings.preferences.idleTimeLimit) || DEFAULT_IDLE_TIME_LIMIT;
},
defaultIdleTimeLimit() {
return RocketChat.settings.get('Idle_Time_Limit');
return DEFAULT_IDLE_TIME_LIMIT;
},
defaultDesktopNotification() {
return notificationLabels[RocketChat.settings.get('Desktop_Notifications_Default_Alert')];
@ -164,11 +184,9 @@ Template.accountPreferences.onCreated(function() {
data.mobileNotifications = $('#mobileNotifications').find('select').val();
data.unreadAlert = $('#unreadAlert').find('input:checked').val();
data.enableAutoAway = $('#enableAutoAway').find('input:checked').val();
data.idleTimeLimit = $('input[name=idleTimeLimit]').val();
data.idleTimeLimit = parseInt($('input[name=idleTimeLimit]').val());
data.notificationsSoundVolume = parseInt($('#notificationsSoundVolume').val());
console.log(data);
Meteor.call('saveUserPreferences', data, function(error, results) {
if (results) {
toastr.success(t('Preferences_saved'));

@ -72,6 +72,11 @@ Meteor.methods({
if (settings.mobileNotifications) {
preferences.mobileNotifications = settings.mobileNotifications;
}
if (settings.idleTimeLimit) {
preferences.idleTimeLimit = settings.idleTimeLimit;
}
preferences.enableAutoAway = settings.enableAutoAway === '1';
preferences.audioNotificationValue = settings.audioNotificationValue - 0;
preferences.desktopNotificationDuration = settings.desktopNotificationDuration - 0;

@ -14,6 +14,8 @@ Meteor.publish('userData', function() {
utcOffset: 1,
language: 1,
settings: 1,
enableAutoAway: 1,
idleTimeLimit: 1,
roles: 1,
active: 1,
defaultRoom: 1,

@ -1,41 +1,84 @@
/* eslint-env mocha */
/* eslint-disable func-names, prefer-arrow-callback */
// /* eslint-env mocha */
// /* eslint-disable func-names, prefer-arrow-callback */
import flexTab from '../../pageobjects/flex-tab.page';
import mainContent from '../../pageobjects/main-content.page';
import sideNav from '../../pageobjects/side-nav.page';
// import flexTab from '../../pageobjects/flex-tab.page';
// import mainContent from '../../pageobjects/main-content.page';
// import sideNav from '../../pageobjects/side-nav.page';
//test data imports
import {checkIfUserIsValid} from '../../data/checks';
import {username, email, password} from '../../data/user.js';
// //test data imports
// import {checkIfUserIsValid} from '../../data/checks';
// import {username, email, password} from '../../data/user.js';
describe.only('[User Presence]', function() {
// describe.only('[User Presence] @watch', function() {
// before(()=>{
// checkIfUserIsValid(username, email, password);
// sideNav.spotlightSearch.waitForVisible(10000);
// sideNav.searchChannel('general');
// });
before(()=>{
checkIfUserIsValid(username, email, password);
sideNav.spotlightSearch.waitForVisible(10000);
sideNav.searchChannel('general');
});
// it('should always render accountStatusBullet', function() {
// sideNav.accountStatusBullet.isVisible().should.be.true;
// });
it('should always render accountStatusBullet', function() {
sideNav.accountStatusBullet.isVisible().should.be.true;
});
// it('should show status as online at first', function() {
// sideNav.accountStatusBullet.isVisible().should.be.true;
// sideNav.accountStatusBulletOnline.isVisible().should.be.true;
// });
it('should show status as online at first', function() {
sideNav.accountStatusBullet.isVisible().should.be.true;
sideNav.accountStatusBulletOnline.isVisible().should.be.true;
});
// it('should show status as away when not focused on tab', function() {
// const currentTab = browser.getCurrentTabId();
// const temporaryTab = browser.newWindow('http://google.com');
it('should show status as away when not focused on tab', function() {
const currentTab = browser.getCurrentTabId();
const temporaryTab = browser.newWindow('http://google.com');
// browser.switchTab(temporaryTab);
browser.switchTab(temporaryTab);
// sideNav.accountStatusBullet.isVisible().should.be.true;
// sideNav.accountStatusBulletOnline.isVisible().should.be.false;
// sideNav.accountStatusBulletAway.isVisible().should.be.true;
// });
sideNav.accountStatusBullet.isVisible().should.be.true;
sideNav.accountStatusBulletOnline.isVisible().should.be.false;
sideNav.accountStatusBulletAway.isVisible().should.be.true;
});
// it('should show status as away when not interacting with the window for more than 10 seconds', function() {
// sideNav.accountStatusBulletOnline.isVisible().should.be.true;
it('should show status as online again when focusing on tab');
});
// // 10 seconds without interaction.
// sideNav.accountStatusBulletAway.waitForVisible(10000);
// sideNav.accountStatusBulletAway.isVisible().should.be.true;
// sideNav.accountStatusBulletOnline.isVisible().should.be.false;
// });
// it('should show status as online after interacting for the first time in a long time', function() {
// sideNav.accountStatusBulletOnline.isVisible().should.be.true;
// // 10 seconds without interaction.
// sideNav.accountStatusBulletAway.waitForVisible(10000);
// // expect user to be shown as away
// sideNav.accountStatusBulletAway.isVisible().should.be.true;
// sideNav.accountStatusBulletOnline.isVisible().should.be.false;
// // make interactions
// mainContent.sendMessage("This is a interaction");
// // expect user to be shown as online again
// sideNav.accountStatusBulletAway.isVisible().should.be.false;
// sideNav.accountStatusBulletOnline.isVisible().should.be.true;
// });
// it('should show status as online again when focusing on tab', function() {
// const appTab = browser.getCurrentTabId();
// const temporaryTab = browser.newWindow('http://google.com');
// browser.switchTab(temporaryTab);
// sideNav.accountStatusBullet.isVisible().should.be.true;
// sideNav.accountStatusBulletOnline.isVisible().should.be.false;
// sideNav.accountStatusBulletAway.isVisible().should.be.true;
// browser.switchTab(appTab);
// sideNav.accountStatusBullet.isVisible().should.be.true;
// sideNav.accountStatusBulletOnline.isVisible().should.be.true;
// sideNav.accountStatusBulletAway.isVisible().should.be.false;
// });
// });

Loading…
Cancel
Save