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] Show emojis and file uploads on notifications #7559

Merged
merged 12 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from 10 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
6 changes: 6 additions & 0 deletions packages/rocketchat-emoji-emojione/callBacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* globals emojione */
Meteor.startup(function() {
RocketChat.callbacks.add('beforeNotifyUser', (message) => {
return emojione.shortnameToUnicode(message);
});
});
5 changes: 3 additions & 2 deletions packages/rocketchat-emoji-emojione/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Package.onUse(function(api) {
'rocketchat:lib'
]);

api.addFiles('emojiPicker.js', 'client');
api.addFiles('emojiPicker.js', ['client', 'server']);
Copy link
Member

Choose a reason for hiding this comment

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

Use api.addFiles('emojiPicker.js'); instead of api.addFiles('emojiPicker.js', ['client', 'server']);


api.addFiles('rocketchat.js', 'client');
api.addFiles('rocketchat.js', ['client', 'server']);

api.addFiles('sprites.css', 'client');
api.addFiles('callBacks.js', 'server');
Copy link
Member

Choose a reason for hiding this comment

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

callbacks

});
2 changes: 1 addition & 1 deletion packages/rocketchat-emoji/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Package.onUse(function(api) {
]);

api.addFiles('function-isSet.js', 'client');
api.addFiles('rocketchat.js', 'client');
api.addFiles('rocketchat.js', ['client', 'server']);

api.addFiles('emojiParser.js', 'client');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Meteor.methods({
msg: '',
file: {
_id: file._id,
name: file.name
name: file.name,
type: file.type
},
groupable: false,
attachments: [attachment]
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,8 @@
"User_unmuted_by": "User <em>__user_unmuted__</em> unmuted by <em>__user_by__</em>.",
"User_unmuted_in_room": "User unmuted in room",
"User_updated_successfully": "User updated successfully",
"User_uploaded_file": "Uploaded a file",
"User_uploaded_image": "Uploaded an image",
"Username": "Username",
"Username_and_message_must_not_be_empty": "Username and message must not be empty.",
"Username_cant_be_empty": "The username cannot be empty",
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/functions/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RocketChat.sendMessage = function(user, message, room, upsert = false) {
Meteor.defer(() => {
// Execute all callbacks
message.sandstormSessionId = sandstormSessionId;
return RocketChat.callbacks.run('afterSaveMessage', message, room);
return RocketChat.callbacks.run('afterSaveMessage', message, room, user._id);
});
return message;
};
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/functions/updateMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ RocketChat.updateMessage = function(message, user) {
const room = RocketChat.models.Rooms.findOneById(message.rid);

Meteor.defer(function() {
RocketChat.callbacks.run('afterSaveMessage', RocketChat.models.Messages.findOneById(tempid), room);
RocketChat.callbacks.run('afterSaveMessage', RocketChat.models.Messages.findOneById(tempid), room, user._id);
});
};
24 changes: 22 additions & 2 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ function replaceMentionedUsernamesWithFullNames(message, mentions) {
return message;
}

/**
* This function returns a string ready to be shown in the notification
*
* @param {object} message the message to be parsed
*/
function parseMessageText(message, userId) {
const user = RocketChat.models.Users.findOneById(userId);
const lng = user && user.language || RocketChat.settings.get('language') || 'en';

if (!message.msg && message.attachments[0]) {
message.msg = message.attachments[0].image_type ? TAPi18n.__('User_uploaded_image', {lng}) : TAPi18n.__('User_uploaded_file', {lng});
}
message.msg = RocketChat.callbacks.run('beforeNotifyUser', message.msg);

return message.msg;
}
/**
* Send notification to user
*
Expand All @@ -31,7 +47,10 @@ function replaceMentionedUsernamesWithFullNames(message, mentions) {
* @param {number} duration Duration of notification
*/
function notifyUser(userId, user, message, room, duration) {

const UI_Use_Real_Name = RocketChat.settings.get('UI_Use_Real_Name') === true;
message.msg = parseMessageText(message, userId);

if (UI_Use_Real_Name) {
message.msg = replaceMentionedUsernamesWithFullNames(message.msg, message.mentions);
}
Expand Down Expand Up @@ -84,7 +103,8 @@ function getBadgeCount(userId) {
}, 0);
}

RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {

// skips this callback if the message was edited
if (message.editedAt) {
return message;
Expand Down Expand Up @@ -159,7 +179,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
let push_message;
//Set variables depending on Push Notification settings
if (RocketChat.settings.get('Push_show_message')) {
push_message = message.msg;
push_message = parseMessageText(message, userId);
} else {
push_message = ' ';
}
Expand Down