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] Add reaction to the last message when get the shortcut +: #7569

Merged
merged 11 commits into from
Jul 27, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Template.messagePopup.onCreated(function() {
return;
}
firstPartValue = firstPartValue.replace(template.selectorRegex, template.prefix + getValue + template.suffix);

template.input.value = firstPartValue + lastPartValue;
return setCursorPosition(template.input, firstPartValue.length);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="message-popup-results">
{{#if emojiEnabled}}
{{> messagePopup popupEmojiConfig}}
{{> messagePopup popupReactionEmojiConfig}}
{{/if}}
{{> messagePopup popupChannelConfig}}
{{> messagePopup popupUserConfig}}
Expand Down
41 changes: 41 additions & 0 deletions packages/rocketchat-ui-message/client/popup/messagePopupConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,47 @@ Template.messagePopupConfig.helpers({
return [];
}

const regExp = new RegExp(`^${ RegExp.escape(key) }`, 'i');
return Object.keys(collection).map(key => {
const value = collection[key];
return {
_id: key,
data: value
};
})
.filter(obj => regExp.test(obj._id))
.slice(0, 10)
.sort(function(a, b) {
if (a._id < b._id) {
return -1;
}
if (a._id > b._id) {
return 1;
}
return 0;
});
}
};
}
},
popupReactionEmojiConfig() {
if (RocketChat.emoji != null) {
const self = this;
return {
title: t('Emoji'),
collection: RocketChat.emoji.list,
template: 'messagePopupEmoji',
trigger: '\\+',
prefix: '+',
suffix: ' ',
getInput: self.getInput,
getFilter(collection, filter) {
const key = `${ filter }`;

if (!RocketChat.emoji.packages.emojione || RocketChat.emoji.packages.emojione.asciiList[key] || filter.length < 2) {
return [];
}

const regExp = new RegExp(`^${ RegExp.escape(key) }`, 'i');
return Object.keys(collection).map(key => {
const value = collection[key];
Expand Down
6 changes: 6 additions & 0 deletions packages/rocketchat-ui/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ this.ChatMessages = class ChatMessages {

const msg = input.value;
const msgObject = { _id: Random.id(), rid, msg};
const lastMessage = ChatMessage.findOne({rid}, { fields: { ts: 1 }, sort: { ts: -1 }});
if (msg[0]+msg[1] === '+:') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use msg.slice(0, 2) instead of msg[0]+msg[1] and check if the emoji exists first:

const reaction = msg.slice(1).trim();
if (RocketChat.emoji.list[reaction]) {
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you try you can set a reaction with an invalid emoji like +:as: askjhdak

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!
How can we trigger an sound error when trying to send a wrong command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not trigger a sound, just send the message, maybe the users is trying to send that as a message

Meteor.call('setReaction', msg.replace('+', '').trim(), lastMessage._id);
input.value = '';
return;
}

// Run to allow local encryption, and maybe other client specific actions to be run before send
return RocketChat.promises.run('onClientBeforeSendMessage', msgObject).then(msgObject => {
Expand Down