nodebb-plugin-gemach-directory 1.0.0 → 1.0.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 +27 -3
  2. package/package.json +1 -1
package/library.js CHANGED
@@ -7,7 +7,8 @@
7
7
  * חדש (SocketPlugins.gemachDirectory.submit) - הוא נשמר כ"ממתין" ולא
8
8
  * מוצג לאף אחד עד שמנהל מאשר אותו.
9
9
  * - כשמוצע גמ"ח חדש, נשלחת התראת NodeBB אמיתית (פעמון) לכל חברי קבוצת
10
- * "administrators" - כדי שמנהל ידע שיש משהו ממתין לאישור.
10
+ * "administrators" שלא כיבו אצל עצמם את ההתראות (ראו getNotifyPreference/
11
+ * setNotifyPreference למטה - כל מנהל שולט בעצמו, לא משפיע על אחרים).
11
12
  * - אישור/דחייה (SocketPlugins.gemachDirectory.approve/reject) פתוחים רק
12
13
  * למנהלים (נבדק בשרת, לא רק בממשק) - אישור מעביר את הגמ"ח לרשימה
13
14
  * הציבורית באופן מיידי, דחייה מוחקת אותו לגמרי (בלי לצבור "זבל").
@@ -32,6 +33,9 @@ const COUNTER_OBJECT = 'gemachDirectory:counters';
32
33
  const PENDING_SET = 'gemachDirectory:pending';
33
34
  const APPROVED_SET = 'gemachDirectory:approved';
34
35
  const GEMACH_KEY = id => `gemachDirectory:item:${id}`;
36
+ // מפה של uid -> '0'/'1' - האם המנהל הזה רוצה לקבל התראות על גמ"חים חדשים.
37
+ // חסר מפתח = כברירת מחדל כן (כדי שמנהלים קיימים לא "יפספסו" בלי לשים לב).
38
+ const NOTIFY_PREFS_OBJECT = 'gemachDirectory:notifyPrefs';
35
39
 
36
40
  const MAX_LENGTHS = {
37
41
  name: 120,
@@ -123,6 +127,21 @@ function registerSocketHandlers() {
123
127
 
124
128
  return { ok: true };
125
129
  };
130
+
131
+ // כל מנהל בודק/קובע בעצמו אם הוא רוצה לקבל התראות על הצעות חדשות -
132
+ // לא משפיע על שאר המנהלים.
133
+ SocketPlugins.gemachDirectory.getNotifyPreference = async function (socket) {
134
+ await requireAdmin(socket);
135
+ const value = await db.getObjectField(NOTIFY_PREFS_OBJECT, socket.uid);
136
+ return { enabled: value !== '0' };
137
+ };
138
+
139
+ SocketPlugins.gemachDirectory.setNotifyPreference = async function (socket, data) {
140
+ await requireAdmin(socket);
141
+ const enabled = !!(data && data.enabled);
142
+ await db.setObjectField(NOTIFY_PREFS_OBJECT, socket.uid, enabled ? '1' : '0');
143
+ return { ok: true };
144
+ };
126
145
  }
127
146
 
128
147
  async function getGemachsFromSet(setKey, newestFirst) {
@@ -138,6 +157,11 @@ async function notifyAdmins(gemach) {
138
157
  const adminUids = await groups.getMembers('administrators', 0, -1);
139
158
  if (!adminUids || !adminUids.length) return;
140
159
 
160
+ const prefs = (await db.getObject(NOTIFY_PREFS_OBJECT)) || {};
161
+ // חסר מפתח = כברירת מחדל כן (רק '0' מפורש מכבה עבור מנהל ספציפי).
162
+ const targetUids = adminUids.filter(uid => prefs[uid] !== '0');
163
+ if (!targetUids.length) return;
164
+
141
165
  const notification = await notifications.create({
142
166
  type: 'gemach-directory-pending',
143
167
  // nid כולל את מזהה הגמ"ח - כך שכל הצעה חדשה היא התראה "חדשה" נפרדת
@@ -146,7 +170,7 @@ async function notifyAdmins(gemach) {
146
170
  path: '/',
147
171
  from: gemach.submittedBy,
148
172
  });
149
- await notifications.push(notification, adminUids);
173
+ await notifications.push(notification, targetUids);
150
174
  }
151
175
 
152
176
  function requireLogin(socket) {
@@ -173,4 +197,4 @@ function sanitizeText(value, maxLength) {
173
197
  return stripped.slice(0, maxLength);
174
198
  }
175
199
 
176
- module.exports = plugin;
200
+ module.exports = plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-gemach-directory",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Server-side storage + admin approval queue for a community gemach directory, filterable by city and category.",
5
5
  "main": "library.js",
6
6
  "keywords": [