nodebb-plugin-web-push 0.3.0 → 0.4.0
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 +10 -1
- package/package.json +1 -1
- package/templates/admin/plugins/web-push.tpl +8 -3
package/library.js
CHANGED
|
@@ -127,7 +127,8 @@ plugin.onNotificationPush = async ({ notification, uidsNotified: uids }) => {
|
|
|
127
127
|
await webPush.sendNotification(subscription, JSON.stringify(payload));
|
|
128
128
|
} catch (e) {
|
|
129
129
|
// Errored — remove subscription from user
|
|
130
|
-
|
|
130
|
+
winston.info(`[plugins/web-push] Push failed: ${e.code}; ${e.message}; statusCode: ${e.statusCode}`);
|
|
131
|
+
// subscriptions.remove(uid, subscription);
|
|
131
132
|
}
|
|
132
133
|
});
|
|
133
134
|
});
|
|
@@ -153,6 +154,9 @@ plugin.addProfileItem = async (data) => {
|
|
|
153
154
|
};
|
|
154
155
|
|
|
155
156
|
async function constructPayload({ bodyShort, bodyLong, path }, language) {
|
|
157
|
+
let { maxLength } = await meta.settings.get('web-push');
|
|
158
|
+
maxLength = parseInt(maxLength, 10) || 256;
|
|
159
|
+
|
|
156
160
|
if (!language) {
|
|
157
161
|
language = meta.config.defaultLang || 'en-GB';
|
|
158
162
|
}
|
|
@@ -167,6 +171,11 @@ async function constructPayload({ bodyShort, bodyLong, path }, language) {
|
|
|
167
171
|
title = meta.config.title || 'NodeBB';
|
|
168
172
|
}
|
|
169
173
|
|
|
174
|
+
// Truncate body if needed
|
|
175
|
+
if (body.length > maxLength) {
|
|
176
|
+
body = `${body.slice(0, maxLength)}…`;
|
|
177
|
+
}
|
|
178
|
+
|
|
170
179
|
return {
|
|
171
180
|
title,
|
|
172
181
|
body,
|
package/package.json
CHANGED
|
@@ -7,9 +7,14 @@
|
|
|
7
7
|
<div class="mb-4">
|
|
8
8
|
<h5 class="fw-bold tracking-tight settings-header">Settings</h5>
|
|
9
9
|
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
<div class="mb-3">
|
|
11
|
+
<label class="form-label" for="maxLength">Maximum length</label>
|
|
12
|
+
<input type="number" min="0" max="4096" id="maxLength" name="maxLength" title="Maximum message length" class="form-control" placeholder="256">
|
|
13
|
+
<p class="form-text">
|
|
14
|
+
Additional characters beyond this specified length will be truncated.
|
|
15
|
+
Due to a software limitation, if the message body is greater than 4096 bytes, the message itself will be an attachment in the push notification.
|
|
16
|
+
</p>
|
|
17
|
+
</div>
|
|
13
18
|
</div>
|
|
14
19
|
</form>
|
|
15
20
|
|