forked from NodeBB/nodebb-plugin-composer-default
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsockets.js
91 lines (76 loc) · 2.42 KB
/
websockets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"use strict";
var async = require.main.require('async'),
meta = require.main.require('./src/meta'),
privileges = require.main.require('./src/privileges'),
posts = require.main.require('./src/posts'),
topics = require.main.require('./src/topics'),
plugins = require.main.require('./src/plugins'),
server = require.main.require('./src/socket.io'),
Sockets = {};
Sockets.push = function(socket, pid, callback) {
privileges.posts.can('topics:read', pid, socket.uid, function(err, canRead) {
if (err || !canRead) {
return callback(err || new Error('[[error:no-privileges]]'));
}
posts.getPostFields(pid, ['content', 'tid', 'uid', 'handle'], function(err, postData) {
if(err || (!postData && !postData.content)) {
return callback(err || new Error('[[error:invalid-pid]]'));
}
async.parallel({
topic: function(next) {
topics.getTopicDataByPid(pid, next);
},
tags: function(next) {
topics.getTopicTags(postData.tid, next);
},
isMain: function(next) {
posts.isMain(pid, next);
}
}, function(err, results) {
if(err) {
return callback(err);
}
if (!results.topic) {
return callback(new Error('[[error:no-topic]]'));
}
callback(null, {
pid: pid,
uid: postData.uid,
handle: parseInt(meta.config.allowGuestHandles, 10) ? postData.handle : undefined,
body: postData.content,
title: results.topic.title,
thumb: results.topic.thumb,
tags: results.tags,
isMain: results.isMain
});
});
});
});
};
Sockets.editCheck = function(socket, pid, callback) {
posts.isMain(pid, function(err, isMain) {
callback(err, {
titleEditable: isMain
});
});
};
Sockets.renderPreview = function(socket, content, callback) {
plugins.fireHook('filter:parse.raw', content, callback);
};
Sockets.renderHelp = function(socket, data, callback) {
var helpText = meta.config['composer:customHelpText'] || '';
if (meta.config['composer:showHelpTab'] === '0') {
return callback(new Error('help-hidden'));
}
plugins.fireHook('filter:parse.raw', helpText, function(err, helpText) {
if (!meta.config['composer:allowPluginHelp'] || meta.config['composer:allowPluginHelp'] === '1') {
plugins.fireHook('filter:composer.help', helpText, callback);
} else {
callback(null, helpText);
}
});
};
Sockets.getFormattingOptions = function(socket, data, callback) {
module.parent.exports.getFormattingOptions(callback);
};
module.exports = Sockets;