nodebb-plugin-poll 3.1.4 → 3.1.5
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/nodebb.js +1 -0
- package/lib/poll.js +4 -5
- package/lib/sockets.js +21 -10
- package/package.json +1 -1
- package/public/js/poll/main.js +8 -0
package/lib/nodebb.js
CHANGED
|
@@ -8,6 +8,7 @@ module.exports = {
|
|
|
8
8
|
Posts: require.main.require('./src/posts'),
|
|
9
9
|
Topics: require.main.require('./src/topics'),
|
|
10
10
|
Privileges: require.main.require('./src/privileges'),
|
|
11
|
+
Plugins: require.main.require('./src/plugins'),
|
|
11
12
|
PluginSockets: require.main.require('./src/socket.io/plugins'),
|
|
12
13
|
AdminSockets: require.main.require('./src/socket.io/admin').plugins,
|
|
13
14
|
SocketIndex: require.main.require('./src/socket.io/index'),
|
package/lib/poll.js
CHANGED
|
@@ -37,17 +37,17 @@ const Scheduler = require('./scheduler');
|
|
|
37
37
|
async.apply(async.series, [
|
|
38
38
|
// Save poll options in parallel
|
|
39
39
|
async.apply(
|
|
40
|
-
async.parallel,
|
|
40
|
+
async.parallel,
|
|
41
41
|
pollData.options.map(
|
|
42
|
-
|
|
42
|
+
option => async.apply(NodeBB.db.setObject, `poll:${pollId}:options:${option.id}`, option)
|
|
43
43
|
),
|
|
44
44
|
),
|
|
45
|
-
// Add poll option id to option list synchronously
|
|
45
|
+
// Add poll option id to option list synchronously
|
|
46
46
|
// To avoid race condition causing duplicate error
|
|
47
47
|
async.apply(
|
|
48
48
|
async.series,
|
|
49
49
|
pollData.options.map(
|
|
50
|
-
|
|
50
|
+
option => async.apply(NodeBB.db.setAdd, `poll:${pollId}:options`, option.id)
|
|
51
51
|
),
|
|
52
52
|
),
|
|
53
53
|
]),
|
|
@@ -56,7 +56,6 @@ const Scheduler = require('./scheduler');
|
|
|
56
56
|
async.apply(NodeBB.db.listAppend, 'polls', pollId),
|
|
57
57
|
async.apply(NodeBB.db.setObjectField, `topic:${poll.tid}`, 'pollId', pollId),
|
|
58
58
|
], (err) => {
|
|
59
|
-
|
|
60
59
|
if (err) {
|
|
61
60
|
return callback(err);
|
|
62
61
|
}
|
package/lib/sockets.js
CHANGED
|
@@ -36,8 +36,7 @@ const Vote = require('./vote');
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
pollData.optionType = parseInt(pollData.settings.maxvotes, 10) > 1 ? 'checkbox' : 'radio';
|
|
39
|
-
|
|
40
|
-
return callback(null, pollData);
|
|
39
|
+
callback(null, pollData);
|
|
41
40
|
});
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -188,22 +187,34 @@ const Vote = require('./vote');
|
|
|
188
187
|
if (!socket.uid || !data || isNaN(parseInt(data.pollId, 10)) || isNaN(parseInt(data.optionId, 10))) {
|
|
189
188
|
return callback(new Error('Invalid request'));
|
|
190
189
|
}
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
async.parallel({
|
|
191
|
+
poll: function (next) {
|
|
192
|
+
Poll.getInfo(data.pollId, next);
|
|
193
|
+
},
|
|
194
|
+
option: function (next) {
|
|
195
|
+
Poll.getOption(data.pollId, data.optionId, true, next);
|
|
196
|
+
},
|
|
197
|
+
}, (err, result) => {
|
|
193
198
|
if (err) {
|
|
194
199
|
return callback(new Error('Something went wrong!'));
|
|
195
200
|
}
|
|
196
|
-
|
|
197
|
-
if (!
|
|
198
|
-
return callback(null,
|
|
201
|
+
const { poll, option } = result;
|
|
202
|
+
if (!option.votes || !option.votes.length) {
|
|
203
|
+
return callback(null, option);
|
|
199
204
|
}
|
|
200
205
|
|
|
201
|
-
NodeBB.User.getUsersFields(
|
|
206
|
+
NodeBB.User.getUsersFields(option.votes, ['uid', 'username', 'userslug', 'picture'], (err, userData) => {
|
|
202
207
|
if (err) {
|
|
203
208
|
console.error(err);
|
|
209
|
+
return callback(err);
|
|
204
210
|
}
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
option.votes = userData;
|
|
212
|
+
NodeBB.Plugins.hooks.fire('filter:poll.getOptionDetails', {
|
|
213
|
+
poll,
|
|
214
|
+
option,
|
|
215
|
+
}, (err, result) => {
|
|
216
|
+
callback(err, result.option);
|
|
217
|
+
});
|
|
207
218
|
});
|
|
208
219
|
});
|
|
209
220
|
};
|
package/package.json
CHANGED
package/public/js/poll/main.js
CHANGED
|
@@ -16,6 +16,14 @@ window.Poll = {};
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
$(window).on('action:posts.loaded', function (ev, data) {
|
|
20
|
+
data.posts.forEach((post) => {
|
|
21
|
+
if (post.hasOwnProperty('pollId')) {
|
|
22
|
+
getPoll(post.pollId);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
19
27
|
$(window).on('action:posts.edited', function (ev, data) {
|
|
20
28
|
if (data.post.hasOwnProperty('pollId')) {
|
|
21
29
|
getPoll(data.post.pollId);
|