mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
Merge branch 'master' into bootstrap3
This commit is contained in:
17
app.js
17
app.js
@@ -16,18 +16,20 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Configuration setup
|
||||
nconf = require('nconf');
|
||||
nconf.argv().file({ file: __dirname + '/config.json'});
|
||||
|
||||
var fs = require('fs'),
|
||||
winston = require('winston'),
|
||||
pkg = require('./package.json'),
|
||||
url = require('url'),
|
||||
meta = require('./src/meta.js');
|
||||
|
||||
nconf = require('nconf');
|
||||
// Runtime environment
|
||||
global.env = process.env.NODE_ENV || 'production',
|
||||
|
||||
// Configuration setup
|
||||
nconf.argv().file({ file: __dirname + '/config.json'});
|
||||
|
||||
|
||||
winston.remove(winston.transports.Console);
|
||||
winston.add(winston.transports.Console, {
|
||||
@@ -64,6 +66,12 @@ if(nconf.get('upgrade')) {
|
||||
winston.info('Base Configuration OK.');
|
||||
|
||||
meta.configs.init(function() {
|
||||
// Initial setup for Redis & Reds
|
||||
var reds = require('reds');
|
||||
RDB = require('./src/redis.js');
|
||||
reds.createClient = function() {
|
||||
return reds.client || (reds.client = RDB);
|
||||
}
|
||||
|
||||
var categories = require('./src/categories.js'),
|
||||
templates = require('./public/src/templates.js'),
|
||||
@@ -75,7 +83,6 @@ if(nconf.get('upgrade')) {
|
||||
};
|
||||
|
||||
DEVELOPMENT = true;
|
||||
RDB = require('./src/redis.js');
|
||||
|
||||
global.configuration = {};
|
||||
global.templates = {};
|
||||
@@ -86,7 +93,7 @@ if(nconf.get('upgrade')) {
|
||||
templates.init([
|
||||
'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index',
|
||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
||||
'emails/header', 'emails/footer', 'install/header', 'install/footer', 'install/redis',
|
||||
'emails/header', 'emails/footer',
|
||||
|
||||
'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic'
|
||||
]);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "nodebb",
|
||||
"license": "GPLv3 or later",
|
||||
"description": "NodeBB Forum",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.6",
|
||||
"homepage": "http://www.nodebb.org",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -202,6 +202,10 @@ footer.footer {
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.account-block {
|
||||
div {
|
||||
padding-bottom:10px;
|
||||
@@ -850,4 +854,4 @@ a:hover, .btn-link:hover, .btn-link:active, .btn-link:focus {
|
||||
margin-right: -11px;
|
||||
}
|
||||
|
||||
//END: FIXES FOR BS3, may need to remove these when we get out of the RC releases
|
||||
//END: FIXES FOR BS3, may need to remove these when we get out of the RC releases
|
||||
|
||||
@@ -14,23 +14,29 @@
|
||||
</div>');
|
||||
|
||||
$('.account-username-box').append(links);
|
||||
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
|
||||
createMenu();
|
||||
|
||||
var editLink = $('#editLink');
|
||||
var settingsLink = $('#settingsLink');
|
||||
var favouritesLink = $('#favouritesLink');
|
||||
|
||||
|
||||
if(yourid === "0" || yourid !== theirid) {
|
||||
editLink.hide();
|
||||
settingsLink.hide();
|
||||
favouritesLink.hide();
|
||||
}
|
||||
|
||||
|
||||
jQuery('.account-sub-links span a').removeClass('bold').each(function() {
|
||||
var href = this.getAttribute('href');
|
||||
if (window.location.href.indexOf(href) !== -1) {
|
||||
jQuery(this).addClass('bold');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}());
|
||||
@@ -96,10 +96,39 @@
|
||||
notifTrigger.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
if (notifContainer.className.indexOf('open') === -1) {
|
||||
socket.emit('api:notifications.get');
|
||||
socket.emit('api:notifications.mark_all_read', null, function() {
|
||||
notifIcon.className = 'icon-circle-blank';
|
||||
utils.refreshTitle();
|
||||
socket.emit('api:notifications.get', null, function(data) {
|
||||
var notifFrag = document.createDocumentFragment(),
|
||||
notifEl = document.createElement('li'),
|
||||
numRead = data.read.length,
|
||||
numUnread = data.unread.length,
|
||||
x;
|
||||
notifList.innerHTML = '';
|
||||
if ((data.read.length + data.unread.length) > 0) {
|
||||
for(x=0;x<numUnread;x++) {
|
||||
notifEl.setAttribute('data-nid', data.unread[x].nid);
|
||||
notifEl.className = 'unread';
|
||||
notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>';
|
||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
||||
}
|
||||
for(x=0;x<numRead;x++) {
|
||||
notifEl.setAttribute('data-nid', data.read[x].nid);
|
||||
notifEl.className = '';
|
||||
notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>';
|
||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
||||
}
|
||||
} else {
|
||||
notifEl.innerHTML = '<a>You have no notifications</a>';
|
||||
notifFrag.appendChild(notifEl);
|
||||
}
|
||||
notifList.appendChild(notifFrag);
|
||||
|
||||
if (data.unread.length > 0) notifIcon.className = 'icon-circle active';
|
||||
else notifIcon.className = 'icon-circle-blank';
|
||||
|
||||
socket.emit('api:notifications.mark_all_read', null, function() {
|
||||
notifIcon.className = 'icon-circle-blank';
|
||||
utils.refreshTitle();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -115,38 +144,10 @@
|
||||
if (nid > 0) socket.emit('api:notifications.mark_read', nid);
|
||||
}
|
||||
});
|
||||
socket.on('api:notifications.get', function(data) {
|
||||
var notifFrag = document.createDocumentFragment(),
|
||||
notifEl = document.createElement('li'),
|
||||
numRead = data.read.length,
|
||||
numUnread = data.unread.length,
|
||||
x;
|
||||
notifList.innerHTML = '';
|
||||
if ((data.read.length + data.unread.length) > 0) {
|
||||
for(x=0;x<numUnread;x++) {
|
||||
notifEl.setAttribute('data-nid', data.unread[x].nid);
|
||||
notifEl.className = 'unread';
|
||||
notifEl.innerHTML = '<a href="' + data.unread[x].path + '"><span class="pull-right">' + utils.relativeTime(data.unread[x].datetime, true) + '</span>' + data.unread[x].text + '</a>';
|
||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
||||
}
|
||||
for(x=0;x<numRead;x++) {
|
||||
notifEl.setAttribute('data-nid', data.read[x].nid);
|
||||
notifEl.className = '';
|
||||
notifEl.innerHTML = '<a href="' + data.read[x].path + '"><span class="pull-right">' + utils.relativeTime(data.read[x].datetime, true) + '</span>' + data.read[x].text + '</a>';
|
||||
notifFrag.appendChild(notifEl.cloneNode(true));
|
||||
}
|
||||
} else {
|
||||
notifEl.innerHTML = '<a>You have no notifications</a>';
|
||||
notifFrag.appendChild(notifEl);
|
||||
}
|
||||
notifList.appendChild(notifFrag);
|
||||
|
||||
if (data.unread.length > 0) notifIcon.className = 'icon-circle active';
|
||||
else notifIcon.className = 'icon-circle-blank';
|
||||
});
|
||||
socket.on('event:new_notification', function() {
|
||||
document.querySelector('.notifications a i').className = 'icon-circle active';
|
||||
app.alert({
|
||||
alert_id: 'new_notif',
|
||||
title: 'New notification',
|
||||
message: 'You have unread notifications.',
|
||||
type: 'warning',
|
||||
|
||||
@@ -12,16 +12,15 @@
|
||||
if (target) {
|
||||
document.location.href = target.getAttribute('data-url');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('#login').on('click', function() {
|
||||
|
||||
var loginData = {
|
||||
'username': $('#username').val(),
|
||||
'password': $('#password').val(),
|
||||
'_csrf': $('#csrf-token').val()
|
||||
};
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: RELATIVE_PATH + '/login',
|
||||
@@ -44,5 +43,6 @@
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
document.querySelector('#content input').focus();
|
||||
}());
|
||||
|
||||
@@ -287,12 +287,14 @@
|
||||
var username = $(this).parents('li').attr('data-username');
|
||||
var touid = $(this).parents('li').attr('data-uid');
|
||||
|
||||
require(['chat'], function(chat){
|
||||
if(username === app.username || !app.username)
|
||||
return;
|
||||
|
||||
require(['chat'], function(chat) {
|
||||
var chatModal = chat.createModalIfDoesntExist(username, touid);
|
||||
chatModal.show();
|
||||
chat.bringModalToTop(chatModal);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
ajaxify.register_events([
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
define(['taskbar'], function(taskbar) {
|
||||
|
||||
|
||||
var module = {};
|
||||
|
||||
|
||||
module.bringModalToTop = function(chatModal) {
|
||||
var topZ = 0;
|
||||
$('.modal').each(function() {
|
||||
@@ -11,7 +10,7 @@ define(['taskbar'], function(taskbar) {
|
||||
topZ = thisZ;
|
||||
}
|
||||
});
|
||||
chatModal.css('zIndex', topZ+1);
|
||||
chatModal.css('zIndex', topZ + 1);
|
||||
}
|
||||
|
||||
module.createModalIfDoesntExist = function(username, touid) {
|
||||
@@ -39,7 +38,9 @@ define(['taskbar'], function(taskbar) {
|
||||
module.bringModalToTop(chatModal);
|
||||
});
|
||||
|
||||
addSendHandler(chatModal, touid);
|
||||
addSendHandler(chatModal, touid);
|
||||
|
||||
getChatMessages(chatModal, touid);
|
||||
}
|
||||
|
||||
taskbar.push('chat', chatModal.attr('UUID'), {title:'chat with '+username});
|
||||
@@ -58,6 +59,14 @@ define(['taskbar'], function(taskbar) {
|
||||
taskbar.minimize('chat', uuid);
|
||||
}
|
||||
|
||||
function getChatMessages(chatModal, touid) {
|
||||
socket.emit('getChatMessages', {touid:touid}, function(messages) {
|
||||
for(var i = 0; i<messages.length; ++i) {
|
||||
module.appendChatMessage(chatModal, messages[i].content);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addSendHandler(chatModal, touid) {
|
||||
chatModal.find('#chat-message-input').off('keypress');
|
||||
chatModal.find('#chat-message-input').on('keypress', function(e) {
|
||||
|
||||
76
src/messaging.js
Normal file
76
src/messaging.js
Normal file
@@ -0,0 +1,76 @@
|
||||
|
||||
var RDB = require('./redis'),
|
||||
async = require('async');
|
||||
|
||||
|
||||
(function(Messaging) {
|
||||
|
||||
function sortUids(fromuid, touid) {
|
||||
var uids = [fromuid, touid];
|
||||
uids.sort();
|
||||
return uids;
|
||||
}
|
||||
|
||||
Messaging.addMessage = function(fromuid, touid, content, callback) {
|
||||
var uids = sortUids(fromuid, touid);
|
||||
|
||||
RDB.incr('global:next_message_id', function(err, mid) {
|
||||
if(err)
|
||||
return callback(err, null);
|
||||
|
||||
var message = {
|
||||
content: content,
|
||||
timestamp: Date.now(),
|
||||
fromuid: fromuid,
|
||||
touid: touid
|
||||
};
|
||||
|
||||
RDB.hmset('message:' + mid, message);
|
||||
RDB.rpush('messages:' + uids[0] + ':' + uids[1], mid);
|
||||
|
||||
callback(null, message);
|
||||
});
|
||||
}
|
||||
|
||||
Messaging.getMessages = function(fromuid, touid, callback) {
|
||||
var uids = sortUids(fromuid, touid);
|
||||
|
||||
RDB.lrange('messages:' + uids[0] + ':' + uids[1], 0, -1, function(err, mids) {
|
||||
if(err)
|
||||
return callback(err, null);
|
||||
|
||||
if(!mids || !mids.length) {
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
|
||||
user.getUserField(touid, 'username', function(err, tousername) {
|
||||
|
||||
var messages = [];
|
||||
|
||||
function getMessage(mid, next) {
|
||||
RDB.hgetall('message:' + mid, function(err, message) {
|
||||
if(err)
|
||||
return next(err);
|
||||
|
||||
if(message.fromuid === fromuid)
|
||||
message.content = 'You : ' + message.content;
|
||||
else
|
||||
message.content = tousername + ' : ' + message.content;
|
||||
|
||||
messages.push(message);
|
||||
next(null);
|
||||
});
|
||||
}
|
||||
|
||||
async.eachSeries(mids, getMessage, function(err) {
|
||||
if(err)
|
||||
return callback(err, null);
|
||||
|
||||
callback(null, messages);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}(exports));
|
||||
@@ -118,5 +118,6 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
function hasEnoughRep(next) {
|
||||
user.getUserField(uid, 'reputation', function(reputation) {
|
||||
user.getUserField(uid, 'reputation', function(err, reputation) {
|
||||
if (err) return next(null, false);
|
||||
next(null, reputation >= meta.config['privileges:manage_content']);
|
||||
});
|
||||
}
|
||||
|
||||
21
src/posts.js
21
src/posts.js
@@ -10,9 +10,9 @@ var RDB = require('./redis.js'),
|
||||
async = require('async'),
|
||||
plugins = require('./plugins'),
|
||||
reds = require('reds'),
|
||||
postSearch = reds.createSearch('nodebbpostsearch'),
|
||||
nconf = require('nconf'),
|
||||
meta = require('./meta.js'),
|
||||
postSearch = reds.createSearch('nodebbpostsearch'),
|
||||
winston = require('winston');
|
||||
|
||||
(function(Posts) {
|
||||
@@ -70,13 +70,18 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
Posts.addUserInfoToPost(postData, function() {
|
||||
topics.getTopicField(postData.tid, 'slug', function(err, topicSlug) {
|
||||
topics.getTopicFields(postData.tid, ['slug', 'deleted'], function(err, topicData) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
if(topicData.deleted === '1')
|
||||
return callback(null);
|
||||
|
||||
if(postData.content)
|
||||
postData.content = utils.strip_tags(postTools.markdownToHTML(postData.content));
|
||||
|
||||
postData.relativeTime = utils.relativeTime(postData.timestamp);
|
||||
postData.topicSlug = topicSlug;
|
||||
postData.topicSlug = topicData.slug;
|
||||
posts.push(postData);
|
||||
callback(null);
|
||||
});
|
||||
@@ -102,8 +107,7 @@ var RDB = require('./redis.js'),
|
||||
Posts.getPostData = function(pid, callback) {
|
||||
RDB.hgetall('post:' + pid, function(err, data) {
|
||||
if(err === null) {
|
||||
plugins.fireHook('filter:post.get', data.content, function(content) {
|
||||
data.content = content;
|
||||
plugins.fireHook('filter:post.get', data, function(data) {
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
@@ -324,8 +328,9 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
},
|
||||
content: function(next) {
|
||||
plugins.fireHook('filter:post.get', content, function(content) {
|
||||
next(null, content);
|
||||
plugins.fireHook('filter:post.get', postData, function(postData) {
|
||||
postData.content = postTools.markdownToHTML(postData.content, false);
|
||||
next(null, postData.content);
|
||||
});
|
||||
}
|
||||
}, function(err, results) {
|
||||
@@ -335,7 +340,7 @@ var RDB = require('./redis.js'),
|
||||
callback(postData);
|
||||
});
|
||||
|
||||
plugins.fireHook('action:post.save', [pid, content]);
|
||||
plugins.fireHook('action:post.save', [postData]);
|
||||
|
||||
postSearch.index(content, pid);
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
nconf = require('nconf'),
|
||||
utils = require('./../public/src/utils.js'),
|
||||
winston = require('winston');
|
||||
|
||||
|
||||
RedisDB.exports = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
|
||||
|
||||
if(nconf.get('redis:password')) {
|
||||
@@ -40,7 +40,7 @@
|
||||
RedisDB.exports.hmget(key, fields, function(err, data) {
|
||||
if(err === null) {
|
||||
var returnData = {};
|
||||
|
||||
|
||||
for(var i=0, ii=fields.length; i<ii; ++i) {
|
||||
returnData[fields[i]] = data[i];
|
||||
}
|
||||
@@ -51,8 +51,8 @@
|
||||
console.log(err);
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -102,9 +102,12 @@ var user = require('./../user.js'),
|
||||
res.json(data);
|
||||
});
|
||||
|
||||
app.get('/api/topic/:id/:slug?', function(req, res) {
|
||||
app.get('/api/topic/:id/:slug?', function(req, res, next) {
|
||||
var uid = (req.user) ? req.user.uid : 0;
|
||||
topics.getTopicWithPosts(req.params.id, uid, function(err, data) {
|
||||
if(data.deleted === '1' && data.expose_tools === 0) {
|
||||
return res.json(404, {});
|
||||
}
|
||||
res.json(data);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -79,8 +79,7 @@ var user = require('./../user.js'),
|
||||
if(!req.user)
|
||||
return res.redirect('/403');
|
||||
|
||||
user.getUserField(req.user.uid, 'userslug', function(userslug) {
|
||||
|
||||
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
|
||||
if(req.params.userslug && userslug === req.params.userslug) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
res.send(header + app.create_route('users/'+req.params.userslug+'/edit','accountedit') + templates['footer']);
|
||||
@@ -96,7 +95,7 @@ var user = require('./../user.js'),
|
||||
if(!req.user)
|
||||
return res.redirect('/403');
|
||||
|
||||
user.getUserField(req.user.uid, 'userslug', function(userslug) {
|
||||
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
|
||||
if(req.params.userslug && userslug === req.params.userslug) {
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
res.send(header + app.create_route('users/'+req.params.userslug+'/settings','accountsettings') + templates['footer']);
|
||||
@@ -127,7 +126,7 @@ var user = require('./../user.js'),
|
||||
return;
|
||||
}
|
||||
|
||||
user.getUserField(req.user.uid, 'uploadedpicture', function(oldpicture) {
|
||||
user.getUserField(req.user.uid, 'uploadedpicture', function(err, oldpicture) {
|
||||
if(!oldpicture) {
|
||||
uploadUserPicture(req.user.uid, path.extname(req.files.userPhoto.name), req.files.userPhoto.path, res);
|
||||
return;
|
||||
|
||||
@@ -31,7 +31,8 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
function hasEnoughRep(next) {
|
||||
user.getUserField(uid, 'reputation', function(reputation) {
|
||||
user.getUserField(uid, 'reputation', function(err, reputation) {
|
||||
if (err) return next(null, false);
|
||||
next(null, reputation >= meta.config['privileges:manage_topic']);
|
||||
});
|
||||
}
|
||||
@@ -89,7 +90,7 @@ var RDB = require('./redis.js'),
|
||||
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||
if (privileges.editable || uid === -1) {
|
||||
|
||||
topics.setTopicField(tid, 'deleted', 1);
|
||||
topics.delete(tid);
|
||||
ThreadTools.lock(tid, uid);
|
||||
|
||||
topicSearch.remove(tid);
|
||||
@@ -108,7 +109,7 @@ var RDB = require('./redis.js'),
|
||||
ThreadTools.privileges(tid, uid, function(privileges) {
|
||||
if (privileges.editable) {
|
||||
|
||||
topics.setTopicField(tid, 'deleted', 0);
|
||||
topics.restore(tid);
|
||||
ThreadTools.unlock(tid, uid);
|
||||
|
||||
io.sockets.in('topic_' + tid).emit('event:topic_restored', {
|
||||
@@ -159,7 +160,7 @@ var RDB = require('./redis.js'),
|
||||
if (privileges.editable) {
|
||||
|
||||
topics.setTopicField(tid, 'pinned', 0);
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(topicData) {
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
||||
RDB.zadd('categories:' + topicData.cid + ':tid', topicData.lastposttime, tid);
|
||||
});
|
||||
if (socket) {
|
||||
@@ -179,7 +180,7 @@ var RDB = require('./redis.js'),
|
||||
|
||||
ThreadTools.move = function(tid, cid, socket) {
|
||||
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(topicData) {
|
||||
topics.getTopicFields(tid, ['cid', 'lastposttime'], function(err, topicData) {
|
||||
var oldCid = topicData.cid;
|
||||
var multi = RDB.multi();
|
||||
|
||||
|
||||
161
src/topics.js
161
src/topics.js
@@ -20,8 +20,6 @@ marked.setOptions({
|
||||
|
||||
(function(Topics) {
|
||||
|
||||
|
||||
|
||||
Topics.getTopicData = function(tid, callback) {
|
||||
RDB.hgetall('topic:' + tid, function(err, data) {
|
||||
if(err === null)
|
||||
@@ -33,8 +31,7 @@ marked.setOptions({
|
||||
|
||||
Topics.getTopicDataWithUsername = function(tid, callback) {
|
||||
Topics.getTopicData(tid, function(topic) {
|
||||
user.getUserField(topic.uid, 'username', function(username) {
|
||||
|
||||
user.getUserField(topic.uid, 'username', function(err, username) {
|
||||
topic.username = username;
|
||||
callback(topic);
|
||||
});
|
||||
@@ -128,17 +125,45 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Topics.getTotalUnread = function(uid, callback) {
|
||||
RDB.zrevrange('topics:recent', 0, 21, function (err, tids) {
|
||||
Topics.hasReadTopics(tids, uid, function(read) {
|
||||
var unreadTids = tids.filter(function(tid, index, self) {
|
||||
return read[index] === 0;
|
||||
});
|
||||
|
||||
var unreadTids = [],
|
||||
start = 0,
|
||||
stop = 21,
|
||||
done = false;
|
||||
|
||||
async.whilst(
|
||||
function () { return unreadTids.length < 21 && !done; },
|
||||
function (callback) {
|
||||
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
|
||||
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
if(tids && !tids.length) {
|
||||
done = true;
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
Topics.hasReadTopics(tids, uid, function(read) {
|
||||
|
||||
var newtids = tids.filter(function(tid, index, self) {
|
||||
return read[index] === 0;
|
||||
});
|
||||
|
||||
unreadTids.push.apply(unreadTids, newtids);
|
||||
|
||||
start = stop + 1;
|
||||
stop = start + 21;
|
||||
callback(null);
|
||||
});
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
callback({
|
||||
count: unreadTids.length
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Topics.getUnreadTopics = function(uid, start, stop, callback) {
|
||||
@@ -153,50 +178,67 @@ marked.setOptions({
|
||||
'topics' : []
|
||||
};
|
||||
|
||||
RDB.zrevrange('topics:recent', start, stop, function (err, tids) {
|
||||
function noUnreadTopics() {
|
||||
unreadTopics.no_topics_message = 'show';
|
||||
unreadTopics.show_markallread_button = 'hidden';
|
||||
callback(unreadTopics);
|
||||
}
|
||||
|
||||
function noUnreadTopics() {
|
||||
unreadTopics.no_topics_message = 'show';
|
||||
unreadTopics.show_markallread_button = 'hidden';
|
||||
function sendUnreadTopics(topicIds) {
|
||||
Topics.getTopicsByTids(topicIds, uid, function(topicData) {
|
||||
unreadTopics.topics = topicData;
|
||||
unreadTopics.nextStart = start + topicIds.length;
|
||||
if(!topicData || topicData.length === 0)
|
||||
unreadTopics.no_topics_message = 'show';
|
||||
if(uid === 0 || topicData.length === 0)
|
||||
unreadTopics.show_markallread_button = 'hidden';
|
||||
callback(unreadTopics);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function sendUnreadTopics(topicIds) {
|
||||
Topics.getTopicsByTids(topicIds, uid, function(topicData) {
|
||||
unreadTopics.topics = topicData;
|
||||
unreadTopics.nextStart = start + tids.length;
|
||||
if(!topicData || topicData.length === 0)
|
||||
unreadTopics.no_topics_message = 'show';
|
||||
if(uid === 0 || topicData.length === 0)
|
||||
unreadTopics.show_markallread_button = 'hidden';
|
||||
callback(unreadTopics);
|
||||
});
|
||||
}
|
||||
var unreadTids = [],
|
||||
done = false;
|
||||
|
||||
if (!tids || !tids.length) {
|
||||
noUnreadTopics();
|
||||
return;
|
||||
}
|
||||
async.whilst(
|
||||
function () { return unreadTids.length < 20 && !done; },
|
||||
function (callback) {
|
||||
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
|
||||
if(err)
|
||||
return callback(err);
|
||||
|
||||
if(uid === 0) {
|
||||
sendUnreadTopics(tids);
|
||||
} else {
|
||||
|
||||
Topics.hasReadTopics(tids, uid, function(read) {
|
||||
|
||||
var unreadTids = tids.filter(function(tid, index, self) {
|
||||
return read[index] === 0;
|
||||
});
|
||||
|
||||
if (!unreadTids || !unreadTids.length) {
|
||||
noUnreadTopics();
|
||||
return;
|
||||
if(tids && !tids.length) {
|
||||
done = true;
|
||||
return callback(null);
|
||||
}
|
||||
|
||||
sendUnreadTopics(unreadTids);
|
||||
if(uid === 0) {
|
||||
unreadTids.push.apply(unreadTids, tids);
|
||||
callback(null);
|
||||
} else {
|
||||
Topics.hasReadTopics(tids, uid, function(read) {
|
||||
|
||||
var newtids = tids.filter(function(tid, index, self) {
|
||||
return read[index] === 0;
|
||||
});
|
||||
|
||||
unreadTids.push.apply(unreadTids, newtids);
|
||||
start = stop + 1;
|
||||
stop = start + 19;
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
function (err) {
|
||||
if(err)
|
||||
return callback([]);
|
||||
if(unreadTids.length)
|
||||
sendUnreadTopics(unreadTids);
|
||||
else
|
||||
noUnreadTopics();
|
||||
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
Topics.getTopicsByTids = function(tids, current_user, callback, category_id) {
|
||||
@@ -572,8 +614,8 @@ marked.setOptions({
|
||||
return;
|
||||
}
|
||||
|
||||
user.getUserField(uid, 'lastposttime', function(lastposttime) {
|
||||
|
||||
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
|
||||
if (err) lastposttime = 0;
|
||||
if(Date.now() - lastposttime < meta.config.postDelay) {
|
||||
callback(new Error('too-many-posts'), null);
|
||||
return;
|
||||
@@ -650,14 +692,7 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Topics.getTopicFields = function(tid, fields, callback) {
|
||||
RDB.hmgetObject('topic:' + tid, fields, function(err, data) {
|
||||
if(err === null) {
|
||||
callback(data);
|
||||
}
|
||||
else {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
RDB.hmgetObject('topic:' + tid, fields, callback);
|
||||
}
|
||||
|
||||
Topics.setTopicField = function(tid, field, value) {
|
||||
@@ -675,7 +710,7 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Topics.updateTimestamp = function(tid, timestamp) {
|
||||
RDB.zadd(schema.topics().recent, timestamp, tid);
|
||||
RDB.zadd('topics:recent', timestamp, tid);
|
||||
Topics.setTopicField(tid, 'lastposttime', timestamp);
|
||||
}
|
||||
|
||||
@@ -687,6 +722,18 @@ marked.setOptions({
|
||||
RDB.lrange('tid:' + tid + ':posts', 0, -1, callback);
|
||||
}
|
||||
|
||||
Topics.delete = function(tid) {
|
||||
Topics.setTopicField(tid, 'deleted', 1);
|
||||
RDB.zrem('topics:recent', tid);
|
||||
}
|
||||
|
||||
Topics.restore = function(tid) {
|
||||
Topics.setTopicField(tid, 'deleted', 0);
|
||||
Topics.getTopicField(tid, 'lastposttime', function(err, lastposttime) {
|
||||
RDB.zadd('topics:recent', lastposttime, tid);
|
||||
});
|
||||
}
|
||||
|
||||
Topics.reIndexTopic = function(tid, callback) {
|
||||
Topics.getPids(tid, function(err, pids) {
|
||||
if(err) {
|
||||
|
||||
18
src/user.js
18
src/user.js
@@ -139,13 +139,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
|
||||
User.getUserField = function(uid, field, callback) {
|
||||
RDB.hget('user:' + uid, field, function(err, data) {
|
||||
if(err === null) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
RDB.hget('user:' + uid, field, callback);
|
||||
}
|
||||
|
||||
User.getUserFields = function(uid, fields, callback) {
|
||||
@@ -221,7 +215,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
return next(null, true);
|
||||
}
|
||||
|
||||
User.getUserField(uid, 'email', function(email) {
|
||||
User.getUserField(uid, 'email', function(err, email) {
|
||||
if(email !== data['email']) {
|
||||
User.isEmailAvailable(data['email'], function(available) {
|
||||
if(!available) {
|
||||
@@ -304,7 +298,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
return;
|
||||
}
|
||||
|
||||
User.getUserField(uid, 'password', function(user_password) {
|
||||
User.getUserField(uid, 'password', function(err, user_password) {
|
||||
bcrypt.compare(data.currentPassword, user_password, function(err, res) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
@@ -584,7 +578,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
|
||||
User.sendPostNotificationToFollowers = function(uid, tid, pid) {
|
||||
User.getUserField(uid, 'username', function(username) {
|
||||
User.getUserField(uid, 'username', function(err, username) {
|
||||
RDB.smembers('followers:' + uid, function(err, followers) {
|
||||
topics.getTopicField(tid, 'slug', function(err, slug) {
|
||||
var message = username + ' made a new post';
|
||||
@@ -658,7 +652,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
|
||||
function iterator(uid, callback) {
|
||||
User.getUserField(uid, 'username', function(username) {
|
||||
User.getUserField(uid, 'username', function(err, username) {
|
||||
usernames.push(username);
|
||||
callback(null);
|
||||
});
|
||||
@@ -677,7 +671,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
|
||||
function iterator(uid, callback) {
|
||||
User.getUserField(uid, 'userslug', function(userslug) {
|
||||
User.getUserField(uid, 'userslug', function(err, userslug) {
|
||||
userslugs.push(userslug);
|
||||
callback(null);
|
||||
});
|
||||
|
||||
@@ -70,7 +70,10 @@ var express = require('express'),
|
||||
ttl: 60*60*24*14
|
||||
}),
|
||||
secret: nconf.get('secret'),
|
||||
key: 'express.sid'
|
||||
key: 'express.sid',
|
||||
cookie: {
|
||||
maxAge: 60*60*24*30 // 30 days
|
||||
}
|
||||
}));
|
||||
app.use(express.csrf());
|
||||
app.use(function(req, res, next) {
|
||||
@@ -161,7 +164,7 @@ var express = require('express'),
|
||||
app.get('/' + route, function(req, res) {
|
||||
if ((route === 'login' || route ==='register') && (req.user && req.user.uid > 0)) {
|
||||
|
||||
user.getUserField(req.user.uid, 'userslug', function(userslug) {
|
||||
user.getUserField(req.user.uid, 'userslug', function(err, userslug) {
|
||||
res.redirect('/users/'+userslug);
|
||||
});
|
||||
return;
|
||||
@@ -207,6 +210,7 @@ var express = require('express'),
|
||||
|
||||
|
||||
app.get('/topic/:topic_id/:slug?', function(req, res) {
|
||||
|
||||
var tid = req.params.topic_id;
|
||||
if (tid.match(/^\d+\.rss$/)) {
|
||||
fs.readFile('feeds/topics/' + tid, function (err, data) {
|
||||
@@ -223,11 +227,16 @@ var express = require('express'),
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
topics.getTopicWithPosts(tid, ((req.user) ? req.user.uid : 0), function(err, topicData) {
|
||||
if(topicData) {
|
||||
if(topicData.deleted === '1' && topicData.expose_tools === 0)
|
||||
return next(new Error('Topic deleted'), null);
|
||||
}
|
||||
|
||||
next(err, topicData);
|
||||
});
|
||||
},
|
||||
function(topicData, next) {
|
||||
var posts = topicData.posts.push(topicData.main_posts[0]),
|
||||
var posts = topicData.posts.push(topicData.main_posts[0]),
|
||||
lastMod = 0,
|
||||
timestamp;
|
||||
|
||||
@@ -374,7 +383,7 @@ var express = require('express'),
|
||||
app.build_header({ req: req, res: res }, function(err, header) {
|
||||
res.send(
|
||||
header +
|
||||
'\n\t<script>templates.ready(function(){ajaxify.go("outgoing?url=' + req.query.url + '");});</script>' +
|
||||
'\n\t<script>templates.ready(function(){ajaxify.go("outgoing?url=' + encodeURIComponent(req.query.url) + '", null, null, true);});</script>' +
|
||||
templates['footer']
|
||||
);
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.join('uid_' + uid);
|
||||
io.sockets.in('global').emit('api:user.isOnline', isUserOnline(uid));
|
||||
|
||||
user.getUserField(uid, 'username', function(username) {
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
socket.emit('event:connect', {status: 1, username:username});
|
||||
});
|
||||
}
|
||||
@@ -275,12 +275,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
}
|
||||
|
||||
if(type === 'gravatar') {
|
||||
user.getUserField(uid, 'gravatarpicture', function(gravatar) {
|
||||
user.getUserField(uid, 'gravatarpicture', function(err, gravatar) {
|
||||
user.setUserField(uid, 'picture', gravatar);
|
||||
updateHeader();
|
||||
});
|
||||
} else if(type === 'uploaded') {
|
||||
user.getUserField(uid, 'uploadedpicture', function(uploadedpicture) {
|
||||
user.getUserField(uid, 'uploadedpicture', function(err, uploadedpicture) {
|
||||
user.setUserField(uid, 'picture', uploadedpicture);
|
||||
updateHeader();
|
||||
});
|
||||
@@ -484,9 +484,9 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
postTools.restore(uid, data.pid);
|
||||
});
|
||||
|
||||
socket.on('api:notifications.get', function(data) {
|
||||
socket.on('api:notifications.get', function(data, callback) {
|
||||
user.notifications.get(uid, function(notifs) {
|
||||
socket.emit('api:notifications.get', notifs);
|
||||
callback(notifs);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -506,26 +506,43 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('getChatMessages', function(data, callback) {
|
||||
var touid = data.touid;
|
||||
require('./messaging').getMessages(uid, touid, function(err, messages) {
|
||||
if(err)
|
||||
return callback(null);
|
||||
|
||||
callback(messages);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('sendChatMessage', function(data) {
|
||||
|
||||
var touid = data.touid;
|
||||
if(touid === uid || uid === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(userSockets[touid]) {
|
||||
var msg = utils.strip_tags(data.message),
|
||||
numSockets = userSockets[touid].length;
|
||||
|
||||
user.getUserField(uid, 'username', function(username) {
|
||||
user.getUserField(uid, 'username', function(err, username) {
|
||||
var finalMessage = username + ' says : ' + msg;
|
||||
|
||||
for(var x=0;x<numSockets;x++) {
|
||||
userSockets[touid][x].emit('chatMessage', {fromuid:uid, username:username, message:finalMessage});
|
||||
}
|
||||
|
||||
notifications.create(finalMessage, 5, '#', 'notification_'+uid+'_'+touid, function(nid) {
|
||||
notifications.create(finalMessage, 5, '#', 'notification_' + uid + '_' + touid, function(nid) {
|
||||
notifications.push(nid, [touid], function(success) {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
require('./messaging').addMessage(uid, touid, msg, function(err, message) {
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user