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] Replace variable 'mergeChannels' with 'groupByType'. #10954

Merged
merged 9 commits into from
Jun 6, 2018
2 changes: 1 addition & 1 deletion packages/rocketchat-api/server/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ RocketChat.API.v1.addRoute('users.setPreferences', { authRequired: true }, {
sidebarSortby: Match.Optional(String),
sidebarViewMode: Match.Optional(String),
sidebarHideAvatar: Match.Optional(Boolean),
mergeChannels: Match.Optional(Boolean),
groupByType: Match.Optional(Boolean),
muteFocusedConversations: Match.Optional(Boolean)
})
});
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,7 @@
"UI_Click_Direct_Message_Description": "Skip opening profile tab, instead go straight to conversation",
"UI_DisplayRoles": "Display Roles",
"UI_Merge_Channels_Groups": "Merge Private Groups with Channels",
"UI_Group_Channels_By_Type": "Group channels by type",
"UI_Unread_Counter_Style": "Unread Counter Style",
"UI_Use_Name_Avatar": "Use Full Name Initials to Generate Default Avatar",
"UI_Use_Real_Name": "Use Real Name",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/lib/roomTypes/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class ConversationRoomType extends RoomTypeConfig {

condition() {
const user = Meteor.user();
return RocketChat.getUserPreference(user, 'mergeChannels');
// returns true only if groupByType is not set
return !RocketChat.getUserPreference(user, 'groupByType');
}
}
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/lib/roomTypes/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class DirectMessageRoomType extends RoomTypeConfig {

condition() {
const user = Meteor.user();
const mergeChannels = RocketChat.getUserPreference(user, 'mergeChannels');
return !mergeChannels && RocketChat.authz.hasAtLeastOnePermission(['view-d-room', 'view-joined-room']);
const groupByType = RocketChat.getUserPreference(user, 'groupByType');
return groupByType && RocketChat.authz.hasAtLeastOnePermission(['view-d-room', 'view-joined-room']);
}

getUserStatus(roomId) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/lib/roomTypes/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class PrivateRoomType extends RoomTypeConfig {

condition() {
const user = Meteor.user();
const mergeChannels = RocketChat.getUserPreference(user, 'mergeChannels');
return !mergeChannels && RocketChat.authz.hasAllPermission('view-p-room');
const groupByType = RocketChat.getUserPreference(user, 'groupByType');
return groupByType && RocketChat.authz.hasAllPermission('view-p-room');
}

isGroupChat() {
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/lib/roomTypes/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export class PublicRoomType extends RoomTypeConfig {
condition() {
const user = Meteor.user();
// const roomsListExhibitionMode = RocketChat.getUserPreference(user, 'roomsListExhibitionMode');
const mergeChannels = RocketChat.getUserPreference(user, 'mergeChannels');
return !mergeChannels && (RocketChat.authz.hasAtLeastOnePermission(['view-c-room', 'view-joined-room']) || RocketChat.settings.get('Accounts_AllowAnonymousRead') === true);
const groupByType = RocketChat.getUserPreference(user, 'groupByType');
return groupByType && (RocketChat.authz.hasAtLeastOnePermission(['view-c-room', 'view-joined-room']) || RocketChat.settings.get('Accounts_AllowAnonymousRead') === true);
}

showJoinLink(roomId) {
Expand Down
4 changes: 2 additions & 2 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1625,9 +1625,9 @@ RocketChat.settings.addGroup('Layout', function() {
type: 'boolean',
'public': true
});
this.add('UI_Merge_Channels_Groups', true, {
this.add('UI_Group_Channels_By_Type', true, {
type: 'boolean',
'public': true
'public': false
});
this.add('UI_Use_Name_Avatar', false, {
type: 'boolean',
Expand Down
20 changes: 0 additions & 20 deletions packages/rocketchat-ui-account/client/accountPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,6 @@ <h1>{{_ "Messages"}}</h1>
<label><input type="radio" name="hideAvatars" value="false" checked="{{checked 'hideAvatars' false}}"/> {{_ "False"}}</label>
</div>
</div>
<!-- <div class="input-line double-col">
<label for="roomsListExhibitionMode">{{_ "Sidebar_list_mode"}}</label>
<div>
<select class="input-monitor rc-input__element" name="roomsListExhibitionMode" id="roomsListExhibitionMode">
<option value="unread" selected="{{selected 'roomsListExhibitionMode' 'unread'}}">{{_ "Unread_Rooms_Mode"}}</option>
<option value="activity" selected="{{selected 'roomsListExhibitionMode' 'activity'}}">{{_ "Sort_by_activity"}}</option>
<option value="category" selected="{{selected 'roomsListExhibitionMode' 'category'}}">{{_ "Split_by_categories"}}</option>
</select>
</div>
</div> -->
<!-- {{# with disabled=showMergedChannels}}
<div class="input-line double-col" id="mergeChannels" {{disabled}}>
<label>{{_ "UI_Merge_Channels_Groups"}}</label>
<div>
<label><input type="radio" name="mergeChannels" value="1" checked="{{checked 'mergeChannels' true 'default'}}" {{disabled}}/> {{_ "True"}}</label>
<label><input type="radio" name="mergeChannels" value="0" checked="{{checked 'mergeChannels' false 'default'}}" {{disabled}}/> {{_ "False"}}</label>
<label><input type="radio" name="mergeChannels" value="-1" checked="{{checked 'mergeChannels' 'default' 'default'}}" {{disabled}}/> {{_ "Default"}}</label>
</div>
</div>
{{/with}} -->
<div class="input-line double-col" id="messageViewMode">
<label>{{_ "View_mode"}}</label>
<div>
Expand Down
8 changes: 4 additions & 4 deletions packages/rocketchat-ui-sidenav/client/sideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ Template.sideNav.onRendered(function() {
});

Template.sideNav.onCreated(function() {
this.mergedChannels = new ReactiveVar(false);
this.groupedByType = new ReactiveVar(false);

this.autorun(() => {
const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
'settings.preferences.roomsListExhibitionMode': 1,
'settings.preferences.mergeChannels': 1
'settings.preferences.groupByType': 1
}
});
const userPref = RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'category' && RocketChat.getUserPreference(user, 'mergeChannels');
this.mergedChannels.set(userPref ? userPref : RocketChat.settings.get('UI_Merge_Channels_Groups'));
const userPref = RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'category' && RocketChat.getUserPreference(user, 'groupByType');
this.groupedByType.set(userPref ? userPref : RocketChat.settings.get('UI_Group_Channels_By_Type'));
});
});
4 changes: 2 additions & 2 deletions packages/rocketchat-ui-sidenav/client/sortlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</ul>
<span class="rc-popover__divider"></span>
<ul class="rc-popover__list">
<li class="rc-popover__item {{bold 'mergeChannels'}}">
<li class="rc-popover__item {{bold 'groupByType'}}">
<label class="rc-popover__label">
<input type="checkbox" name="mergeChannels" class="hidden" checked="{{checked 'mergeChannels'}}"/>
<input type="checkbox" name="groupByType" class="hidden" checked="{{checked 'groupByType'}}"/>
<span class="rc-popover__icon">
{{> icon block="rc-popover__icon-element" icon='sort-amount-down' }}
</span>
Expand Down
5 changes: 2 additions & 3 deletions packages/rocketchat-ui-sidenav/client/sortlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ const checked = function(prop, field) {
if (prop === 'sidebarShowFavorites') {
return RocketChat.getUserPreference(user, 'sidebarShowFavorites');
}
if (prop === 'mergeChannels') {
// TODO change mergeChannels to GroupByType
return !RocketChat.getUserPreference(user, 'mergeChannels');
if (prop === 'groupByType') {
return RocketChat.getUserPreference(user, 'groupByType');
}
if (prop === 'sidebarShowUnread') {
return RocketChat.getUserPreference(user, 'sidebarShowUnread');
Expand Down
9 changes: 5 additions & 4 deletions server/methods/channelsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ Meteor.methods({

if (channelType !== 'public' && RocketChat.authz.hasPermission(Meteor.userId(), 'view-p-room')) {
const user = Meteor.user();
const userPref = RocketChat.getUserPreference(user, 'mergeChannels') && RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'category';
const globalPref = RocketChat.settings.get('UI_Merge_Channels_Groups');
const mergeChannels = userPref !== undefined ? userPref : globalPref;
const userPref = RocketChat.getUserPreference(user, 'groupByType') && RocketChat.getUserPreference(user, 'roomsListExhibitionMode') === 'category';
const globalPref = RocketChat.settings.get('UI_Group_Channels_By_Type');
// needs to negate globalPref because userPref represents its opposite
const groupByType = userPref !== undefined ? userPref : globalPref;

if (mergeChannels) {
if (!groupByType) {
roomTypes.push({
type: 'p',
username: user.username
Expand Down
8 changes: 4 additions & 4 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ Meteor.methods({
muteFocusedConversations: Match.Optional(Boolean)
};
check(settings, Match.ObjectIncluding(keys));
if (settings.mergeChannels) {
if (settings.groupByType) {
check(settings, Match.ObjectIncluding({
mergeChannels: Match.OneOf(Number, Boolean) //eslint-disable-line new-cap
groupByType: Match.OneOf(Number, Boolean) //eslint-disable-line new-cap
}));
}
const user = Meteor.user();
Expand All @@ -59,8 +59,8 @@ Meteor.methods({
RocketChat.models.Users.setLanguage(user._id, settings.language);
}

if (settings.mergeChannels != null) {
settings.mergeChannels = ['1', true].includes(settings.mergeChannels);
if (settings.groupByType != null) {
settings.groupByType = ['1', true].includes(settings.groupByType);
}

if (settings.roomsListExhibitionMode != null) {
Expand Down
29 changes: 29 additions & 0 deletions server/startup/migrations/v124.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
RocketChat.Migrations.add({
version: 124,
up() {
RocketChat.models.Users.update({
'settings.preferences.mergeChannels': true
}, {
$unset: {
'settings.preferences.mergeChannels': 1
},
$set: {
'settings.preferences.groupByType': false
}
}, {
multi: true
});
RocketChat.models.Users.update({
'settings.preferences.mergeChannels': false
}, {
$unset: {
'settings.preferences.mergeChannels': 1
},
$set: {
'settings.preferences.groupByType': true
}
}, {
multi: true
});
}
});