nodebb-plugin-poll 4.0.6 → 4.0.7
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 +1 -1
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
|
|