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

Add missing parts of one click to direct message #7608

Merged
merged 1 commit into from
Aug 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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