nodebb-plugin-poll 4.0.6 → 4.0.8
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/lib/hooks.js +8 -3
- package/package.json +2 -2
- package/public/js/poll/creator.js +10 -13
package/lib/hooks.js
CHANGED
|
@@ -68,7 +68,12 @@ Hooks.filter.postGetFields = async function (hookData) {
|
|
|
68
68
|
|
|
69
69
|
Hooks.filter.postEdit = async function (hookData) {
|
|
70
70
|
const currentPollIds = await Poll.getPollIdsByPid(hookData.data.pid);
|
|
71
|
-
|
|
71
|
+
if (!currentPollIds.length && (!Array.isArray(hookData.data.polls) || !hookData.data.polls.length)) {
|
|
72
|
+
// no polls before or after, nothing to do
|
|
73
|
+
return hookData;
|
|
74
|
+
}
|
|
75
|
+
const pollData = hookData.data.polls || [];
|
|
76
|
+
const toAdd = pollData.filter(p => !currentPollIds.includes(String(p.pollId)));
|
|
72
77
|
|
|
73
78
|
if (toAdd.length) {
|
|
74
79
|
const cid = await posts.getCidByPid(hookData.data.pid, 'cid');
|
|
@@ -79,8 +84,8 @@ Hooks.filter.postEdit = async function (hookData) {
|
|
|
79
84
|
...hookData.post,
|
|
80
85
|
uid: hookData.data.uid,
|
|
81
86
|
pid: hookData.data.pid,
|
|
82
|
-
},
|
|
83
|
-
hookData.post.pollIds = JSON.stringify(
|
|
87
|
+
}, pollData);
|
|
88
|
+
hookData.post.pollIds = JSON.stringify(pollData.map(p => String(p.pollId)));
|
|
84
89
|
return hookData;
|
|
85
90
|
};
|
|
86
91
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-poll",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
4
4
|
"description": "NodeBB Poll Plugin",
|
|
5
5
|
"main": "library.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"cron": "^1.8.2"
|
|
27
27
|
},
|
|
28
28
|
"nbbpm": {
|
|
29
|
-
"compatibility": "^4.
|
|
29
|
+
"compatibility": "^4.12.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"eslint": "10.0.3",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
formatting.addButtonDispatch('poll', function (/* textarea */) {
|
|
14
14
|
onPollButtonClicked(composer);
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
updateComposerBadgeCount(
|
|
16
|
+
const uuid = postContainer.attr('data-uuid');
|
|
17
|
+
updateComposerBadgeCount(uuid, postData.polls ? postData.polls.length : 0);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
}
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
postData.polls.push(newPoll);
|
|
70
70
|
}
|
|
71
71
|
openManageModal({ ...payload, modal });
|
|
72
|
-
|
|
73
|
-
updateComposerBadgeCount(
|
|
72
|
+
|
|
73
|
+
updateComposerBadgeCount(uuid, postData.polls.length);
|
|
74
74
|
});
|
|
75
75
|
return false;
|
|
76
76
|
},
|
|
@@ -100,8 +100,7 @@
|
|
|
100
100
|
if (poll) {
|
|
101
101
|
postData.polls = postData.polls.filter(poll => String(poll.pollId) !== clickedPollId);
|
|
102
102
|
openManageModal(payload);
|
|
103
|
-
|
|
104
|
-
updateComposerBadgeCount(postContainer, postData.polls.length);
|
|
103
|
+
updateComposerBadgeCount(uuid, postData.polls.length);
|
|
105
104
|
}
|
|
106
105
|
});
|
|
107
106
|
});
|
|
@@ -270,13 +269,11 @@
|
|
|
270
269
|
});
|
|
271
270
|
}
|
|
272
271
|
|
|
273
|
-
function updateComposerBadgeCount(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
count
|
|
279
|
-
);
|
|
272
|
+
function updateComposerBadgeCount(uuid, count) {
|
|
273
|
+
$(window).trigger('action:composer.updateFormattingBtnBadgeCount', {
|
|
274
|
+
uuid: uuid,
|
|
275
|
+
formatName: 'poll',
|
|
276
|
+
count,
|
|
280
277
|
});
|
|
281
278
|
}
|
|
282
279
|
|