Skip to content

Commit

Permalink
Merge branch 'develop' into fix/user-bar-scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Sep 19, 2018
2 parents 39180cc + e8dc9c3 commit ef16514
Show file tree
Hide file tree
Showing 21 changed files with 193 additions and 17 deletions.
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
12 changes: 12 additions & 0 deletions packages/rocketchat-api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,3 +954,15 @@ RocketChat.API.v1.addRoute('channels.roles', { authRequired: true }, {
});
},
});

RocketChat.API.v1.addRoute('channels.moderators', { authRequired: true }, {
get() {
const findResult = findChannelByIdOrName({ params: this.requestParams() });

const moderators = RocketChat.models.Subscriptions.findByRoomIdAndRoles(findResult._id, ['moderator'], { fields: { u: 1 } }).fetch().map((sub) => sub.u);

return RocketChat.API.v1.success({
moderators,
});
},
});
13 changes: 13 additions & 0 deletions packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,3 +770,16 @@ RocketChat.API.v1.addRoute('groups.roles', { authRequired: true }, {
});
},
});

RocketChat.API.v1.addRoute('groups.moderators', { authRequired: true }, {
get() {
const findResult = findPrivateGroupByIdOrName({ params: this.requestParams(), userId: this.userId });

const moderators = RocketChat.models.Subscriptions.findByRoomIdAndRoles(findResult.rid, ['moderator'], { fields: { u: 1 } }).fetch().map((sub) => sub.u);

return RocketChat.API.v1.success({
moderators,
});
},
});

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);
});
});

2 changes: 2 additions & 0 deletions packages/rocketchat-theme/client/imports/components/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
display: flex;
overflow: auto;

overflow: auto;

flex-direction: column;

min-height: 72px;
Expand Down
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
2 changes: 2 additions & 0 deletions packages/rocketchat-ui-login/client/login/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Template.loginForm.events({
if (error != null) {
if (error.error === 'no-valid-email') {
instance.state.set('email-verification');
} else if (error.error === 'error-user-is-not-activated') {
toastr.error(t('Wait_activation_warning'));
} else {
toastr.error(t('User_not_found_or_incorrect_password'));
}
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
48 changes: 48 additions & 0 deletions tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,4 +902,52 @@ describe('[Channels]', function() {
.end(done);
});
});

describe('/channels.moderators', () => {
let testChannel;
it('/channels.create', (done) => {
request.post(api('channels.create'))
.set(credentials)
.send({
name: `channel.roles.test.${ Date.now() }`,
})
.end((err, res) => {
testChannel = res.body.channel;
done();
});
});
it('/channels.invite', async(done) => {
request.post(api('channels.invite'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat',
})
.end(done);
});
it('/channels.addModerator', (done) => {
request.post(api('channels.addModerator'))
.set(credentials)
.send({
roomId: testChannel._id,
userId: 'rocket.cat',
})
.end(done);
});
it('should return an array of moderators with rocket.cat as a moderator', (done) => {
request.get(api('channels.moderators'))
.set(credentials)
.query({
roomId: testChannel._id,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('moderators').that.is.an('array').that.has.lengthOf(1);
expect(res.body.moderators[0].username).to.be.equal('rocket.cat');
})
.end(done);
});
});
});
Loading

0 comments on commit ef16514

Please sign in to comment.