Skip to content

Commit 239fa29

Browse files
authored
Merge pull request #3220 from Countly/SER-16-custom-variables-on-push-provided-by-api
Ser 16 custom variables on push provided by api
2 parents cd16efc + d2f3c5b commit 239fa29

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

plugins/push/api/send/audience.js

+3
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ class Pusher extends PusherPopper {
678678
if (!note) {
679679
continue;
680680
}
681+
for (let k in (this.variables || {})) {
682+
note.pr[k] = this.variables[k];
683+
}
681684

682685
let p = pf[0],
683686
d = note._id.getTimestamp().getTime(),

plugins/push/frontend/public/javascripts/countly.models.js

+49-2
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,12 @@
816816
return;
817817
}
818818
Object.keys(userPropertiesDto).forEach(function(key) {
819-
userPropertiesDto[key].l = countlyPushNotification.helper.findUserPropertyLabelByValue(userPropertiesDto[key].k, userProperties);
819+
if (userPropertiesDto[key].t === UserPropertyTypeEnum.API) {
820+
userPropertiesDto[key].l = userPropertiesDto[key].k;
821+
}
822+
else {
823+
userPropertiesDto[key].l = countlyPushNotification.helper.findUserPropertyLabelByValue(userPropertiesDto[key].k, userProperties);
824+
}
820825
});
821826
},
822827
getUserPropertyElement: function(index, userProperty) {
@@ -841,6 +846,20 @@
841846
isAdjacentIndex: function(previousIndex, currentIndex) {
842847
return (parseInt(currentIndex) - 1) === parseInt(previousIndex);
843848
},
849+
decodeHtml: function(str) {
850+
var map =
851+
{
852+
'&': '&',
853+
'&lt;': '<',
854+
'&gt;': '>',
855+
'&quot;': '"',
856+
'&#039;': "'",
857+
'&#39;': "'"
858+
};
859+
return str.replace(/&amp;|&lt;|&gt;|&quot;|&#039;|&#39;/g, function(m) {
860+
return map[m];
861+
});
862+
},
844863
buildMessageText: function(message, userPropertiesDto) {
845864
var self = this;
846865
if (!message) {
@@ -849,7 +868,35 @@
849868
if (!userPropertiesDto) {
850869
return message;
851870
}
852-
var messageInHTMLString = message;
871+
// var html = '',
872+
// keys = this.sortUserProperties(userPropertiesDto),
873+
// ranges = [-1]
874+
// .concat(keys.map(function(k) {
875+
// return parseInt(k);
876+
// }))
877+
// .concat([-1]);
878+
879+
// ranges.forEach(function(start, idx) {
880+
// if (idx === ranges.length - 1) {
881+
// return;
882+
// }
883+
884+
// var end = ranges[idx + 1];
885+
// if (end === 0) { // prop at index 0
886+
// return;
887+
// }
888+
// else if (start === -1) { // first range
889+
// html += message.substr(0, end) + self.getUserPropertyElement(end, userPropertiesDto[end]);
890+
// }
891+
// else if (end === -1) { // last range
892+
// html += message.substr(start);
893+
// }
894+
// else {
895+
// html += message.substr(start, end - start) + self.getUserPropertyElement(end, userPropertiesDto[end]);
896+
// }
897+
// });
898+
// return html;
899+
var messageInHTMLString = this.decodeHtml(message);
853900
var buildMessageLength = 0;
854901
var previousIndex = undefined;
855902
this.sortUserProperties(userPropertiesDto).forEach(function(currentUserPropertyIndex, index) {

0 commit comments

Comments
 (0)