Skip to content

Commit

Permalink
Merge pull request #7564 from RocketChat/one-click-to-direct-message
Browse files Browse the repository at this point in the history
[NEW] Adds preference to one-click-to-direct-message and basic functionality
  • Loading branch information
rodrigok committed Jul 25, 2017
2 parents a07e71a + 8722ed9 commit c7604e2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@
"Clear_all_unreads_question": "Clear all unreads?",
"Click_here": "Click here",
"Click_here_for_more_info": "Click here for more info",
"UI_Click_Direct_Message": "Click to Create Direct Message",
"UI_Click_Direct_Message_Description": "Skip opening profile tab, instead go straight to conversation",
"Client_ID": "Client ID",
"Client_Secret": "Client Secret",
"Clients_will_refresh_in_a_few_seconds": "Clients will refresh in a few seconds",
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,10 @@ RocketChat.settings.addGroup('Layout', function() {
type: 'boolean',
'public': true
});
this.add('UI_Click_Direct_Message', false, {
type: 'boolean',
'public': true
});
});
});

Expand Down
44 changes: 31 additions & 13 deletions packages/rocketchat-ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,23 @@ const isSubscribed = _id => ChatSubscription.find({ rid: _id }).count() > 0;
const favoritesEnabled = () => RocketChat.settings.get('Favorite_Rooms');

const userCanDrop = _id => !RocketChat.roomTypes.readOnly(_id, Meteor.user());
const openProfileTab = (e, instance, data) => {
const roomData = Session.get(`roomData${ data.rid }`);

if (RocketChat.Layout.isEmbedded()) {
fireGlobalEvent('click-user-card-message', { username: data.u.username });
e.preventDefault();
e.stopPropagation();
return;
}

if (['c', 'p', 'd'].includes(roomData.t)) {
instance.setUserDetail(data.u.username);
}

instance.tabBar.setTemplate('membersList');
return instance.tabBar.open();
};
Template.room.helpers({
isTranslated() {
const sub = ChatSubscription.findOne({ rid: this._id }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } });
Expand Down Expand Up @@ -458,21 +474,23 @@ Template.room.events({
if (!Meteor.userId() || !this._arguments) {
return;
}
const roomData = Session.get(`roomData${ this._arguments[1].rid }`);

if (RocketChat.Layout.isEmbedded()) {
fireGlobalEvent('click-user-card-message', { username: this._arguments[1].u.username });
e.preventDefault();
e.stopPropagation();
return;
}
if (RocketChat.settings.get('UI_Click_Direct_Message')) {
return Meteor.call('createDirectMessage', this._arguments[1].u.username, (error, result) => {
if (error) {
if (error.isClientSafe) {
openProfileTab(e, instance, this._arguments[1]);
} else {
return handleError(error);
}
}

if (['c', 'p', 'd'].includes(roomData.t)) {
instance.setUserDetail(this._arguments[1].u.username);
if ((result != null ? result.rid : undefined) != null) {
return FlowRouter.go('direct', { username: this._arguments[1].u.username }, FlowRouter.current().queryParams);
}
});
} else {
openProfileTab(e, instance, this._arguments[1]);
}

instance.tabBar.setTemplate('membersList');
return instance.tabBar.open();
},

'scroll .wrapper': _.throttle(function(e) {
Expand Down

0 comments on commit c7604e2

Please sign in to comment.