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.
Files changed (2) hide show
  1. package/library.js +16 -14
  2. 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 webPush.sendNotification(subscription, JSON.stringify({
98
- title: 'Test notification',
99
- body: 'This is a test message sent from NodeBB',
100
- tag: 'web-push-test',
101
- data: {
102
- url: `${nconf.get('url')}/me/web-push`,
103
- icon: `${nconf.get('url')}/apple-touch-icon`,
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, language) {
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
- if (!language) {
195
- language = meta.config.defaultLang || 'en-GB';
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], language);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-web-push",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "A starter kit for quickly creating NodeBB plugins",
5
5
  "main": "library.js",
6
6
  "repository": {