Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Option to enable/disable auto away and configure timer #8029

Merged
merged 21 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1bdbb04
feat(user-presence): some tests
armand1m Aug 27, 2017
5b39a7e
feat(rocketchat-ui): Adds user presence fieldset and some fields.
armand1m Aug 29, 2017
078c38b
feat(i18n): added some english statements for Auto Away
armand1m Sep 2, 2017
8a60466
feat(account/preferences): Adds enableAutoAway and idleTimeLimit
armand1m Sep 3, 2017
4b358a5
style(linting): fixes linting
armand1m Sep 3, 2017
61927a7
refactor(clean): removes dead and unnecessary code
armand1m Sep 3, 2017
8604d91
style(client/startup): removes comments
armand1m Sep 3, 2017
99c9678
style(assets): remove screenshots
armand1m Sep 3, 2017
1945d30
Merge branch 'develop' into feature/user-presence
Oct 2, 2017
9e5f185
Merge branch 'develop' into feature/user-presence
rodrigok Dec 4, 2017
54bd7ed
fix(garbage): removing dead and unused code
armand1m Dec 5, 2017
3e40952
fix(account-preferences): reload browser when changing auto away sett…
armand1m Dec 5, 2017
7a53f49
feat(i18n): adds translations to Portuguese and Deutsch.
armand1m Dec 5, 2017
02e18fb
refactor(account-preferences): remove dead code
armand1m Dec 5, 2017
9132d3f
fix(i18n-pt-BR): fixes "ausência" word
armand1m Dec 5, 2017
19d78c6
fix(i18n-de): fixes Enable_Auto_Away key
armand1m Dec 5, 2017
a190b3c
Merge branch 'develop' into feature/user-presence
Dec 5, 2017
d3cde02
test(e2e): Fixes e2e tests in User Options
armand1m Dec 5, 2017
c7ef2f7
fix(i18n): Fixes internationalization mistake
armand1m Dec 5, 2017
65c754c
Merge branch 'develop' into feature/user-presence
Dec 5, 2017
e66d237
Update accountPreferences.js
rodrigok Dec 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions client/startup/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ if (window.DISABLE_ANIMATION) {
Meteor.startup(function() {
TimeSync.loggingEnabled = false;

UserPresence.awayTime = 300000;
UserPresence.start();
const userHasPreferences = (user) => {
if (!user) {
return false;
}

const userHasSettings = user.hasOwnProperty('settings');

if (!userHasSettings) {
return false;
}

return user.settings.hasOwnProperty('preferences');
};

Meteor.subscribe('activeUsers');

Session.setDefault('AvatarRandom', 0);
Expand Down Expand Up @@ -79,8 +91,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();

if (!userHasPreferences(user)) {
UserPresence.awayTime = defaultIdleTimeLimit;
UserPresence.start();
} else {
UserPresence.awayTime = user.settings.preferences.idleTimeLimit || defaultIdleTimeLimit;

if (user.settings.preferences.hasOwnProperty('enableAutoAway')) {
user.settings.preferences.enableAutoAway && UserPresence.start();
} else {
UserPresence.start();
}
}

if (localStorage.getItem('userLanguage') !== userLanguage) {
localStorage.setItem('userLanguage', userLanguage);
Expand All @@ -94,8 +122,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);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2007,4 +2007,4 @@
"your_message_optional": "ihre optionale Nachricht",
"Your_password_is_wrong": "Falsches Passwort",
"Your_push_was_sent_to_s_devices": "Eine Push-Nachricht wurde an %s Geräte gesendet."
}
}
5 changes: 4 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,10 @@
"Empty_title": "Empty title",
"Enable": "Enable",
"Enable_Desktop_Notifications": "Enable Desktop Notifications",
"Enable_Svg_Favicon": "Enable SVG favicon",
"Enable_two-factor_authentication": "Enable two-factor authentication",
"Enabled": "Enabled",
"Enable_Auto_Away": "Enable Auto Away",
"Enable_Svg_Favicon": "Enable SVG favicon",
"Encrypted_message": "Encrypted message",
"End_OTR": "End OTR",
"Enter_a_regex": "Enter a regex",
Expand Down Expand Up @@ -944,6 +945,7 @@
"IssueLinks_LinkTemplate": "Template for issue links",
"IssueLinks_LinkTemplate_Description": "Template for issue links; %s will be replaced by the issue number.",
"It_works": "It works",
"Idle_Time_Limit": "Idle Time Limit",
"italics": "italics",
"Jitsi_Chrome_Extension": "Chrome Extension Id",
"Jitsi_Enable_Channels": "Enable in Channels",
Expand Down Expand Up @@ -1953,6 +1955,7 @@
"User_updated_successfully": "User updated successfully",
"User_uploaded_file": "Uploaded a file",
"User_uploaded_image": "Uploaded an image",
"User_Presence": "User Presence",
"Username": "Username",
"Username_and_message_must_not_be_empty": "Username and message must not be empty.",
"Username_cant_be_empty": "The username cannot be empty",
Expand Down
5 changes: 4 additions & 1 deletion packages/rocketchat-i18n/i18n/nl.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
"Duplicate_archived_private_group_name": "Een gearchiveerde privé-group met naam '%s' bestaat al",
"Duplicate_channel_name": "Een kanaal met de naam '% s' bestaat al",
"Duplicate_private_group_name": "Een privé-groep met de naam '%s' bestaat al",
"Enable_Auto_Away": "Schakel Auto Away in",
"Edit": "Wijzig",
"Edit_Custom_Field": "Bewerken Aangepast veld",
"Edit_Department": "Afdeling bewerken",
Expand Down Expand Up @@ -512,6 +513,7 @@
"Invalid_secret_URL_message": "De gegeven URL is ongeldig.",
"invisible": "onzichtbaar",
"Invisible": "Onzichtbaar",
"Idle_Time_Limit": "Niet-actieve tijdslimiet",
"Invitation_HTML": "Uitnodiging HTML",
"Invitation_HTML_Default": "<h2> Je bent uitgenodigd voor <h1> [Site_Name] </h1></h2><p> Ga naar [Site_URL] en probeer de beste open source chat-oplossing die vandaag beschikbaar zijn! </p>",
"Invitation_HTML_Description": "U mag de volgende plaatshouders gebruiken: <br /><ul><li> [email] voor de ontvanger e-mail. </li><li> [Site_Name] en [Site_URL] voor de toepassing Naam en URL respectievelijk. </li></ul>",
Expand Down Expand Up @@ -1130,6 +1132,7 @@
"Username_is_already_in_here": "`@%s` is al hier.",
"Username_is_not_in_this_room": "De gebruiker `#%s` is niet in deze kamer.",
"Username_title": "Registreer Gebruikersnaam",
"User_Presence": "Aanwezigheid van de gebruiker",
"Username_wants_to_start_otr_Do_you_want_to_accept": "__username__ wil OTR starten. Heeft u wilt accepteren?",
"Users": "Gebruikers",
"Users_in_role": "Gebruikers met rol",
Expand Down Expand Up @@ -1204,4 +1207,4 @@
"Your_mail_was_sent_to_s": "Uw e-mail werd verzonden naar %s",
"Your_password_is_wrong": "Je wachtwoord is verkeerd!",
"Your_push_was_sent_to_s_devices": "Je push werd verzonden naar %s apparaten"
}
}
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
"EmojiCustomFilesystem": "Sistema de arquivos do emoji customizado",
"Empty_title": "Título vazio",
"Enable": "Habilitar",
"Enable_Auto_Away": "Habilitar Auto Ausência",
"Enable_Desktop_Notifications": "Habilitar Notificações Desktop",
"Enabled": "Ativado",
"Encrypted_message": "Mensagem criptografada",
Expand Down Expand Up @@ -1221,6 +1222,7 @@
"User_removed": "Usuário removido",
"User_removed_by": "Usuário <em>__user_removed__</em> removido da conversa por <em>__user_by__</em>.",
"User_Settings": "Configurações do Usuário",
"User_Presence": "Presença do Usuário",
"User_unmuted_by": "<em>__user_by__</em> permitiu que <em>__user_unmuted__</em> fale na sala.",
"User_unmuted_in_room": "Usuário pode falar na sala",
"User_updated_successfully": "Usuário atualizado com sucesso",
Expand Down Expand Up @@ -1316,4 +1318,4 @@
"your_message_optional": "sua mensagem (opcional)",
"Your_password_is_wrong": "Sua senha está errada!",
"Your_push_was_sent_to_s_devices": "Sua natificação foi enviada para %s dispositivos"
}
}
5 changes: 4 additions & 1 deletion packages/rocketchat-i18n/i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"Duplicate_channel_name": "Um canal com o nome '%s' já existe",
"Duplicate_private_group_name": "Já existe um Grupo Privado com nome '%s'",
"Duration": "Duração",
"Enable_Auto_Away": "Habilitar auto ausência",
"Edit": "Editar",
"Edit_Custom_Field": "Editar Campo Personalizado",
"Edit_Department": "Editar Departamento",
Expand Down Expand Up @@ -563,6 +564,7 @@
"How_responsive_was_the_chat_agent": "Quão responsivo foi o agente de bate-papo?",
"How_satisfied_were_you_with_this_chat": "Ficou satisfeito com este bate-papo?",
"How_to_handle_open_sessions_when_agent_goes_offline": "O que fazer com sessões abertas quando agente ficar offline",
"Idle_Time_Limit": "Tempo limite de ausência",
"If_you_are_sure_type_in_your_password": "Se você tem certeza, digite sua senha:",
"If_you_are_sure_type_in_your_username": "Se você tem certeza, digite seu nome de usuário:",
"Importer_Archived": "Arquivado",
Expand Down Expand Up @@ -1215,6 +1217,7 @@
"Use_this_username": "Usar este nome de usuário",
"Use_uploaded_avatar": "Use o avatar de upload",
"Use_url_for_avatar": "Use url para o avatar",
"User_Presence": "Presença do Utilizador",
"User__username__is_now_a_moderator_of__room_name_": "Usuário __username__ agora é um moderador de __room_name__",
"User__username__is_now_a_owner_of__room_name_": "Usuário __username__ agora é proprietário de __room_name__",
"User__username__removed_from__room_name__moderators": "Usuário __username__ removido dos moderadores de __room_name__",
Expand Down Expand Up @@ -1341,4 +1344,4 @@
"your_message_optional": "sua mensagem (opcional)",
"Your_password_is_wrong": "Sua senha está errada!",
"Your_push_was_sent_to_s_devices": "Sua natificação foi enviada para %s dispositivos"
}
}
24 changes: 24 additions & 0 deletions packages/rocketchat-ui-account/client/accountPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ <h1>{{_ "Localization"}}</h1>
</div>
</div>
</div>
<div class="section">
<h1>{{_ "User_Presence"}}</h1>
<div class="section-content border-component-color">
<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>
</div>
</div>

