mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-23 04:40:36 +01:00
Merge branch 'master' of github.com:designcreateplay/NodeBB
This commit is contained in:
@@ -8,29 +8,178 @@ var async = require('async'),
|
||||
(function (Favourites) {
|
||||
"use strict";
|
||||
|
||||
function vote(type, unvote, pid, room_id, uid, socket, callback) {
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
if (uid === 0) {
|
||||
return socket.emit('event:alert', {
|
||||
alert_id: 'post_vote',
|
||||
title: '[[topic:vote.not_logged_in.title]]',
|
||||
message: '[[topic:vote.not_logged_in.message]]',
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['uid', 'timestamp'], function (err, postData) {
|
||||
if (uid === parseInt(postData.uid, 10)) {
|
||||
socket.emit('event:alert', {
|
||||
alert_id: 'post_vote',
|
||||
title: '[[topic:vote.cant_vote_self.title]]',
|
||||
message: '[[topic:vote.cant_vote_self.message]]',
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback(false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
db[type === 'upvote' || !unvote ? 'sortedSetAdd' : 'sortedSetRemove']('uid:' + uid + ':upvote', postData.timestamp, pid);
|
||||
db[type === 'upvote' || unvote ? 'sortedSetRemove' : 'sortedSetAdd']('uid:' + uid + ':downvote', postData.timestamp, pid);
|
||||
|
||||
user[type === 'upvote' ? 'incrementUserFieldBy' : 'decrementUserFieldBy'](postData.uid, 'reputation', 1, function (err, newreputation) {
|
||||
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
|
||||
});
|
||||
|
||||
if (room_id) {
|
||||
websockets.in(room_id).emit('event:' + (type === 'upvote' ? 'rep_up' : 'rep_down'), {
|
||||
uid: postData.uid,
|
||||
pid: pid
|
||||
});
|
||||
}
|
||||
|
||||
socket.emit('posts.' + (unvote ? 'unvote' : type), {
|
||||
pid: pid
|
||||
});
|
||||
|
||||
adjustPostVotes(pid, uid, type, unvote, function() {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function adjustPostVotes(pid, uid, type, unvote, callback) {
|
||||
var notType = (type === 'upvote' ? 'downvote' : 'upvote');
|
||||
|
||||
async.series([
|
||||
function(next) {
|
||||
if (unvote) {
|
||||
db.setRemove('pid:' + pid + ':' + type, uid, function(err) {
|
||||
next(err);
|
||||
});
|
||||
} else {
|
||||
db.setAdd('pid:' + pid + ':' + type, uid, function(err) {
|
||||
next(err);
|
||||
});
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
db.setRemove('pid:' + pid + ':' + notType, uid, function(err) {
|
||||
next(err);
|
||||
});
|
||||
}
|
||||
], function(err) {
|
||||
async.parallel({
|
||||
upvotes: function(next) {
|
||||
db.setCount('pid:' + pid + ':upvote', next);
|
||||
},
|
||||
downvotes: function(next) {
|
||||
db.setCount('pid:' + pid + ':downvote', next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
posts.setPostField(pid, 'votes', parseInt(results.upvotes, 10) - parseInt(results.downvotes, 10));
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Favourites.upvote = function(pid, room_id, uid, socket) {
|
||||
Favourites.unvote(pid, room_id, uid, socket, function(err) {
|
||||
vote('upvote', false, pid, room_id, uid, socket);
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.downvote = function(pid, room_id, uid, socket) {
|
||||
Favourites.unvote(pid, room_id, uid, socket, function(err) {
|
||||
vote('downvote', false, pid, room_id, uid, socket);
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.unvote = function(pid, room_id, uid, socket, callback) {
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
Favourites.hasVoted(pid, uid, function(err, voteStatus) {
|
||||
if (voteStatus.upvoted || voteStatus.downvoted) {
|
||||
socket.emit('posts.unvote', {
|
||||
pid: pid
|
||||
});
|
||||
|
||||
return vote(voteStatus.upvoted ? 'downvote' : 'upvote', true, pid, room_id, uid, socket, function() {
|
||||
if (callback) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.hasVoted = function(pid, uid, callback) {
|
||||
async.parallel({
|
||||
upvoted: function(next) {
|
||||
db.isSetMember('pid:' + pid + ':upvote', uid, next);
|
||||
},
|
||||
downvoted: function(next) {
|
||||
db.isSetMember('pid:' + pid + ':downvote', uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
callback(err, results)
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.getVoteStatusByPostIDs = function(pids, uid, callback) {
|
||||
var data = {};
|
||||
|
||||
function iterator(pid, next) {
|
||||
Favourites.hasVoted(pid, uid, function(err, voteStatus) {
|
||||
data[pid] = voteStatus;
|
||||
next()
|
||||
});
|
||||
}
|
||||
|
||||
async.each(pids, iterator, function(err) {
|
||||
callback(data);
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.favourite = function (pid, room_id, uid, socket) {
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
if (uid === 0) {
|
||||
|
||||
translator.mget(['topic:favourites.not_logged_in.message', 'topic:favourites.not_logged_in.title'], function(err, results) {
|
||||
socket.emit('event:alert', {
|
||||
alert_id: 'post_favourite',
|
||||
title: results[1],
|
||||
message: results[0],
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
return socket.emit('event:alert', {
|
||||
alert_id: 'post_favourite',
|
||||
title: '[[topic:favourites.not_logged_in.title]]',
|
||||
message: '[[topic:favourites.not_logged_in.message]]',
|
||||
type: 'danger',
|
||||
timeout: 5000
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
posts.getPostFields(pid, ['uid', 'timestamp'], function (err, postData) {
|
||||
|
||||
Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
|
||||
|
||||
if (!hasFavourited) {
|
||||
|
||||
db.sortedSetAdd('uid:' + uid + ':favourites', postData.timestamp, pid);
|
||||
db.setAdd('pid:' + pid + ':users_favourited', uid, function(err) {
|
||||
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
|
||||
@@ -38,15 +187,8 @@ var async = require('async'),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
if (uid !== postData.uid) {
|
||||
user.incrementUserFieldBy(postData.uid, 'reputation', 1, function (err, newreputation) {
|
||||
db.sortedSetAdd('users:reputation', newreputation, postData.uid);
|
||||
});
|
||||
}
|
||||
|
||||
if (room_id) {
|
||||
websockets.in(room_id).emit('event:rep_up', {
|
||||
websockets.in(room_id).emit('event:favourited', {
|
||||
uid: uid !== postData.uid ? postData.uid : 0,
|
||||
pid: pid
|
||||
});
|
||||
@@ -60,7 +202,7 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.unfavourite = function (pid, room_id, uid, socket) {
|
||||
Favourites.unfavourite = function(pid, room_id, uid, socket) {
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
if (uid === 0) {
|
||||
@@ -70,23 +212,15 @@ var async = require('async'),
|
||||
posts.getPostField(pid, 'uid', function (err, uid_of_poster) {
|
||||
Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
|
||||
if (hasFavourited) {
|
||||
|
||||
db.sortedSetRemove('uid:' + uid + ':favourites', pid);
|
||||
|
||||
db.setRemove('pid:' + pid + ':users_favourited', uid, function(err) {
|
||||
db.setCount('pid:' + pid + ':users_favourited', function(err, count) {
|
||||
posts.setPostField(pid, 'reputation', count);
|
||||
});
|
||||
});
|
||||
|
||||
if (uid !== uid_of_poster) {
|
||||
user.incrementUserFieldBy(uid_of_poster, 'reputation', -1, function (err, newreputation) {
|
||||
db.sortedSetAdd('users:reputation', newreputation, uid_of_poster);
|
||||
});
|
||||
}
|
||||
|
||||
if (room_id) {
|
||||
websockets.in(room_id).emit('event:rep_down', {
|
||||
websockets.in(room_id).emit('event:unfavourited', {
|
||||
uid: uid !== uid_of_poster ? uid_of_poster : 0,
|
||||
pid: pid
|
||||
});
|
||||
@@ -100,15 +234,15 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.hasFavourited = function (pid, uid, callback) {
|
||||
Favourites.hasFavourited = function(pid, uid, callback) {
|
||||
db.isSetMember('pid:' + pid + ':users_favourited', uid, callback);
|
||||
};
|
||||
|
||||
Favourites.getFavouritesByPostIDs = function (pids, uid, callback) {
|
||||
Favourites.getFavouritesByPostIDs = function(pids, uid, callback) {
|
||||
var data = {};
|
||||
|
||||
function iterator(pid, next) {
|
||||
Favourites.hasFavourited(pid, uid, function (err, hasFavourited) {
|
||||
Favourites.hasFavourited(pid, uid, function(err, hasFavourited) {
|
||||
data[pid] = hasFavourited;
|
||||
next()
|
||||
});
|
||||
@@ -119,7 +253,7 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Favourites.getFavouritedUidsByPids = function (pids, callback) {
|
||||
Favourites.getFavouritedUidsByPids = function(pids, callback) {
|
||||
var data = {};
|
||||
|
||||
function getUids(pid, next) {
|
||||
|
||||
@@ -479,8 +479,8 @@ var db = require('./database'),
|
||||
async.each(pids, reIndex, callback);
|
||||
}
|
||||
|
||||
// this function should really be called User.getFavouritePosts
|
||||
Posts.getFavourites = function(uid, start, end, callback) {
|
||||
|
||||
db.getSortedSetRevRange('uid:' + uid + ':favourites', start, end, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
@@ -490,18 +490,26 @@ var fs = require('fs'),
|
||||
});
|
||||
}
|
||||
|
||||
function getOnlineUsers(req, res) {
|
||||
function getOnlineUsers(req, res, next) {
|
||||
var websockets = require('../socket.io');
|
||||
|
||||
user.getUsers('users:online', 0, 49, function (err, data) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
var onlineUsers = [];
|
||||
|
||||
uid = 0;
|
||||
if (req.user) {
|
||||
uid = req.user.uid;
|
||||
}
|
||||
|
||||
user.isAdministrator(uid, function (err, isAdministrator) {
|
||||
if (true != isAdministrator) {
|
||||
if(err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
if (!isAdministrator) {
|
||||
data = data.filter(function(item) {
|
||||
return item.status !== 'offline';
|
||||
});
|
||||
|
||||
@@ -64,11 +64,12 @@ SocketAdmin.user.createUser = function(socket, user, callback) {
|
||||
SocketAdmin.user.banUser = function(socket, theirid) {
|
||||
admin.user.banUser(socket.uid, theirid, socket, function(isBanned) {
|
||||
if(isBanned) {
|
||||
if(index.userSockets[theirid]) {
|
||||
for(var i=0; i<index.userSockets[theirid].length; ++i) {
|
||||
index.userSockets[theirid][i].emit('event:banned');
|
||||
}
|
||||
var sockets = index.getUserSockets(theirid);
|
||||
|
||||
for(var i=0; i<sockets.length; ++i) {
|
||||
sockets[i].emit('event:banned');
|
||||
}
|
||||
|
||||
module.parent.exports.logoutUser(theirid);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -27,9 +27,6 @@ var SocketIO = require('socket.io'),
|
||||
var io;
|
||||
|
||||
|
||||
Sockets.userSockets = {};
|
||||
|
||||
|
||||
Sockets.init = function(server) {
|
||||
|
||||
io = socketioWildcard(SocketIO).listen(server, {
|
||||
@@ -63,16 +60,13 @@ Sockets.init = function(server) {
|
||||
sessionID = socket.handshake.signedCookies["express.sid"];
|
||||
db.sessionStore.get(sessionID, function(err, sessionData) {
|
||||
if (!err && sessionData && sessionData.passport && sessionData.passport.user) {
|
||||
uid = sessionData.passport.user;
|
||||
uid = parseInt(sessionData.passport.user, 10);
|
||||
} else {
|
||||
uid = 0;
|
||||
}
|
||||
|
||||
socket.uid = parseInt(uid, 10);
|
||||
|
||||
Sockets.userSockets[uid] = Sockets.userSockets[uid] || [];
|
||||
Sockets.userSockets[uid].push(socket);
|
||||
|
||||
/* Need to save some state for the logger & maybe some other modules later on */
|
||||
socket.state = {
|
||||
user : {
|
||||
@@ -106,45 +100,43 @@ Sockets.init = function(server) {
|
||||
isAdmin: userData.isAdmin,
|
||||
uid: uid
|
||||
});
|
||||
|
||||
socketUser.isOnline(socket, uid, function(err, data) {
|
||||
socket.broadcast.emit('user.isOnline', err, data);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
socket.broadcast.emit('user.anonConnect');
|
||||
}
|
||||
|
||||
socketUser.isOnline(socket, uid, function(err, data) {
|
||||
socket.broadcast.emit('user.isOnline', err, data);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
|
||||
var index = (Sockets.userSockets[uid] || []).indexOf(socket);
|
||||
if (index !== -1) {
|
||||
Sockets.userSockets[uid].splice(index, 1);
|
||||
}
|
||||
|
||||
if (Sockets.userSockets[uid] && Sockets.userSockets[uid].length === 0) {
|
||||
delete Sockets.userSockets[uid];
|
||||
|
||||
if (uid) {
|
||||
db.sortedSetRemove('users:online', uid, function(err, data) {
|
||||
if (uid && !Sockets.getUserSockets(uid).length <= 1) {
|
||||
db.sortedSetRemove('users:online', uid, function(err) {
|
||||
socketUser.isOnline(socket, uid, function(err, data) {
|
||||
socket.broadcast.emit('user.isOnline', err, data);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
socketUser.isOnline(socket, uid, function(err, data) {
|
||||
socket.broadcast.emit('user.isOnline', err, data);
|
||||
});
|
||||
if (!uid) {
|
||||
socket.broadcast.emit('user.anonDisconnect');
|
||||
}
|
||||
|
||||
emitOnlineUserCount();
|
||||
|
||||
for(var roomName in io.sockets.manager.roomClients[socket.id]) {
|
||||
updateRoomBrowsingText(roomName.slice(1));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
socket.on('*', function(payload, callback) {
|
||||
|
||||
function callMethod(method) {
|
||||
if(socket.uid) {
|
||||
user.setUserField(socket.uid, 'lastonline', Date.now());
|
||||
@@ -187,16 +179,10 @@ Sockets.init = function(server) {
|
||||
};
|
||||
|
||||
Sockets.logoutUser = function(uid) {
|
||||
if(Sockets.userSockets[uid] && Sockets.userSockets[uid].length) {
|
||||
for(var i=0; i< Sockets.userSockets[uid].length; ++i) {
|
||||
Sockets.userSockets[uid][i].emit('event:disconnect');
|
||||
Sockets.userSockets[uid][i].disconnect();
|
||||
|
||||
if(!Sockets.userSockets[uid]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Sockets.getUserSockets(uid).forEach(function(socket) {
|
||||
socket.emit('event:disconnect');
|
||||
socket.disconnect();
|
||||
});
|
||||
};
|
||||
|
||||
Sockets.emitUserCount = function() {
|
||||
@@ -212,18 +198,38 @@ Sockets.in = function(room) {
|
||||
};
|
||||
|
||||
Sockets.getConnectedClients = function() {
|
||||
return Sockets.userSockets;
|
||||
var clients = io.sockets.clients();
|
||||
var uids = [];
|
||||
clients.forEach(function(client) {
|
||||
if(client.uid && uids.indexOf(client.uid) === -1) {
|
||||
uids.push(client.uid);
|
||||
}
|
||||
});
|
||||
return uids;
|
||||
};
|
||||
|
||||
Sockets.getOnlineAnonCount = function () {
|
||||
return Sockets.userSockets[0] ? Sockets.userSockets[0].length : 0;
|
||||
return Sockets.getUserSockets(0).length;
|
||||
};
|
||||
|
||||
Sockets.getUserSockets = function(uid) {
|
||||
var sockets = io.sockets.clients();
|
||||
if(!sockets || !sockets.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
sockets = sockets.filter(function(s) {
|
||||
return s.uid === parseInt(uid, 10);
|
||||
});
|
||||
|
||||
return sockets;
|
||||
};
|
||||
|
||||
/* Helpers */
|
||||
|
||||
Sockets.isUserOnline = isUserOnline;
|
||||
function isUserOnline(uid) {
|
||||
return !!Sockets.userSockets[uid] && Sockets.userSockets[uid].length > 0;
|
||||
return Sockets.getUserSockets(uid).length > 0;
|
||||
}
|
||||
|
||||
Sockets.updateRoomBrowsingText = updateRoomBrowsingText;
|
||||
@@ -292,11 +298,8 @@ function emitTopicPostStats(callback) {
|
||||
|
||||
Sockets.emitOnlineUserCount = emitOnlineUserCount;
|
||||
function emitOnlineUserCount(callback) {
|
||||
var anon = Sockets.userSockets[0] ? Sockets.userSockets[0].length : 0;
|
||||
var registered = Object.keys(Sockets.userSockets).length;
|
||||
if (anon) {
|
||||
registered = registered - 1;
|
||||
}
|
||||
var anon = Sockets.getOnlineAnonCount(0);
|
||||
var registered = Sockets.getConnectedClients().length;
|
||||
|
||||
var returnObj = {
|
||||
users: registered + anon,
|
||||
|
||||
@@ -113,39 +113,29 @@ SocketModules.chats.send = function(socket, data) {
|
||||
usersData[0].uid = socket.uid;
|
||||
usersData[1].uid = touid;
|
||||
|
||||
Messaging.parse(msg, socket.uid, socket.uid, usersData[1], usersData[0], true, function(parsed) {
|
||||
Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
|
||||
var numSockets = 0,
|
||||
x;
|
||||
Messaging.parse(msg, socket.uid, socket.uid, usersData[1], usersData[0], true, function(parsed) {
|
||||
Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
|
||||
|
||||
if (server.userSockets[touid]) {
|
||||
numSockets = server.userSockets[touid].length;
|
||||
|
||||
for (x = 0; x < numSockets; ++x) {
|
||||
server.userSockets[touid][x].emit('event:chats.receive', {
|
||||
fromuid: socket.uid,
|
||||
username: username,
|
||||
message: parsed,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
server.getUserSockets(touid).forEach(function(s) {
|
||||
s.emit('event:chats.receive', {
|
||||
fromuid: socket.uid,
|
||||
username: username,
|
||||
message: parsed,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
});
|
||||
|
||||
if (server.userSockets[socket.uid]) {
|
||||
|
||||
numSockets = server.userSockets[socket.uid].length;
|
||||
|
||||
for (x = 0; x < numSockets; ++x) {
|
||||
server.userSockets[socket.uid][x].emit('event:chats.receive', {
|
||||
fromuid: touid,
|
||||
username: toUsername,
|
||||
message: parsed,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
server.getUserSockets(socket.uid).forEach(function(s) {
|
||||
s.emit('event:chats.receive', {
|
||||
fromuid: touid,
|
||||
username: toUsername,
|
||||
message: parsed,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -73,6 +73,24 @@ SocketPosts.reply = function(socket, data, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
SocketPosts.upvote = function(socket, data) {
|
||||
if(data && data.pid && data.room_id) {
|
||||
favourites.upvote(data.pid, data.room_id, socket.uid, socket);
|
||||
}
|
||||
};
|
||||
|
||||
SocketPosts.downvote = function(socket, data) {
|
||||
if(data && data.pid && data.room_id) {
|
||||
favourites.downvote(data.pid, data.room_id, socket.uid, socket);
|
||||
}
|
||||
};
|
||||
|
||||
SocketPosts.unvote = function(socket, data) {
|
||||
if(data && data.pid && data.room_id) {
|
||||
favourites.unvote(data.pid, data.room_id, socket.uid, socket);
|
||||
}
|
||||
};
|
||||
|
||||
SocketPosts.favourite = function(socket, data) {
|
||||
if(data && data.pid && data.room_id) {
|
||||
favourites.favourite(data.pid, data.room_id, socket.uid, socket);
|
||||
|
||||
@@ -341,6 +341,12 @@ var async = require('async'),
|
||||
});
|
||||
}
|
||||
|
||||
function getVoteStatusData(next) {
|
||||
favourites.getVoteStatusByPostIDs(pids, current_user, function(vote_data) {
|
||||
next(null, vote_data);
|
||||
})
|
||||
}
|
||||
|
||||
function addUserInfoToPosts(next) {
|
||||
function iterator(post, callback) {
|
||||
posts.addUserInfoToPost(post, function() {
|
||||
@@ -370,17 +376,21 @@ var async = require('async'),
|
||||
}
|
||||
}
|
||||
|
||||
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges], function(err, results) {
|
||||
async.parallel([getFavouritesData, addUserInfoToPosts, getPrivileges, getVoteStatusData], function(err, results) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var fav_data = results[0],
|
||||
privileges = results[2];
|
||||
privileges = results[2],
|
||||
voteStatus = results[3];
|
||||
|
||||
for (var i = 0; i < postData.length; ++i) {
|
||||
var pid = postData[i].pid;
|
||||
postData[i].favourited = fav_data[pid];
|
||||
postData[i].upvoted = voteStatus[pid].upvoted;
|
||||
postData[i].downvoted = voteStatus[pid].downvoted;
|
||||
postData[i].votes = postData[i].votes || 0;
|
||||
postData[i].display_moderator_tools = (current_user != 0) && privileges[pid].editable;
|
||||
postData[i].display_move_tools = privileges[pid].move;
|
||||
if(parseInt(postData[i].deleted, 10) === 1 && !privileges[pid].view_deleted) {
|
||||
@@ -647,8 +657,7 @@ var async = require('async'),
|
||||
var websockets = require('./socket.io');
|
||||
|
||||
if (!uids) {
|
||||
clients = websockets.getConnectedClients();
|
||||
uids = Object.keys(clients);
|
||||
uids = websockets.getConnectedClients();
|
||||
} else if (!Array.isArray(uids)) {
|
||||
uids = [uids];
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ var db = require('./database'),
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
var latestSchema = new Date(2014, 0, 30, 16, 0).getTime();
|
||||
var latestSchema = new Date(2014, 1, 2, 16, 0).getTime();
|
||||
|
||||
db.get('schemaDate', function(err, value) {
|
||||
if (parseInt(value, 10) >= latestSchema) {
|
||||
@@ -431,6 +431,8 @@ Upgrade.upgrade = function(callback) {
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 0, 30, 16, 0).getTime();
|
||||
|
||||
function updateTopic(tid, next) {
|
||||
Topics.getTopicFields(tid, ['postcount', 'viewcount'], function(err, topicData) {
|
||||
if(err) {
|
||||
@@ -454,7 +456,6 @@ Upgrade.upgrade = function(callback) {
|
||||
});
|
||||
}
|
||||
|
||||
thisSchemaDate = new Date(2014, 0, 30, 16, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
@@ -476,7 +477,44 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2014/1/30] Adding new topic sets -- skipped');
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = new Date(2014, 1, 2, 16, 0).getTime();
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
|
||||
winston.info('[2014/2/6] Upvoting all favourited posts for each user');
|
||||
|
||||
User.getUsers('users:joindate', 0, -1, function (err, users) {
|
||||
function getFavourites(user, next) {
|
||||
function upvote(post, next) {
|
||||
var pid = post.pid,
|
||||
uid = user.uid;
|
||||
|
||||
if (post.uid !== uid) {
|
||||
db.setAdd('pid:' + pid + ':upvote', uid);
|
||||
db.sortedSetAdd('uid:' + uid + ':upvote', post.timestamp, pid);
|
||||
db.incrObjectField('post:' + pid, 'votes');
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
Posts.getFavourites(user.uid, 0, -1, function(err, posts) {
|
||||
async.each(posts.posts, upvote, function(err) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
async.each(users, getFavourites, function(err) {
|
||||
next(err);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2014/2/6] Upvoting all favourited posts for each user -- skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!
|
||||
], function(err) {
|
||||
|
||||
Reference in New Issue
Block a user