mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 12:16:31 +02:00
Merge branch 'master' into user_groups
This commit is contained in:
@@ -15,6 +15,7 @@ var RDB = require('./redis.js'),
|
||||
|
||||
var category_name = categoryData.name,
|
||||
category_slug = categoryData.slug,
|
||||
disabled = categoryData.disabled || '0',
|
||||
category_description = categoryData.description;
|
||||
|
||||
function getTopicIds(next) {
|
||||
@@ -32,6 +33,7 @@ var RDB = require('./redis.js'),
|
||||
var categoryData = {
|
||||
'category_name' : category_name,
|
||||
'category_description': category_description,
|
||||
'disabled': disabled,
|
||||
'show_sidebar' : 'show',
|
||||
'show_topic_button': 'inline-block',
|
||||
'no_topics_message': 'hidden',
|
||||
|
||||
@@ -75,8 +75,7 @@ var async = require('async'),
|
||||
server_conf = config,
|
||||
client_conf = {
|
||||
socket: {
|
||||
address: protocol + '//' + host,
|
||||
port: config.port
|
||||
address: protocol + '//' + host + (config.use_port ? ':' + config.port : '')
|
||||
},
|
||||
api_url: protocol + '//' + host + (config.use_port ? ':' + config.port : '') + relative_path + '/api/',
|
||||
relative_path: relative_path
|
||||
|
||||
@@ -18,17 +18,19 @@ var fs = require('fs'),
|
||||
RDB.smembers('plugins:active', next);
|
||||
},
|
||||
function(plugins, next) {
|
||||
async.each(plugins, function(plugin) {
|
||||
// TODO: Update this check to also check node_modules
|
||||
var pluginPath = path.join(__dirname, '../plugins/', plugin),
|
||||
modulePath = path.join(__dirname, '../node_modules/', plugin);
|
||||
if (fs.existsSync(pluginPath)) _self.loadPlugin(pluginPath, next);
|
||||
else if (fs.existsSync(modulePath)) _self.loadPlugin(modulePath, next);
|
||||
else {
|
||||
if (global.env === 'development') winston.info('[plugins] Plugin \'' + plugin + '\' not found');
|
||||
next(); // Ignore this plugin silently
|
||||
}
|
||||
}, next);
|
||||
if (plugins && Array.isArray(plugins) && plugins.length > 0) {
|
||||
async.each(plugins, function(plugin) {
|
||||
// TODO: Update this check to also check node_modules
|
||||
var pluginPath = path.join(__dirname, '../plugins/', plugin),
|
||||
modulePath = path.join(__dirname, '../node_modules/', plugin);
|
||||
if (fs.existsSync(pluginPath)) _self.loadPlugin(pluginPath, next);
|
||||
else if (fs.existsSync(modulePath)) _self.loadPlugin(modulePath, next);
|
||||
else {
|
||||
if (global.env === 'development') winston.info('[plugins] Plugin \'' + plugin + '\' not found');
|
||||
next(); // Ignore this plugin silently
|
||||
}
|
||||
}, next);
|
||||
} else next();
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
|
||||
@@ -55,7 +55,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
PostTools.edit = function(uid, pid, title, content) {
|
||||
PostTools.edit = function(uid, pid, title, content, images) {
|
||||
var success = function() {
|
||||
posts.setPostField(pid, 'content', content);
|
||||
posts.setPostField(pid, 'edited', Date.now());
|
||||
@@ -66,6 +66,11 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.uploadPostImages(pid, images, function(err, uploadedImages) {
|
||||
next(err, uploadedImages);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
posts.getPostField(pid, 'tid', function(tid) {
|
||||
PostTools.isMain(pid, tid, function(isMainPost) {
|
||||
@@ -76,7 +81,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
next(null, tid);
|
||||
next(null, {tid:tid, isMainPost:isMainPost});
|
||||
});
|
||||
});
|
||||
},
|
||||
@@ -84,10 +89,12 @@ var RDB = require('./redis.js'),
|
||||
PostTools.toHTML(content, next);
|
||||
}
|
||||
], function(err, results) {
|
||||
io.sockets.in('topic_' + results[0]).emit('event:post_edited', {
|
||||
io.sockets.in('topic_' + results[1].tid).emit('event:post_edited', {
|
||||
pid: pid,
|
||||
title: title,
|
||||
content: results[1]
|
||||
isMainPost: results[1].isMainPost,
|
||||
content: results[2],
|
||||
uploadedImages:results[0]
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -160,7 +167,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
});
|
||||
|
||||
// Restore topic if it is the only post
|
||||
// Restore topic if it is the only post
|
||||
topics.getTopicField(postData.tid, 'postcount', function(err, count) {
|
||||
if (count === '1') {
|
||||
threadTools.restore(postData.tid, uid);
|
||||
@@ -179,6 +186,7 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
PostTools.toHTML = function(raw, callback) {
|
||||
raw = raw || '';
|
||||
plugins.fireHook('filter:post.parse', raw, function(parsed) {
|
||||
var cheerio = require('cheerio');
|
||||
|
||||
|
||||
42
src/posts.js
42
src/posts.js
@@ -332,7 +332,7 @@ var RDB = require('./redis.js'),
|
||||
|
||||
async.parallel({
|
||||
uploadedImages: function(next) {
|
||||
uploadPostImages(postData, images, function(err, uploadedImages) {
|
||||
Posts.uploadPostImages(postData.pid, images, function(err, uploadedImages) {
|
||||
if(err) {
|
||||
winston.error('Uploading images failed!', err.stack);
|
||||
next(null, []);
|
||||
@@ -350,7 +350,6 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
}, function(err, results) {
|
||||
postData.uploadedImages = results.uploadedImages;
|
||||
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(postData.uploadedImages));
|
||||
postData.content = results.content;
|
||||
callback(postData);
|
||||
});
|
||||
@@ -366,41 +365,44 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
function uploadPostImages(postData, images, callback) {
|
||||
Posts.uploadPostImages = function(pid, images, callback) {
|
||||
var imgur = require('./imgur');
|
||||
imgur.setClientID(meta.config.imgurClientID);
|
||||
|
||||
var uploadedImages = [];
|
||||
if(!images)
|
||||
return callback(null, []);
|
||||
|
||||
var uploadedImages = images.filter(function(image) { return !!image.url; });
|
||||
|
||||
function uploadImage(image, next) {
|
||||
if(!image.data)
|
||||
return next(null);
|
||||
|
||||
function uploadImage(image, callback) {
|
||||
imgur.upload(image.data, 'base64', function(err, data) {
|
||||
if(err) {
|
||||
callback(err);
|
||||
next(err);
|
||||
} else {
|
||||
if(data.success) {
|
||||
var img= {url:data.data.link, name:image.name};
|
||||
uploadedImages.push(img);
|
||||
callback(null);
|
||||
next(null);
|
||||
} else {
|
||||
winston.error('Can\'t upload image, did you set imgurClientID?');
|
||||
callback(data);
|
||||
next(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(!images) {
|
||||
callback(null, uploadedImages);
|
||||
} else {
|
||||
async.each(images, uploadImage, function(err) {
|
||||
if(!err) {
|
||||
callback(null, uploadedImages);
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
async.each(images, uploadImage, function(err) {
|
||||
if(!err) {
|
||||
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
|
||||
callback(null, uploadedImages);
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Posts.getPostsByUid = function(uid, start, end, callback) {
|
||||
|
||||
46
src/user.js
46
src/user.js
@@ -7,7 +7,8 @@ var utils = require('./../public/src/utils.js'),
|
||||
bcrypt = require('bcrypt'),
|
||||
notifications = require('./notifications.js'),
|
||||
topics = require('./topics.js'),
|
||||
async = require('async');
|
||||
async = require('async'),
|
||||
userSearch = require('reds').createSearch('nodebbusersearch');
|
||||
|
||||
(function(User) {
|
||||
User.create = function(username, password, email, callback) {
|
||||
@@ -90,6 +91,8 @@ var utils = require('./../public/src/utils.js'),
|
||||
RDB.zadd('users:postcount', 0, uid);
|
||||
RDB.zadd('users:reputation', 0, uid);
|
||||
|
||||
userSearch.index(username, uid);
|
||||
|
||||
io.sockets.emit('user.latest', {userslug: userslug, username: username});
|
||||
|
||||
if (password !== undefined) {
|
||||
@@ -385,25 +388,42 @@ var utils = require('./../public/src/utils.js'),
|
||||
});
|
||||
}
|
||||
|
||||
User.reIndexAll = function(callback) {
|
||||
User.getUsers('users:joindate', 0, -1, function(err, usersData) {
|
||||
if(err) {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
function reIndexUser(uid, username) {
|
||||
userSearch.remove(uid, function(){
|
||||
userSearch.index(username, uid);
|
||||
})
|
||||
}
|
||||
|
||||
for(var i=0; i<usersData.length; ++i) {
|
||||
reIndexUser(usersData[i].uid, usersData[i].username);
|
||||
}
|
||||
callback(null, 1);
|
||||
});
|
||||
}
|
||||
|
||||
User.search = function(username, callback) {
|
||||
if(!username) {
|
||||
callback([]);
|
||||
return;
|
||||
}
|
||||
|
||||
RDB.keys('username:*'+ username + '*:uid', function(err, keys) {
|
||||
if(!err) {
|
||||
if(keys && keys.length) {
|
||||
RDB.mget(keys, function(err, uids) {
|
||||
User.getDataForUsers(uids, function(userdata) {
|
||||
callback(userdata);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback([]);
|
||||
}
|
||||
} else {
|
||||
userSearch.query(query = username).type('or').end(function(err, uids) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
if(uids && uids.length) {
|
||||
User.getDataForUsers(uids, function(userdata) {
|
||||
callback(userdata);
|
||||
});
|
||||
} else {
|
||||
callback([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ var express = require('express'),
|
||||
|
||||
// Middlewares
|
||||
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
|
||||
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public') }));
|
||||
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public'), prefix:nconf.get('relative_path') }));
|
||||
app.use(nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public')));
|
||||
app.use(express.bodyParser()); // Puts POST vars in request.body
|
||||
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
|
||||
@@ -295,6 +295,11 @@ var express = require('express'),
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
categories.getCategoryById(cid, 0, function(err, categoryData) {
|
||||
|
||||
if(categoryData) {
|
||||
if(categoryData.disabled === '1')
|
||||
return next(new Error('Category disabled'), null);
|
||||
}
|
||||
next(err, categoryData);
|
||||
});
|
||||
},
|
||||
@@ -403,10 +408,16 @@ var express = require('express'),
|
||||
app.get('/reindex', function(req, res) {
|
||||
topics.reIndexAll(function(err) {
|
||||
if(err) {
|
||||
res.json(err);
|
||||
} else {
|
||||
res.send('All topics reindexed');
|
||||
return res.json(err);
|
||||
}
|
||||
|
||||
user.reIndexAll(function(err) {
|
||||
if(err) {
|
||||
return res.json(err);
|
||||
} else {
|
||||
res.send('Topics and users reindexed');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,8 +33,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
(function(io) {
|
||||
var users = {},
|
||||
userSockets = {},
|
||||
rooms = {},
|
||||
chats = {};
|
||||
rooms = {};
|
||||
|
||||
global.io = io;
|
||||
|
||||
@@ -58,13 +57,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
socket.emit('event:connect', {status: 1, username:username, uid:uid});
|
||||
|
||||
if(chats[uid]) {
|
||||
for(var i=0; i<chats[uid].length; ++i) {
|
||||
io.sockets.in(chats[uid][i]).emit('chatMessage', {fromuid:uid, username:username, message: username+' came online\n', timestamp: Date.now()});
|
||||
socket.join(chats[uid][i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -83,18 +75,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
delete users[sessionID];
|
||||
if(uid) {
|
||||
io.sockets.in('global').emit('api:user.isOnline', isUserOnline(uid));
|
||||
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
|
||||
if(chats[uid] && chats[uid].length) {
|
||||
|
||||
for(var i=0; i<chats[uid].length; ++i) {
|
||||
|
||||
io.sockets.in(chats[uid][i]).emit('chatGoOffline', {uid:uid, username:username, timestamp:Date.now()});
|
||||
socket.leave(chats[uid][i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,8 +250,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.emit('api:user.get_online_users', returnData);
|
||||
});
|
||||
|
||||
socket.on('api:user.isOnline', function(uid) {
|
||||
socket.emit('api:user.isOnline', isUserOnline(uid));
|
||||
socket.on('api:user.isOnline', function(uid, callback) {
|
||||
callback({online:isUserOnline(uid), timestamp:Date.now()});
|
||||
});
|
||||
|
||||
socket.on('api:user.changePassword', function(data, callback) {
|
||||
@@ -364,7 +344,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.emit('event:alert', {
|
||||
title: 'Thank you for posting',
|
||||
message: 'You have successfully posted. Click here to view your post.',
|
||||
type: 'warning',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
}
|
||||
@@ -417,7 +397,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.emit('event:alert', {
|
||||
title: 'Reply Successful',
|
||||
message: 'You have successfully replied. Click here to view your reply.',
|
||||
type: 'warning',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
|
||||
@@ -497,7 +477,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
posts.emitContentTooShortAlert(socket);
|
||||
return;
|
||||
}
|
||||
postTools.edit(uid, data.pid, data.title, data.content);
|
||||
postTools.edit(uid, data.pid, data.title, data.content, data.images);
|
||||
});
|
||||
|
||||
socket.on('api:posts.delete', function(data) {
|
||||
@@ -549,15 +529,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
|
||||
var msg = utils.strip_tags(data.message);
|
||||
|
||||
var uids = [uid, touid].sort();
|
||||
var chatroom = 'chatroom_'+uids[0]+'_'+uids[1];
|
||||
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
var finalMessage = username + ': ' + msg,
|
||||
var finalMessage = username + ' : ' + msg,
|
||||
notifText = 'New message from <strong>' + username + '</strong>';
|
||||
|
||||
if(!isUserOnline(touid)) {
|
||||
notifications.create(notifText, 5, '#', 'notification_' + uid + '_' + touid, function(nid) {
|
||||
notifications.create(notifText, 5, 'javascript:app.openChat(''+username+'', '+uid+');', 'notification_' + uid + '_' + touid, function(nid) {
|
||||
notifications.push(nid, [touid], function(success) {
|
||||
|
||||
});
|
||||
@@ -571,13 +548,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
numSockets = userSockets[touid].length;
|
||||
|
||||
for(var x=0; x<numSockets; ++x) {
|
||||
userSockets[touid][x].join(chatroom);
|
||||
userSockets[touid][x].emit('chatMessage', {fromuid:uid, username:username, message: finalMessage, timestamp: Date.now()});
|
||||
}
|
||||
|
||||
chats[touid] = chats[touid] || [];
|
||||
if(chats[touid].indexOf(chatroom) === -1)
|
||||
chats[touid].push(chatroom);
|
||||
}
|
||||
|
||||
if(userSockets[uid]) {
|
||||
@@ -585,13 +557,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
numSockets = userSockets[uid].length;
|
||||
|
||||
for(var x=0; x<numSockets; ++x) {
|
||||
userSockets[uid][x].join(chatroom);
|
||||
userSockets[uid][x].emit('chatMessage', {fromuid:touid, username:username, message:'You : ' + msg, timestamp: Date.now()});
|
||||
}
|
||||
|
||||
chats[uid] = chats[uid] || [];
|
||||
if(chats[uid].indexOf(chatroom) === -1)
|
||||
chats[uid].push(chatroom);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -617,7 +584,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
if (uid > 0) {
|
||||
if (parseInt(data.tid) > 0) {
|
||||
topics.getTopicData(data.tid, function(topicData) {
|
||||
|
||||
if (data.body)
|
||||
topicData.body = data.body;
|
||||
|
||||
@@ -640,9 +606,17 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
}
|
||||
});
|
||||
} else if (parseInt(data.pid) > 0) {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.getPostField(data.pid, 'content', function(raw) {
|
||||
posts.getPostFields(data.pid, ['content', 'uploadedImages'], function(raw) {
|
||||
try {
|
||||
raw.uploadedImages = JSON.parse(raw.uploadedImages);
|
||||
} catch(e) {
|
||||
winston.err(e);
|
||||
raw.uploadedImages = [];
|
||||
}
|
||||
|
||||
next(null, raw);
|
||||
});
|
||||
},
|
||||
@@ -655,7 +629,8 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.emit('api:composer.push', {
|
||||
title: results[1],
|
||||
pid: data.pid,
|
||||
body: results[0]
|
||||
body: results[0].content,
|
||||
uploadedImages: results[0].uploadedImages
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user