pull/9608/head
Guilherme Gazzo 8 years ago
parent b5e9c9c09d
commit b52402ddb3
No known key found for this signature in database
GPG Key ID: 1F85C9AD922D0829
  1. 5
      packages/rocketchat-api/server/api.js
  2. 4
      packages/rocketchat-lib/lib/roomTypes/conversation.js
  3. 4
      packages/rocketchat-lib/lib/roomTypes/direct.js
  4. 4
      packages/rocketchat-lib/lib/roomTypes/favorite.js
  5. 2
      packages/rocketchat-lib/lib/roomTypes/index.js
  6. 4
      packages/rocketchat-lib/lib/roomTypes/private.js
  7. 4
      packages/rocketchat-lib/lib/roomTypes/public.js
  8. 2
      packages/rocketchat-lib/lib/roomTypes/unread.js
  9. 2
      packages/rocketchat-lib/startup/defaultRoomTypes.js
  10. 4
      packages/rocketchat-theme/client/imports/components/popover.css
  11. 77
      packages/rocketchat-ui-sidenav/client/roomList.js
  12. 29
      packages/rocketchat-ui-sidenav/client/sidebarHeader.js
  13. 56
      packages/rocketchat-ui-sidenav/client/sortlist.html
  14. 36
      packages/rocketchat-ui-sidenav/client/sortlist.js
  15. 2
      packages/rocketchat-ui-sidenav/package.js
  16. 47
      server/methods/saveUserPreferences.js

