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 @@ -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
10 changes: 10 additions & 0 deletions packages/rocketchat-ui/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ this.ChatMessages = class ChatMessages {
const msg = input.value;
const msgObject = { _id: Random.id(), rid, msg};

if (msg.slice(0, 2) === '+:') {
const reaction = msg.slice(1).trim();
if (RocketChat.emoji.list[reaction]) {
const lastMessage = ChatMessage.findOne({rid}, { fields: { ts: 1 }, sort: { ts: -1 }});
Meteor.call('setReaction', reaction, 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