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] User preference for 24- or 12-hour clock #11169

Merged
merged 4 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions packages/chatpal-search/client/template/result.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment';
import { DateFormat } from 'meteor/rocketchat:lib';

Template.ChatpalSearchResultTemplate.onCreated(function() {
this.badRequest = new ReactiveVar(false);
Expand Down Expand Up @@ -100,10 +100,10 @@ Template.ChatpalSearchSingleMessage.helpers({
},

time() {
return moment(this.created).format(RocketChat.settings.get('Message_TimeFormat'));
return DateFormat.formatTime(this.created);
},
date() {
return moment(this.created).format(RocketChat.settings.get('Message_DateFormat'));
return DateFormat.formatDate(this.created);
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ RocketChat.API.v1.addRoute('users.setPreferences', { authRequired: true }, {
data: Match.ObjectIncluding({
newRoomNotification: Match.Maybe(String),
newMessageNotification: Match.Maybe(String),
clockMode: Match.Maybe(Number),
useEmojis: Match.Maybe(Boolean),
convertAsciiEmoji: Match.Maybe(Boolean),
saveMobileBandwidth: Match.Maybe(Boolean),
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"#channel": "#channel",
"0_Errors_Only": "0 - Errors Only",
"12_Hour": "12-hour clock",
"1_Errors_and_Information": "1 - Errors and Information",
"24_Hour": "24-hour clock",
"2_Erros_Information_and_Debug": "2 - Errors, Information and Debug",
"403": "Forbidden",
"500": "Internal Server Error",
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-lib/client/lib/formatDate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import moment from 'moment';
export const formatTime = (time) => {
switch (RocketChat.getUserPreference(Meteor.userId(), 'clockMode', false)) {
case 1:
return moment(time).format('h:mm A');
case 2:
return moment(time).format('H:mm');
default:
return moment(time).format(RocketChat.settings.get('Message_TimeFormat'));
}
};

export const formatDateAndTime = (time) => {
switch (RocketChat.getUserPreference(Meteor.userId(), 'clockMode', false)) {
case 1:
return moment(time).format('MMMM D, Y h:mm A');
case 2:
return moment(time).format('MMMM D, Y H:mm');
default:
return moment(time).format(RocketChat.settings.get('Message_TimeAndDateFormat'));
}
};

export const formatDate = (time) => moment(time).format(RocketChat.settings.get('Message_DateFormat'));
2 changes: 2 additions & 0 deletions packages/rocketchat-lib/client/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RoomSettingsEnum, RoomTypeConfig, RoomTypeRouteConfig, UiTextContext }
import { hide, leave, erase } from './ChannelActions';
import { call } from './callMethod';
import { LoginPresence } from './LoginPresence';
import * as DateFormat from './formatDate';

export {
call,
Expand All @@ -25,4 +26,5 @@ export {
UiTextContext,
RocketChatAnnouncement,
LoginPresence,
DateFormat,
};
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ class ModelUsers extends RocketChat.models._Base {
const update = {
$set: settings,
};
if (![1, 2].includes(parseInt(settings.preferences.clockMode))) {
delete update.$set['settings.preferences.clockMode'];
update.$unset = { 'settings.preferences.clockMode': 1 };
}

return this.update(_id, update);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment';
import { DateFormat } from 'meteor/rocketchat:lib';
import { fixCordova } from 'meteor/rocketchat:lazy-load';
const colors = {
good: '#35AC19',
Expand Down Expand Up @@ -58,10 +58,9 @@ Template.messageAttachment.helpers({
const messageDate = new Date(this.ts);
const today = new Date();
if (messageDate.toDateString() === today.toDateString()) {
return moment(this.ts).format(RocketChat.settings.get('Message_TimeFormat'));
} else {
return moment(this.ts).format(RocketChat.settings.get('Message_TimeAndDateFormat'));
return DateFormat.formatTime(this.ts);
}
return DateFormat.formatDateAndTime(this.ts);
},
injectIndex(data, previousIndex, index) {
data.index = `${ previousIndex }.attachments.${ index }`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global SnippetedMessages */
import moment from 'moment';
import { DateFormat } from 'meteor/rocketchat:lib';

Template.snippetPage.helpers({
snippet() {
Expand All @@ -23,7 +23,7 @@ Template.snippetPage.helpers({
time() {
const snippet = SnippetedMessages.findOne({ _id: FlowRouter.getParam('snippetId') });
if (snippet !== undefined) {
return moment(snippet.ts).format(RocketChat.settings.get('Message_TimeFormat'));
return DateFormat.formatTime(snippet.ts);
}
},
});
Expand All @@ -34,4 +34,3 @@ Template.snippetPage.onCreated(function() {
Meteor.subscribe('snippetedMessage', snippetId);
});
});

13 changes: 13 additions & 0 deletions packages/rocketchat-ui-account/client/accountPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ <h1>{{_ "Messages"}}</h1>
<label><input type="radio" name="unreadAlert" value="false" checked="{{checked 'unreadAlert' false}}"/> {{_ "Off"}}</label>
</div>
</div>
<div class="input-line double-col" id="clockMode">
<label>{{_ "Message_TimeFormat"}}</label>
<div>
<div class="rc-select">
<select class="input-monitor rc-select__element" name="clockMode">
<option value="0" selected="{{selected 'clockMode' 0}}">{{_ "Default"}}</option>
<option value="1" selected="{{selected 'clockMode' 1}}">{{_ "12_Hour"}}</option>
<option value="2" selected="{{selected 'clockMode' 2}}">{{_ "24_Hour"}}</option>
</select>
{{> icon block="rc-select__arrow" icon="arrow-down" }}
</div>
</div>
</div>
<div class="input-line double-col">
<label>{{_ "Use_Emojis"}}</label>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Template.accountPreferences.onCreated(function() {

data.newRoomNotification = $('select[name=newRoomNotification]').val();
data.newMessageNotification = $('select[name=newMessageNotification]').val();
data.clockMode = parseInt($('select[name=clockMode]').val());
data.useEmojis = JSON.parse($('input[name=useEmojis]:checked').val());
data.convertAsciiEmoji = JSON.parse($('input[name=convertAsciiEmoji]:checked').val());
data.saveMobileBandwidth = JSON.parse($('input[name=saveMobileBandwidth]:checked').val());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fixCordova } from 'meteor/rocketchat:lazy-load';
import moment from 'moment';
import { DateFormat } from 'meteor/rocketchat:lib';
import _ from 'underscore';

const roomFiles = new Mongo.Collection('room_files');
Expand Down Expand Up @@ -42,7 +42,9 @@ Template.uploadedFilesList.helpers({
return fixCordova(this.url);
}
},

format(timestamp) {
return DateFormat.formatDateAndTime(timestamp);
},
fileTypeIcon() {
const [, extension] = this.name.match(/.*?\.(.*)$/);

Expand Down Expand Up @@ -87,7 +89,7 @@ Template.uploadedFilesList.helpers({
},

formatTimestamp(timestamp) {
return moment(timestamp).format(RocketChat.settings.get('Message_TimeAndDateFormat') || 'LLL');
return DateFormat.formatDateAndTime(timestamp);
},

hasMore() {
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-ui-flextab/client/tabs/userInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import _ from 'underscore';
import s from 'underscore.string';
import moment from 'moment';
import { DateFormat } from 'meteor/rocketchat:lib';

import { getActions } from './userActions';

Expand Down Expand Up @@ -113,7 +114,7 @@ Template.userInfo.helpers({
userTime() {
const user = Template.instance().user.get();
if (user && user.utcOffset != null) {
return Template.instance().now.get().utcOffset(user.utcOffset).format(RocketChat.settings.get('Message_TimeFormat'));
return DateFormat.formatTime(Template.instance().now.get().utcOffset(user.utcOffset));
}
},

Expand Down
7 changes: 4 additions & 3 deletions packages/rocketchat-ui-message/client/message.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* globals renderEmoji renderMessageBody */
import _ from 'underscore';
import moment from 'moment';
import { DateFormat } from 'meteor/rocketchat:lib';

Template.message.helpers({
encodeURI(text) {
Expand Down Expand Up @@ -98,10 +99,10 @@ Template.message.helpers({
}
},
time() {
return moment(this.ts).format(RocketChat.settings.get('Message_TimeFormat'));
return DateFormat.formatTime(this.ts);
},
date() {
return moment(this.ts).format(RocketChat.settings.get('Message_DateFormat'));
return DateFormat.formatDate(this.ts);
},
isTemp() {
if (this.temp === true) {
Expand Down Expand Up @@ -139,7 +140,7 @@ Template.message.helpers({
},
editTime() {
if (Template.instance().wasEdited) {
return moment(this.editedAt).format(`${ RocketChat.settings.get('Message_DateFormat') } ${ RocketChat.settings.get('Message_TimeFormat') }`);
return DateFormat.formatDateAndTime(this.editedAt);
}
},
editedBy() {
Expand Down
1 change: 1 addition & 0 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Meteor.methods({
language: Match.Optional(String),
newRoomNotification: Match.Optional(String),
newMessageNotification: Match.Optional(String),
clockMode: Match.Optional(Number),
useEmojis: Match.Optional(Boolean),
convertAsciiEmoji: Match.Optional(Boolean),
saveMobileBandwidth: Match.Optional(Boolean),
Expand Down
1 change: 1 addition & 0 deletions tests/data/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const preferences = {
newRoomNotification: 'door',
newMessageNotification: 'chime',
muteFocusedConversations: true,
clockMode: 0,
useEmojis: true,
convertAsciiEmoji: true,
saveMobileBandwidth: true,
Expand Down