Skip to content

Commit

Permalink
Merge pull request #7608 from RocketChat/improvements/one-click-to-di…
Browse files Browse the repository at this point in the history
…rect-message

Add missing parts of `one click to direct message`
  • Loading branch information
rodrigok authored Aug 1, 2017
2 parents 8e319c5 + c715816 commit dd77b12
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions packages/rocketchat-ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,45 @@ 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 }`);

const openProfileTab = (e, instance, username) => {
const roomData = Session.get(`roomData${ Session.get('openedRoom') }`);

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

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

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

const openProfileTabOrOpenDM = (e, instance, username) => {
if (RocketChat.settings.get('UI_Click_Direct_Message')) {
return Meteor.call('createDirectMessage', username, (error, result) => {
if (error) {
if (error.isClientSafe) {
openProfileTab(e, instance, username);
} else {
return handleError(error);
}
}

if ((result != null ? result.rid : undefined) != null) {
return FlowRouter.go('direct', { username }, FlowRouter.current().queryParams);
}
});
} else {
openProfileTab(e, instance, username);
}
};

Template.room.helpers({
isTranslated() {
const sub = ChatSubscription.findOne({ rid: this._id }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } });
Expand Down Expand Up @@ -469,31 +491,18 @@ Template.room.events({
if (!Meteor.userId()) {
return;
}
instance.tabBar.open();
return instance.setUserDetail(this.user.username);

openProfileTabOrOpenDM(e, instance, this.user.username);
},

'click .user-card-message'(e, instance) {
if (!Meteor.userId() || !this._arguments) {
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 ((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]);
}
const username = this._arguments[1].u.username;

openProfileTabOrOpenDM(e, instance, username);
},

'scroll .wrapper': _.throttle(function(e, t) {
Expand Down Expand Up @@ -565,17 +574,9 @@ Template.room.events({
return;
}

if (RocketChat.Layout.isEmbedded()) {
fireGlobalEvent('click-mention-link', { username: $(e.currentTarget).data('username') });
e.stopPropagation();
e.preventDefault();
return;
}

instance.tabBar.setTemplate('membersList');
instance.setUserDetail($(e.currentTarget).data('username'));
const username = $(e.currentTarget).data('username');

return instance.tabBar.open();
openProfileTabOrOpenDM(e, instance, username);
},

'click .image-to-download'(event) {
Expand Down

0 comments on commit dd77b12

Please sign in to comment.