Skip to content

Commit

Permalink
Merge pull request #7559 from RocketChat/add-file-upload-notification
Browse files Browse the repository at this point in the history
[NEW] Show emojis and file uploads on notifications
  • Loading branch information
rodrigok authored Jul 26, 2017
2 parents 978474e + ee4b713 commit d3c2b75
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 8 deletions.
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');

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

api.addFiles('sprites.css', 'client');
api.addFiles('callbacks.js', 'server');
});
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');

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

0 comments on commit d3c2b75

Please sign in to comment.