<div class="input-line double-col" id="idleTimeLimit">
<label>{{_ "Idle_Time_Limit"}}</label>
<div>
{{#if idleTimeLimit}}
<input type="number" name="idleTimeLimit" min="0" value="{{idleTimeLimit}}">
{{else}}
<input type="number" name="idleTimeLimit" min="0" value="" placeholder="{{_ "Use_Global_Settings"}} ({{defaultIdleTimeLimit}})">
{{/if}}
</div>
</div>
</div>

</div>
<div class="section">
<h1>{{_ "Messages"}}</h1>
<div class="section-content border-component-color">
Expand Down
88 changes: 69 additions & 19 deletions packages/rocketchat-ui-account/client/accountPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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';
Expand Down Expand Up @@ -46,14 +58,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;
}
return currentValue === value;

const userPreferences = user.settings.preferences;

if (userPreferences.hasOwnProperty(property)) {
return value === userPreferences[property];
}

return defaultValue;
},
selected(property, value, defaultValue) {
const user = Meteor.user();
Expand Down Expand Up @@ -87,6 +103,13 @@ 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 DEFAULT_IDLE_TIME_LIMIT;
},
defaultDesktopNotification() {
return notificationLabels[RocketChat.settings.get('Desktop_Notifications_Default_Alert')];
},
Expand All @@ -105,9 +128,11 @@ Template.accountPreferences.helpers({
Template.accountPreferences.onCreated(function() {
const user = Meteor.user();
const settingsTemplate = this.parentTemplate(3);

if (settingsTemplate.child == null) {
settingsTemplate.child = [];
}

settingsTemplate.child.push(this);

if (user && user.settings && user.settings.preferences) {
Expand All @@ -116,27 +141,29 @@ Template.accountPreferences.onCreated(function() {
} else {
this.roomsListExhibitionMode = new ReactiveVar('category');
}

let instance = this;

this.autorun(() => {
if (instance.useEmojis && instance.useEmojis.get()) {
Tracker.afterFlush(() => $('#convertAsciiEmoji').show());
} else {
Tracker.afterFlush(() => $('#convertAsciiEmoji').hide());
}
});

this.clearForm = function() {
this.find('#language').value = localStorage.getItem('userLanguage');
};

this.shouldUpdateLocalStorageSetting = function(setting, newValue) {
return localStorage.getItem(setting) !== newValue;
};

this.save = function() {
instance = this;
const data = {};
let reload = false;
const selectedLanguage = $('#language').val();
if (localStorage.getItem('userLanguage') !== selectedLanguage) {
localStorage.setItem('userLanguage', selectedLanguage);
data.language = selectedLanguage;
reload = true;
}

data.newRoomNotification = $('select[name=newRoomNotification]').val();
data.newMessageNotification = $('select[name=newMessageNotification]').val();
data.useEmojis = $('input[name=useEmojis]:checked').val();
Expand All @@ -152,19 +179,42 @@ Template.accountPreferences.onCreated(function() {
data.sendOnEnter = $('#sendOnEnter').find('select').val();
data.unreadRoomsMode = $('input[name=unreadRoomsMode]:checked').val();
data.roomsListExhibitionMode = $('select[name=roomsListExhibitionMode]').val();

data.autoImageLoad = $('input[name=autoImageLoad]:checked').val();
data.emailNotificationMode = $('select[name=emailNotificationMode]').val();
data.highlights = _.compact(_.map($('[name=highlights]').val().split(','), function(e) {
return s.trim(e);
}));
data.desktopNotificationDuration = $('input[name=desktopNotificationDuration]').val();
data.desktopNotifications = $('#desktopNotifications').find('select').val();
data.mobileNotifications = $('#mobileNotifications').find('select').val();
data.unreadAlert = $('#unreadAlert').find('input:checked').val();
data.notificationsSoundVolume = parseInt($('#notificationsSoundVolume').val());

data.roomCounterSidebar = $('#roomCounterSidebar').find('input:checked').val();
data.highlights = _.compact(_.map($('[name=highlights]').val().split(','), function(e) {
return s.trim(e);
}));

const selectedLanguage = $('#language').val();
const enableAutoAway = $('#enableAutoAway').find('input:checked').val();
const idleTimeLimit = parseInt($('input[name=idleTimeLimit]').val());

data.enableAutoAway = enableAutoAway;
data.idleTimeLimit = idleTimeLimit;

let reload = false;

if (this.shouldUpdateLocalStorageSetting('userLanguage', selectedLanguage)) {
localStorage.setItem('userLanguage', selectedLanguage);
data.language = selectedLanguage;
reload = true;
}

if (this.shouldUpdateLocalStorageSetting('enableAutoAway', enableAutoAway)) {
localStorage.setItem('enableAutoAway', enableAutoAway);
reload = true;
}

if (this.shouldUpdateLocalStorageSetting('idleTimeLimit', idleTimeLimit)) {
localStorage.setItem('idleTimeLimit', idleTimeLimit);
reload = true;
}

Meteor.call('saveUserPreferences', data, function(error, results) {
if (results) {
Expand Down
5 changes: 5 additions & 0 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions server/publications/userData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Meteor.publish('userData', function() {
utcOffset: 1,
language: 1,
settings: 1,
enableAutoAway: 1,
idleTimeLimit: 1,
roles: 1,
active: 1,
defaultRoom: 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/ui/04-main-elements-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('[Main Elements Render]', function() {
describe('render:', () => {
before(() => {
sideNav.accountMenu.click();
sideNav.popOverContent.waitForVisible(5000);
sideNav.getPopOverContent().waitForVisible(10000);
});

after(() => {
Expand Down
Loading