@ -222,15 +222,20 @@ class API extends Restivus {
post() {
const args = loginCompatibility(this.bodyParams);
console.log('args ->', args);
const invocation = new DDPCommon.MethodInvocation({
connection: {
close() {}
}
});
console.log('invocation ->', invocation);
let auth;
try {
auth = DDP._CurrentInvocation.withValue(invocation, () => Meteor.call('login', args));
console.log('UTH ->', auth);
} catch (error) {
let e = error;
if (error.reason === 'User not found') {

@ -3,7 +3,7 @@ import { RoomTypeConfig } from '../RoomTypeConfig';
export class ConversationRoomType extends RoomTypeConfig {
constructor() {
super({
identifier: 'activity',
identifier: 'merged',
order: 30,
label: 'Conversations'
});
@ -11,6 +11,6 @@ export class ConversationRoomType extends RoomTypeConfig {
condition() {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'activity';
return RocketChat.getUserPreference(user, 'mergeChannels');
}
}

@ -62,8 +62,8 @@ export class DirectMessageRoomType extends RoomTypeConfig {
condition() {
const user = Meteor.user();
const roomsListExhibitionMode = RocketChat.getUserPreference(user, 'roomsListExhibitionMode');
return !roomsListExhibitionMode || ['unread', 'category'].includes(roomsListExhibitionMode) && RocketChat.authz.hasAtLeastOnePermission(['view-d-room', 'view-joined-room']);
const mergeChannels = RocketChat.getUserPreference(user, 'mergeChannels');
return !mergeChannels && RocketChat.authz.hasAtLeastOnePermission(['view-d-room', 'view-joined-room']);
}
getUserStatus(roomId) {

@ -10,4 +10,8 @@ export class FavoriteRoomType extends RoomTypeConfig {
label: 'Favorites'
});
}
condition() {
const user = Meteor.user();
return RocketChat.settings.get('Favorite_Rooms') && RocketChat.getUserPreference(user, 'sidebarShowFavorites');
}
}

@ -1,4 +1,3 @@
import { ChannelsRoomType } from './channels';
import { ConversationRoomType } from './conversation';
import { DirectMessageRoomType } from './direct';
import { FavoriteRoomType } from './favorite';
@ -7,7 +6,6 @@ import { PublicRoomType } from './public';
import { UnreadRoomType } from './unread';
export {
ChannelsRoomType,
ConversationRoomType,
DirectMessageRoomType,
FavoriteRoomType,

@ -44,9 +44,9 @@ export class PrivateRoomType extends RoomTypeConfig {
condition() {
const user = Meteor.user();
const roomsListExhibitionMode = RocketChat.getUserPreference(user, 'roomsListExhibitionMode');
// const roomsListExhibitionMode = RocketChat.getUserPreference(user, 'roomsListExhibitionMode');
const mergeChannels = RocketChat.getUserPreference(user, 'mergeChannels');
return !roomsListExhibitionMode || ['unread', 'category'].includes(roomsListExhibitionMode) && !mergeChannels && RocketChat.authz.hasAllPermission('view-p-room');
return !mergeChannels && RocketChat.authz.hasAllPermission('view-p-room');
}
isGroupChat() {

@ -42,9 +42,9 @@ export class PublicRoomType extends RoomTypeConfig {
condition() {
const user = Meteor.user();
const roomsListExhibitionMode = RocketChat.getUserPreference(user, 'roomsListExhibitionMode');
// const roomsListExhibitionMode = RocketChat.getUserPreference(user, 'roomsListExhibitionMode');
const mergeChannels = RocketChat.getUserPreference(user, 'mergeChannels');
return !roomsListExhibitionMode || ['unread', 'category'].includes(roomsListExhibitionMode) && !mergeChannels && (RocketChat.authz.hasAtLeastOnePermission(['view-c-room', 'view-joined-room']) || RocketChat.settings.get('Accounts_AllowAnonymousRead') === true);
return !mergeChannels && (RocketChat.authz.hasAtLeastOnePermission(['view-c-room', 'view-joined-room']) || RocketChat.settings.get('Accounts_AllowAnonymousRead') === true);
}
showJoinLink(roomId) {

@ -13,6 +13,6 @@ export class UnreadRoomType extends RoomTypeConfig {
condition() {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'unread';
return RocketChat.getUserPreference(user, 'sidebarShowUnread');
}
}

@ -1,5 +1,4 @@
import {
ChannelsRoomType,
ConversationRoomType,
DirectMessageRoomType,
FavoriteRoomType,
@ -11,7 +10,6 @@ import {
RocketChat.roomTypes.add(new UnreadRoomType());
RocketChat.roomTypes.add(new FavoriteRoomType());
RocketChat.roomTypes.add(new ConversationRoomType());
RocketChat.roomTypes.add(new ChannelsRoomType());
RocketChat.roomTypes.add(new PublicRoomType());
RocketChat.roomTypes.add(new PrivateRoomType());
RocketChat.roomTypes.add(new DirectMessageRoomType());

@ -101,6 +101,10 @@
}
}
&--bold {
font-weight: bold;
}
&--star-filled .rc-icon {
fill: currentColor;
}

@ -5,37 +5,47 @@ import { UiTextContext } from 'meteor/rocketchat:lib';
Template.roomList.helpers({
rooms() {
if (this.identifier === 'unread') {
const query = {
alert: true,
open: true,
hideUnreadStatus: {$ne: true}
};
return ChatSubscription.find(query, {sort: {'t': 1, 'name': 1}});
}
/*
modes:
sortby activity/alphabetical
merge channels into one list
show favorites
show unread
*/
if (this.anonymous) {
return RocketChat.models.Rooms.find({t: 'c'}, {sort: {name: 1}});
}
const favoritesEnabled = RocketChat.settings.get('Favorite_Rooms');
const user = Meteor.user();
const sortBy = RocketChat.getUserPreference(user, 'sidebarSortby') || 'activity';
const query = {
open: true
};
const sort = { 't': 1 };
if (this.identifier === 'd' && RocketChat.settings.get('UI_Use_Real_Name')) {
sort.fname = 1;
} else {
sort.name = 1;
const sort = {};
if (sortBy === 'activity') {
sort.t = 1;
} else { // alphabetical
sort[this.identifier === 'd' && RocketChat.settings.get('UI_Use_Real_Name') ? 'fname' : 'name'] = /descending/.test(sortBy) ? -1 : 1;
}
if (this.identifier === 'unread') {
query.alert = true;
query.hideUnreadStatus = {$ne: true};
return ChatSubscription.find(query, {sort});
}
const favoritesEnabled = RocketChat.settings.get('Favorite_Rooms') && RocketChat.getUserPreference(user, 'sidebarShowFavorites');
if (this.identifier === 'f') {
query.f = favoritesEnabled;
} else {
let types = [this.identifier];
const user = Meteor.user();
if (this.identifier === 'activity') {
if (this.identifier === 'merged') {
types = ['c', 'p', 'd'];
}
@ -43,10 +53,10 @@ Template.roomList.helpers({
types = ['c', 'p'];
}
if (this.identifier === 'tokens' && user && user.services && user.services.tokenpass) {
query.tokens = { $exists: true };
} else if (this.identifier === 'c' || this.identifier === 'p') {
if (['c', 'p'].includes(this.identifier)) {
query.tokens = { $exists: false };
} else if (this.identifier === 'tokens' && user && user.services && user.services.tokenpass) {
query.tokens = { $exists: true };
}
if (RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'unread') {
@ -59,15 +69,28 @@ Template.roomList.helpers({
query.t = {$in: types};
query.f = {$ne: favoritesEnabled};
}
if (this.identifier === 'activity') {
const list = ChatSubscription.find(query).fetch().map(sub => {
const lm = RocketChat.models.Rooms.findOne(sub.rid, {fields: {_updatedAt: 1}})._updatedAt;
if (sortBy === 'activity') {
const list = ChatSubscription.find(query, {sort: {rid : 1}}).fetch();
const ids = list.map(sub => sub.rid);
const rooms = RocketChat.models.Rooms.find({
_id: { $in : ids}
},
{
sort : {
_id: 1
},
fields: {_updatedAt: 1}
}).fetch();
return _.sortBy(list.map((sub, i) => {
const lm = rooms[i]._updatedAt;
return {
lm: lm && lm.toISOString(),
...sub
};
});
return _.sortBy(list, 'lm').reverse();
}), 'lm').reverse();
}
return ChatSubscription.find(query, {sort});
},
@ -83,7 +106,7 @@ Template.roomList.helpers({
or is unread and has one room
*/
return !['unread', 'f'].includes(group.identifier) || rooms.count();
return !['unread', 'f'].includes(group.identifier) || (rooms.length || rooms.count && rooms.count());
},
roomType(room) {

@ -21,7 +21,32 @@ const toolbarButtons = [
},
{
name: t('Sort'),
icon: 'sort'
icon: 'sort',
action: (e) => {
const sidebarHeader = document.querySelector('.sidebar__header');
const sidebarHeaderPadding = parseInt(getComputedStyle(sidebarHeader)['padding-left'].replace('px', '')) * 2;
const sidebarHeaderMargin = parseInt(getComputedStyle(sidebarHeader)['margin-left'].replace('px', '')) * 2;
const options = [];
const config = {
template: 'sortlist',
mousePosition: () => ({
x: e.currentTarget.getBoundingClientRect().left,
y: e.currentTarget.getBoundingClientRect().bottom + 50
}),
customCSSProperties: () => ({
top: `${ e.currentTarget.getBoundingClientRect().bottom + 10 }px`,
left: `${ e.currentTarget.getBoundingClientRect().left - 10 }px`
}),
data: {
change : (value) => {
// return instance.form[key].set(key === 'desktopNotificationDuration' ? parseInt(value) : value);
},
// value: instance.form[key].get(),
options
}
};
popover.open(config);
}
},
{
name: t('Create_A_New_Channel'),
@ -187,6 +212,6 @@ Template.sidebarHeader.helpers({
Template.sidebarHeader.events({
'click .js-button'(e) {
return this.action && this.action.apply(this);
return this.action && this.action.apply(this, [e]);
}
});

@ -0,0 +1,56 @@
<template name="sortlist">
<div class="rc-popover__column">
<ul class="rc-popover__list">
<li class="rc-popover__item">
<label class="rc-popover__item">
<input type="checkbox" name="mergeChannels" checked="{{checked 'mergeChannels'}}"/>
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='star' }}
</span>
<span class="rc-popover__item-text">Merge</span>
</label>
</li>
{{#if favorite}}
<li class="rc-popover__item">
<label class="rc-popover__item">
<input type="checkbox" name="sidebarShowFavorites" checked="{{checked 'sidebarShowFavorites'}}"/>
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='star' }}
</span>
<span class="rc-popover__item-text">Favorite</span>
</label>
</li>
{{/if}}
<li class="rc-popover__item">
<label class="rc-popover__item">
<input type="checkbox" name="sidebarShowUnread" checked="{{checked 'sidebarShowUnread'}}">
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='eye-off' }}
</span>
<span class="rc-popover__item-text">Unread</span>
</label>
</li>
</ul>
<span class="rc-popover__divider"></span>
<ul class="rc-popover__list">
<li class="rc-popover__item">
<label class="rc-popover__item">
<input type="radio" name="sidebarSortby" value="alphabetical" checked="{{checked 'sidebarSortby' 'alphabetical'}}">
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='sort' }}
</span>
<span class="rc-popover__item-text">Alphabetical</span>
</label>
</li>
<li class="rc-popover__item">
<label class="rc-popover__item">
<input type="radio" name="sidebarSortby" value="activity" checked="{{checked 'sidebarSortby' 'activity'}}">
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='clock' }}
</span>
</label>
<span class="rc-popover__item-text">Activity</span>
</li>
</ul>
</div>
</template>

@ -0,0 +1,36 @@
/* globals menu*/
Template.sortlist.helpers({
favorite() {
return RocketChat.settings.get('Favorite_Rooms');
},
checked(prop, field) {
const user = Meteor.user();
if (prop === 'sidebarShowFavorites') {
return RocketChat.getUserPreference(user, 'sidebarShowFavorites');
}
if (prop === 'mergeChannels') {
return RocketChat.getUserPreference(user, 'mergeChannels');
}
if (prop === 'sidebarShowUnread') {
return RocketChat.getUserPreference(user, 'sidebarShowUnread');
}
if (prop === 'sidebarSortby') {
return (RocketChat.getUserPreference(user, 'sidebarSortby') || 'activity') === field;
}
}
});
Template.sortlist.events({
'change input'({currentTarget}) {
const name = currentTarget.getAttribute('name');
const value = currentTarget.getAttribute('type') === 'checkbox' ? currentTarget.checked : currentTarget.value;
Meteor.call('saveUserPreferences', {
[name] : value
});
}
});
Template.sortlist.onRendered(function() {
});

@ -28,6 +28,7 @@ Package.onUse(function(api) {
api.addFiles('client/sideNav.html', 'client');
api.addFiles('client/toolbar.html', 'client');
api.addFiles('client/roomList.html', 'client');
api.addFiles('client/sortlist.html', 'client');
api.addFiles('client/userStatus.html', 'client');
api.addFiles('client/createCombinedFlex.js', 'client');
@ -39,5 +40,6 @@ Package.onUse(function(api) {
api.addFiles('client/sidebarItem.js', 'client');
api.addFiles('client/sideNav.js', 'client');
api.addFiles('client/roomList.js', 'client');
api.addFiles('client/sortlist.js', 'client');
api.addFiles('client/toolbar.js', 'client');
});

@ -1,6 +1,6 @@
Meteor.methods({
saveUserPreferences(settings) {
check(settings, Match.ObjectIncluding({
const keys = {
language: Match.Optional(String),
newRoomNotification: Match.Optional(String),
newMessageNotification: Match.Optional(String),
@ -16,7 +16,7 @@ Meteor.methods({
desktopNotifications: Match.Optional(String),
mobileNotifications: Match.Optional(String),
enableAutoAway: Match.Optional(Boolean),
highlights: [String],
highlights: Match.Optional([String]),
desktopNotificationDuration: Match.Optional(Number),
viewMode: Match.Optional(Number),
hideUsernames: Match.Optional(Boolean),
@ -25,26 +25,39 @@ Meteor.methods({
hideFlexTab: Match.Optional(Boolean),
sendOnEnter: Match.Optional(String),
roomCounterSidebar: Match.Optional(Boolean),
mergeChannels: Match.Optional(Number),
idleTimeLimit: Match.Optional(Number)
}));
idleTimeLimit: Match.Optional(Number),
// sidebarMergeChannels: Match.Optional(Boolean),
sidebarShowFavorites: Match.Optional(Boolean),
sidebarShowUnread: Match.Optional(Boolean),
sidebarSortby: Match.Optional(String)
};
check(settings, Match.ObjectIncluding(keys));
if (settings.mergeChannels) {
check(settings, Match.ObjectIncluding({
mergeChannels: Match.OneOf(Number, Boolean)
}));
}
const user = Meteor.userId();
if (!user) {
return false;
}
if (settings.language != null) {
RocketChat.models.Users.setLanguage(user, settings.language);
}
if (settings.mergeChannels != null) {
settings.mergeChannels = ['1', true].includes(settings.mergeChannels);
}
if (Meteor.userId()) {
if (settings.language != null) {
RocketChat.models.Users.setLanguage(Meteor.userId(), settings.language);
}
if (settings.mergeChannels !== -1) {
settings.mergeChannels = settings.mergeChannels === '1';
} else {
delete settings.mergeChannels;
}
if (settings.roomsListExhibitionMode != null) {
settings.roomsListExhibitionMode = ['category', 'unread', 'activity'].includes(settings.roomsListExhibitionMode) ? settings.roomsListExhibitionMode : 'category';
}
RocketChat.models.Users.setPreferences(Meteor.userId(), settings);
RocketChat.models.Users.setPreferences(user, settings);
return true;
}
return true;
}
});

Loading…
Cancel
Save