Skip to content

Commit

Permalink
Merge pull request #2345 from litewhatever/develop
Browse files Browse the repository at this point in the history
Add settings to configure what (nickname/channel/group and message) is being sent to third-party when using push notification.
  • Loading branch information
engelgabriel committed Feb 25, 2016
2 parents 05942d9 + 94cd9ec commit cf08e93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@
"Push_gcm_project_number" : "GCM Project Number",
"Push_production" : "Production",
"Push_test_push" : "Test",
"Push_show_message" : "Show message in notification",
"Push_show_username_room" : "Show channel/group/username in notification",
"Quick_Search" : "Quick Search",
"quote" : "quote",
"Recents" : "Recents",
Expand Down
29 changes: 23 additions & 6 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}
});

//Set variables depending on Push Notification settings
if (RocketChat.settings.get('Push_show_message')) {
push_message = message.msg
} else {
push_message = ' '
}

if (RocketChat.settings.get('Push_show_username_room')) {
push_username = "@" + user.username
push_room = " @ #" + room.name
} else {
push_username = ' '
push_room = ' '
}

if ((room.t == null) || room.t === 'd') {
userOfMentionId = message.rid.replace(message.u._id, '');
userOfMention = RocketChat.models.Users.findOne({
Expand All @@ -112,10 +127,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
if (Push.enabled === true && userOfMention.statusConnection !== 'online') {
Push.send({
from: 'push',
title: "@" + user.username,
text: message.msg,
title: push_username,
text: push_message,
apn: {
text: "@" + user.username + ":\n" + message.msg
// ternary operator
text: push_username + ((push_username != ' ' && push_message != ' ') ? ":\n" : '') + push_message
},
badge: 1,
sound: 'chime',
Expand Down Expand Up @@ -241,10 +257,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
if (Push.enabled === true) {
Push.send({
from: 'push',
title: "@" + user.username + " @ #" + room.name,
text: message.msg,
title: push_username + push_room,
text: push_message,
apn: {
text: "@" + user.username + " @ #" + room.name + ":\n" + message.msg
// ternary operator
text: push_username + push_room + ((push_username != ' ' && push_room != ' ' && push_message != ' ') ? ":\n" : '') + push_message
},
badge: 1,
sound: 'chime',
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ RocketChat.settings.addGroup 'Push', ->
@add 'Push_gcm_api_key', '', { type: 'string' }
@add 'Push_gcm_project_number', '', { type: 'string', public: true }

@section 'Privacy', ->
@add 'Push_show_username_room', true, { type: 'boolean', public: true }
@add 'Push_show_message', true, { type: 'boolean', public: true }


RocketChat.settings.addGroup 'Layout', ->
@add 'Layout_Sidenav_Footer', '<div><a href="https://github.com/RocketChat/Rocket.Chat" class="logo" target="_blank"> <img src="/images/logo/logo.svg?v=3" /></a><div class="github-tagline"><span class="octicon octicon-pencil" style="color: #994C00"></span> with <span class="octicon octicon-heart" style="color: red"></span> on <span class="octicon octicon-mark-github"></span></div></div>', { type: 'string', public: true, i18nDescription: 'Layout_Sidenav_Footer_description' }
Expand Down

0 comments on commit cf08e93

Please sign in to comment.