diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index d532cfda72af..02ef0ba3ab5a 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -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", diff --git a/packages/rocketchat-lib/server/startup/settings.js b/packages/rocketchat-lib/server/startup/settings.js index d93b106c04f5..521e48dbe97a 100644 --- a/packages/rocketchat-lib/server/startup/settings.js +++ b/packages/rocketchat-lib/server/startup/settings.js @@ -1036,6 +1036,10 @@ RocketChat.settings.addGroup('Layout', function() { type: 'boolean', 'public': true }); + this.add('UI_Click_Direct_Message', false, { + type: 'boolean', + 'public': true + }); }); }); diff --git a/packages/rocketchat-ui/client/views/app/room.js b/packages/rocketchat-ui/client/views/app/room.js index 4adb3f5d9fbf..1d77eccb8deb 100644 --- a/packages/rocketchat-ui/client/views/app/room.js +++ b/packages/rocketchat-ui/client/views/app/room.js @@ -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 } }); @@ -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) {