nodebb-plugin-web-push 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +16 -14
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -93,17 +93,15 @@ plugin.addRoutes = async ({ router, middleware, helpers }) => {
|
|
|
93
93
|
return helpers.notAllowed(req, res);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
const { userLang } = await user.getSettings(req.uid);
|
|
96
97
|
const { subscription } = req.body;
|
|
97
|
-
await
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
badge: `${nconf.get('url')}/apple-touch-icon`,
|
|
105
|
-
},
|
|
106
|
-
}));
|
|
98
|
+
const payload = await constructPayload({
|
|
99
|
+
nid: utils.generateUUID(),
|
|
100
|
+
bodyShort: 'Test notification',
|
|
101
|
+
bodyLong: 'This is a test message sent from NodeBB',
|
|
102
|
+
path: `${nconf.get('url')}/me/web-push`,
|
|
103
|
+
}, req.uid, userLang);
|
|
104
|
+
await webPush.sendNotification(subscription, JSON.stringify(payload));
|
|
107
105
|
});
|
|
108
106
|
};
|
|
109
107
|
|
|
@@ -187,13 +185,15 @@ plugin.addProfileItem = async (data) => {
|
|
|
187
185
|
return data;
|
|
188
186
|
};
|
|
189
187
|
|
|
190
|
-
async function constructPayload(notification, uid,
|
|
188
|
+
async function constructPayload(notification, uid, lang) {
|
|
191
189
|
let { maxLength, icon, badge } = await meta.settings.get('web-push');
|
|
192
190
|
maxLength = parseInt(maxLength, 10) || 256;
|
|
193
191
|
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
// i18n/rtl
|
|
193
|
+
if (!lang) {
|
|
194
|
+
lang = meta.config.defaultLang || 'en-GB';
|
|
196
195
|
}
|
|
196
|
+
const dir = await translator.translate('[[language:dir]]', lang);
|
|
197
197
|
|
|
198
198
|
// Merge with related unread notifications
|
|
199
199
|
if (notification.mergeId) {
|
|
@@ -206,7 +206,7 @@ async function constructPayload(notification, uid, language) {
|
|
|
206
206
|
|
|
207
207
|
const { nid, mergeId, bodyShort, bodyLong, path } = notification;
|
|
208
208
|
|
|
209
|
-
let [title, body] = await translator.translateKeys([bodyShort, bodyLong],
|
|
209
|
+
let [title, body] = await translator.translateKeys([bodyShort, bodyLong], lang);
|
|
210
210
|
([title, body] = [title, body].map(str => validator.unescape(utils.stripHTMLTags(str))));
|
|
211
211
|
const tag = mergeId || nid;
|
|
212
212
|
const url = `${nconf.get('url')}${path}`;
|
|
@@ -229,6 +229,8 @@ async function constructPayload(notification, uid, language) {
|
|
|
229
229
|
title,
|
|
230
230
|
body,
|
|
231
231
|
tag,
|
|
232
|
+
lang,
|
|
233
|
+
dir,
|
|
232
234
|
data: { url, icon, badge },
|
|
233
235
|
};
|
|
234
236
|
}
|