Skip to content

Commit 14f13ec

Browse files
committed
feat: restore compatibility with v2.x (tested with v2.8.x)
1 parent 01cf2e4 commit 14f13ec

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

lib/controllers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Controllers.renderSettings = async function (req, res) {
2424
payload.title = '[[ntfy:profile.label]]';
2525
payload.breadcrumbs = helpers.buildBreadcrumbs([{ text: username, url: `/user/${userslug}` }, { text: payload.title }]);
2626

27+
// v2 compatibility
28+
if (nconf.get('version').startsWith('2')) {
29+
const v2payload = { ...res.locals.templateValues, ...payload };
30+
return res.render('account/ntfy-v2', v2payload);
31+
}
32+
2733
res.render('account/ntfy', payload);
2834
};
2935

library.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,19 @@ plugin.init = async (params) => {
2222
middleware.ensureLoggedIn,
2323
middleware.canViewUsers,
2424
middleware.checkAccountPermissions,
25-
middleware.buildAccountData,
2625
];
2726

27+
// v2 compatibility
28+
if (!nconf.get('version').startsWith('2')) {
29+
accountMiddlewares.push(middleware.buildAccountData);
30+
} else {
31+
const accountHelpers = require.main.require('./src/controllers/accounts/helpers');
32+
accountMiddlewares.push(async (req, res, next) => {
33+
res.locals.templateValues = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);
34+
next();
35+
});
36+
}
37+
2838
routeHelpers.setupPageRoute(router, '/user/:userslug/ntfy', accountMiddlewares, controllers.renderSettings);
2939
};
3040

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"readmeFilename": "README.md",
3333
"nbbpm": {
34-
"compatibility": "^3.0.0"
34+
"compatibility": "^2.8.x || ^3.0.0"
3535
},
3636
"devDependencies": {
3737
"@commitlint/cli": "17.6.6",

plugin.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"staticDirs": {
1313
"static": "./static"
1414
},
15+
"scripts": [
16+
"static/lib/main.js"
17+
],
1518
"modules": {
1619
"../client/account/ntfy.js": "./static/lib/modules/settings.js",
1720
"../admin/plugins/ntfy.js": "./static/lib/admin.js"

static/lib/main.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
(async () => {
4+
const hooks = await app.require('hooks');
5+
6+
hooks.on('filter:script.load', ({ tpl_url, scripts }) => {
7+
if (tpl_url === 'account/ntfy-v2') {
8+
scripts.splice(scripts.indexOf('forum/account/ntfy-v2'), 1, 'forum/account/ntfy');
9+
}
10+
11+
return { tpl_url, scripts };
12+
});
13+
})();
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<div class="account">
2+
<!-- IMPORT partials/account/header.tpl -->
3+
4+
<div class="row">
5+
<div class="panel panel-default col-xs-12 col-lg-offset-2 col-lg-8" style="margin-top: 1rem;">
6+
<div class="panel-body">
7+
<p>
8+
<a href="https://play.google.com/store/apps/details?id=io.heckel.ntfy">
9+
<img src="https://docs.ntfy.sh/static/img/badge-googleplay.png">
10+
</a>
11+
<a href="https://f-droid.org/en/packages/io.heckel.ntfy/">
12+
<img src="https://docs.ntfy.sh/static/img/badge-fdroid.png">
13+
</a>
14+
<a href="https://apps.apple.com/us/app/ntfy/id1625396347">
15+
<img src="https://docs.ntfy.sh/static/img/badge-appstore.png">
16+
</a>
17+
</p>
18+
<p>
19+
A mobile device is not necessary, <a href="https://docs.ntfy.sh/subscribe/web/">you can also subscribe to push notifications via your browser.</a>
20+
</p>
21+
22+
<hr />
23+
24+
<p><strong>Your private push notification "topic name" is:</strong></p>
25+
<div class="input-group" style="margin-bottom: 1rem;">
26+
<input id="topic" type="text" class="form-control" value="{ntfyTopic}" readonly />
27+
<span class="input-group-btn">
28+
<a class="btn btn-success" href="{ntfyUrl}">[[ntfy:profile.subscribe]]</a>
29+
</span>
30+
</div>
31+
<!-- TODO: separate server url if specified in ACP -->
32+
<p>
33+
<em>Treat this topic name like a password!</em>
34+
</p>
35+
<p>
36+
If the topic name is leaked, it can be used by others to receive your notifications.
37+
</p>
38+
<button class="btn btn-primary" data-action="test">[[ntfy:profile.test]]</button>
39+
<button class="btn btn-danger" data-action="regenerate">[[ntfy:profile.regenerate]]</button>
40+
</div>
41+
</div>
42+
</div>

0 commit comments

Comments
 (0)