nodebb-plugin-discord-onekite 1.0.3 → 1.0.4

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.2
1
+ # nodebb-plugin-discord-onekite (NodeBB v4.x) — v1.0.3
2
2
 
3
- Fix ACP issues:
4
- - Uses `modules` mapping so `require('admin/plugins/discord-onekite')` always resolves.
5
- - Multi-select uses `name="cids[]"` so selections persist.
6
- - Also hooks `action:ajaxify.end` as a fallback in admin to re-init after navigation.
3
+ This version aligns more closely with the official Quickstart pattern:
4
+ - uses `modules` mapping (no leading ./) to expose `admin/plugins/discord-onekite`
5
+ - template has no inline script
6
+ - admin.js logs `[discord-onekite] admin init` when loaded
7
7
 
8
- Requirement: no categories selected => notify all.
8
+ If you still don't see that log, NodeBB isn't loading the module, so we can narrow it down quickly.
package/library.js CHANGED
@@ -21,7 +21,6 @@ function normalizeCids(value) {
21
21
 
22
22
  async function getSettings() {
23
23
  const s = await meta.settings.get(SETTINGS_KEY);
24
- // Note: when select name is cids[], nodebb may save it as array or comma string; normalize handles both.
25
24
  return {
26
25
  webhookUrl: (s && s.webhookUrl) ? String(s.webhookUrl).trim() : '',
27
26
  notifyReplies: !!(s && (s.notifyReplies === true || s.notifyReplies === 'on' || s.notifyReplies === 'true')),
@@ -30,7 +29,7 @@ async function getSettings() {
30
29
  }
31
30
 
32
31
  function cidAllowed(topicCid, allowedCids) {
33
- if (!allowedCids || allowedCids.length === 0) return true; // none selected => ALL
32
+ if (!allowedCids || allowedCids.length === 0) return true;
34
33
  return allowedCids.includes(String(topicCid));
35
34
  }
36
35
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-discord-onekite",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "id": "nodebb-plugin-discord-onekite",
3
3
  "name": "Discord Onekite Notifier",
4
4
  "description": "Notifie Discord via webhook pour nouveaux sujets et/ou réponses, filtrable par catégories (NodeBB v4.x uniquement).",
5
- "library": "./library.js",
5
+ "library": "library.js",
6
6
  "hooks": [
7
7
  { "hook": "static:app.load", "method": "init" },
8
8
  { "hook": "filter:admin.header.build", "method": "addAdminNavigation" },
@@ -11,6 +11,6 @@
11
11
  ],
12
12
  "templates": "static/templates",
13
13
  "modules": {
14
- "../admin/plugins/discord-onekite.js": "./static/lib/admin.js"
14
+ "../admin/plugins/discord-onekite.js": "static/lib/admin.js"
15
15
  }
16
16
  }
@@ -3,7 +3,6 @@
3
3
 
4
4
  define('admin/plugins/discord-onekite', ['settings', 'api'], function (settings, api) {
5
5
  const ACP = {};
6
- let initialized = false;
7
6
 
8
7
  function normalizeCids(v) {
9
8
  if (!v) return [];
@@ -12,69 +11,57 @@ define('admin/plugins/discord-onekite', ['settings', 'api'], function (settings,
12
11
  return [];
13
12
  }
14
13
 
15
- async function loadCategoriesIntoSelect(savedCids) {
16
- const $select = $('#cids');
17
- if (!$select.length) return;
18
-
14
+ async function fetchCategories() {
15
+ // In NodeBB, api.get('/categories') => GET /api/categories
19
16
  const res = await api.get('/categories');
20
-
21
- // Depending on endpoint, categories may be at res.categories or res.category
22
- const categories = (res && (res.categories || res.category || res.data || [])) || [];
23
- const list = Array.isArray(categories) ? categories : [];
24
-
25
- $select.empty();
26
- list
27
- .filter(c => c && typeof c.cid !== 'undefined' && c.name)
28
- .forEach(c => {
29
- const cid = String(c.cid);
30
- const $opt = $('<option />').val(cid).text(c.name);
31
- if (savedCids.includes(cid)) $opt.prop('selected', true);
32
- $opt.appendTo($select);
33
- });
17
+ return (res && res.categories) ? res.categories : [];
34
18
  }
35
19
 
36
20
  ACP.init = async function () {
37
- // NodeBB will call init() on page load for template admin/plugins/discord-onekite.
38
- // But ACP is ajaxified; ensure we don't double-bind.
39
- if (initialized) {
40
- return;
41
- }
42
- initialized = true;
21
+ // This should be called automatically by NodeBB when template admin/plugins/discord-onekite is loaded.
22
+ // Also safe to call multiple times.
23
+ console.log('[discord-onekite] admin init');
43
24
 
44
25
  const $form = $('.discord-onekite-settings');
45
26
  if (!$form.length) return;
46
27
 
47
- // 1) Load raw settings first (to get cids)
28
+ // Load current settings
48
29
  const saved = await new Promise((resolve) => {
49
30
  settings.get('discord-onekite', (data) => resolve(data || {}));
50
31
  });
51
32
 
52
- const savedCids = normalizeCids(saved.cids);
53
-
54
- // 2) Populate fields
55
33
  settings.load('discord-onekite', $form);
34
+ const savedCids = normalizeCids(saved.cids);
56
35
 
57
- // 3) Populate categories + apply selection
36
+ // Populate categories select
37
+ const $select = $('#cids');
58
38
  try {
59
- await loadCategoriesIntoSelect(savedCids);
39
+ const categories = await fetchCategories();
40
+ $select.empty();
41
+ categories
42
+ .filter(c => c && typeof c.cid !== 'undefined' && c.name)
43
+ .forEach(c => {
44
+ const cid = String(c.cid);
45
+ const $opt = $('<option />').val(cid).text(c.name);
46
+ if (savedCids.includes(cid)) $opt.prop('selected', true);
47
+ $opt.appendTo($select);
48
+ });
60
49
  } catch (e) {
61
- // eslint-disable-next-line no-console
62
- console.error('[discord-onekite] categories load failed', e);
63
- app.alertError('Impossible de charger la liste des catégories.');
50
+ console.error('[discord-onekite] failed to fetch categories', e);
51
+ if (app && app.alertError) app.alertError('Impossible de charger la liste des catégories (GET /api/categories).');
64
52
  }
65
53
 
66
- // 4) Save
54
+ // Save
67
55
  $('#save').off('click.discordOnekite').on('click.discordOnekite', function () {
68
56
  settings.save('discord-onekite', $form, function () {
69
- app.alertSuccess('Paramètres enregistrés !');
57
+ if (app && app.alertSuccess) app.alertSuccess('Paramètres enregistrés !');
70
58
  });
71
59
  });
72
60
  };
73
61
 
74
- // In case NodeBB doesn't call init (theme/custom admin), also listen for ajaxify end
75
- $(window).off('action:ajaxify.end.discordOnekite').on('action:ajaxify.end.discordOnekite', function () {
76
- if (ajaxify && ajaxify.data && ajaxify.data.template === 'admin/plugins/discord-onekite') {
77
- initialized = false;
62
+ // Fallback for ajaxified ACP navigation
63
+ $(window).off('action:ajaxify.end.discordOnekite').on('action:ajaxify.end.discordOnekite', function (ev, data) {
64
+ if (data && data.template === 'admin/plugins/discord-onekite') {
78
65
  ACP.init();
79
66
  }
80
67
  });
@@ -19,10 +19,13 @@
19
19
 
20
20
  <div class="mb-3">
21
21
  <label class="form-label" for="cids">Catégories à notifier</label>
22
- <select class="form-select" id="cids" name="cids[]" multiple size="12"></select>
22
+ <select class="form-select" id="cids" name="cids" multiple size="12"></select>
23
23
  <p class="form-text text-muted">
24
24
  Si aucune catégorie n’est sélectionnée : <strong>toutes les catégories</strong> seront notifiées.
25
25
  </p>
26
+ <p class="form-text">
27
+ <em>Astuce debug :</em> ouvre la console navigateur, tu dois voir <code>[discord-onekite] admin init</code>.
28
+ </p>
26
29
  </div>
27
30
 
28
31
  <!-- IMPORT admin/partials/save_button.tpl -->