Skip to content

Commit d5ed6aa

Browse files
authored
Merge pull request #6124 from Countly/fix-placeholders-in-api-push-notifications
[Fix] Placeholders in API push notifications
2 parents 9bf0053 + 3acc812 commit d5ed6aa

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Version 24.05.X
22
Fixes:
3+
- [push] Fixed push notifications title and content text and variables combination
34
- [reports] Correctly match event for email report if event key contains '.'
45

56
## Version 24.05.28
@@ -4503,4 +4504,3 @@ This version provides several features and bugfixes to both server and SDKs. The
45034504
A user of an application can only view analytics for that application
45044505
and cannot edit its settings.
45054506
* Added csfr protection to all methods provided through app.js.
4506-

plugins/push/api/send/data/pers.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,46 @@ const { dot } = require('../../../../../api/utils/common');
44
* Personalize function. A factory to create a function which would apply personalization to a given string.
55
*
66
* @param {String} string string to personalize
7-
* @param {Object} personaliztion object of {5: {f: 'fallback', c: false, k: 'key'}, 10: {...}} kind
7+
* @param {Object} personalizations object of {5: {f: 'fallback', c: false, k: 'key'}, 10: {...}} kind
88
*
99
* @returns {function} function with single obejct parameter which returns final string for a given data
1010
*/
11-
module.exports = function personalize(string, personaliztion) {
12-
let parts = [],
13-
indicies = personaliztion ? Object.keys(personaliztion).map(n => parseInt(n, 10)) : [],
14-
i = 0,
15-
def;
11+
module.exports = function personalize(string, personalizations) {
12+
let parts = [];
13+
let def;
14+
let i = 0;
15+
let indexes = Object.keys(personalizations || {}).map(n => parseInt(n, 10));
1616

17-
indicies.forEach(idx => {
17+
indexes.forEach(idx => {
1818
if (i < idx) {
19-
parts.push(string.substr(i, idx));
19+
const subStringLength = idx - i;
20+
// push all the string that appears before the personalization index
21+
parts.push(string.substr(i, subStringLength));
2022
}
23+
24+
// push the personalization function
2125
parts.push(function(data) {
22-
let pers = personaliztion[idx];
23-
data = dot(data, pers.k);
24-
if (pers.c && data) {
26+
let personalization = personalizations[idx];
27+
28+
data = dot(data, personalization.k);
29+
30+
if (personalization.c && data) {
2531
if (typeof data !== 'string') {
2632
data = data + '';
2733
}
34+
2835
return data.substr(0, 1).toUpperCase() + data.substr(1);
2936
}
30-
return data === null || data === undefined ? pers.f : (data + '');
37+
38+
// if data does not exist return fallback value
39+
return data === null || data === undefined ? personalization.f : (data + '');
3140
});
32-
i = idx + 1;
41+
42+
i = idx;
3343
});
3444

3545
if (i < string.length) {
36-
parts.push(string.substr(i, string.length));
46+
parts.push(string.substr(i));
3747
}
3848

3949
/**
@@ -48,11 +58,12 @@ module.exports = function personalize(string, personaliztion) {
4858
return parts.map(p => typeof p === 'string' ? p : p(data)).join('');
4959
}
5060
}
61+
5162
return def;
5263
};
5364

5465
// a message with all slots filled with default values
5566
def = compile({___dummy: true});
5667

5768
return compile;
58-
};
69+
};

plugins/push/frontend/public/stylesheets/main.scss

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -673,30 +673,32 @@
673673

674674
.cly-vue-push-notification-message-editor-with-emoji-picker {
675675

676-
677-
&__user-property {
678-
padding: 1px 5px 2px;
679-
background: #ECECEC;
680-
border-radius: 2px;
681-
margin-right: 2px;
682-
683-
&:hover {
684-
cursor: pointer;
685-
}
676+
// .cly-vue-push-notification-message-editor-with-emoji-picker__content
677+
&__content {
678+
word-break: break-all;
679+
overflow-x:auto;
680+
height: 100px;
681+
padding-right:32px;
686682
}
687683

684+
// .cly-vue-push-notification-message-editor-with-emoji-picker__title
688685
&__title {
689686
word-break: break-all;
690687
overflow-x: auto;
691688
height:35px;
692689
padding-right:32px;
693690
}
694691

695-
&__content {
696-
word-break: break-all;
697-
overflow-x:auto;
698-
height: 100px;
699-
padding-right:32px;
692+
// .cly-vue-push-notification-message-editor-with-emoji-picker__user-property
693+
&__user-property {
694+
padding: 1px 5px 2px;
695+
background: #ECECEC;
696+
border-radius: 2px;
697+
698+
// .cly-vue-push-notification-message-editor-with-emoji-picker__user-property:hover
699+
&:hover {
700+
cursor: pointer;
701+
}
700702
}
701703
}
702704

@@ -830,4 +832,4 @@
830832
.cly-vue-push-notification-details-chart-bars__item-legend-percentage + .text-medium span i{
831833
margin-left: 6px;
832834
cursor: pointer;
833-
}
835+
}

0 commit comments

Comments
 (0)