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

[FIX] Message_AllowedMaxSize fails for emoji sequences #10431

Merged
merged 17 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 17 additions & 3 deletions packages/rocketchat-lib/server/methods/sendMessage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* globals emojione */
import _ from 'underscore';
import moment from 'moment';

Meteor.methods({
Expand Down Expand Up @@ -29,10 +31,22 @@ Meteor.methods({
message.ts = new Date();
}

if (message.msg && message.msg.length > RocketChat.settings.get('Message_MaxAllowedSize')) {
throw new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', {
method: 'sendMessage'
if (message.msg) {
// converting emoji unicodes to shortnames if present
let adjustedMessage = emojione.toShort(message.msg);

adjustedMessage = adjustedMessage.replace(/:\w+:/gm, (match) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this part still needed? 🤔

if (RocketChat.emoji.list[match] !== undefined) {
return ' ';
}
return match;
});

if (_.toArray(adjustedMessage).length > RocketChat.settings.get('Message_MaxAllowedSize')) {
throw new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', {
method: 'sendMessage'
});
}
}

const user = RocketChat.models.Users.findOneById(Meteor.userId(), {
Expand Down
15 changes: 13 additions & 2 deletions packages/rocketchat-ui/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals MsgTyping */
/* globals MsgTyping, emojione */
import _ from 'underscore';
import s from 'underscore.string';
import moment from 'moment';
import toastr from 'toastr';
Expand Down Expand Up @@ -554,7 +555,17 @@ this.ChatMessages = class ChatMessages {
}

isMessageTooLong(message) {
return message && message.length > this.messageMaxSize;
// converting emoji unicodes to shortnames if present
let adjustedMessage = emojione.toShort(message);

adjustedMessage = adjustedMessage.replace(/:\w+:/gm, (match) => {
if (RocketChat.emoji.list[match] !== undefined) {
return ' ';
}
return match;
});

return message && _.toArray(adjustedMessage).length > this.messageMaxSize;
}

isEmpty() {
Expand Down