mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
closed #160
new build_title function to be called via socket also added categories.getCategoryField and refactored all calls to getTopicField to be error-first
This commit is contained in:
@@ -78,6 +78,10 @@ var ajaxify = {};
|
||||
|
||||
}, url, template);
|
||||
|
||||
socket.emit('api:meta.buildTitle', url, function(title) {
|
||||
document.title = title;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -240,6 +240,10 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
Categories.getCategoryField = function(cid, field, callback) {
|
||||
RDB.hget('category:' + cid, field, callback);
|
||||
}
|
||||
|
||||
Categories.getCategoryFields = function(cid, fields, callback) {
|
||||
RDB.hmgetObject('category:' + cid, fields, function(err, data) {
|
||||
if(err === null)
|
||||
|
||||
48
src/meta.js
48
src/meta.js
@@ -60,17 +60,49 @@ var utils = require('./../public/src/utils.js'),
|
||||
}
|
||||
}
|
||||
|
||||
Meta.build_title = function(title, current_user, callback) {
|
||||
var user = require('./user');
|
||||
Meta.title = {
|
||||
build: function(urlFragment, current_user, callback) {
|
||||
var self = this,
|
||||
user = require('./user');
|
||||
|
||||
if (!title) title = global.config.title || 'NodeBB';
|
||||
else title += ' | ' + global.config.title || 'NodeBB';
|
||||
async.parallel({
|
||||
title: function(next) {
|
||||
self.parseFragment(urlFragment, next);
|
||||
},
|
||||
notifCount: function(next) {
|
||||
user.notifications.getUnreadCount(current_user, next);
|
||||
}
|
||||
}, function(err, values) {
|
||||
var title;
|
||||
|
||||
// Grab the number of unread notifications
|
||||
user.notifications.getUnreadCount(current_user, function(err, count) {
|
||||
if (!err && count > 0) title = '(' + count + ') ' + title;
|
||||
if (err) title = global.config.title || 'NodeBB';
|
||||
else title = (values.notifCount > 0 ? '(' + values.notifCount + ') ' : '') + (values.title ? values.title + ' | ' : '') + global.config.title || 'NodeBB';
|
||||
|
||||
callback(err, title);
|
||||
callback(null, title);
|
||||
});
|
||||
},
|
||||
parseFragment: function(urlFragment, callback) {
|
||||
if (urlFragment === '') {
|
||||
callback(null, 'Index');
|
||||
} else if (urlFragment === 'recent') {
|
||||
callback(null, 'Recent Topics');
|
||||
} else if (urlFragment === 'unread') {
|
||||
callback(null, 'Unread Topics');
|
||||
} else if (urlFragment === 'users') {
|
||||
callback(null, 'Registered Users');
|
||||
} else if (/^category\/\d+\/?/.test(urlFragment)) {
|
||||
var cid = urlFragment.match(/category\/(\d+)/)[1];
|
||||
|
||||
require('./categories').getCategoryField(cid, 'name', function(err, name) {
|
||||
callback(null, name);
|
||||
});
|
||||
} else if (/^topic\/\d+\/?/.test(urlFragment)) {
|
||||
var tid = urlFragment.match(/topic\/(\d+)/)[1];
|
||||
|
||||
require('./topics').getTopicField(tid, 'title', function(err, title) {
|
||||
callback(null, title);
|
||||
});
|
||||
} else callback(null);
|
||||
}
|
||||
}
|
||||
}(exports));
|
||||
@@ -64,7 +64,7 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
Posts.addUserInfoToPost(postData, function() {
|
||||
topics.getTopicField(postData.tid, 'slug', function(topicSlug) {
|
||||
topics.getTopicField(postData.tid, 'slug', function(err, topicSlug) {
|
||||
|
||||
if(postData.content)
|
||||
postData.content = utils.strip_tags(postTools.markdownToHTML(postData.content));
|
||||
@@ -158,7 +158,7 @@ var RDB = require('./redis.js'),
|
||||
Posts.get_cid_by_pid = function(pid, callback) {
|
||||
Posts.getPostField(pid, 'tid', function(tid) {
|
||||
if (tid) {
|
||||
topics.getTopicField(tid, 'cid', function(cid) {
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
if (cid) {
|
||||
callback(cid);
|
||||
} else {
|
||||
@@ -278,7 +278,7 @@ var RDB = require('./redis.js'),
|
||||
|
||||
RDB.incr('totalpostcount');
|
||||
|
||||
topics.getTopicField(tid, 'cid', function(cid) {
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
RDB.handle(err);
|
||||
|
||||
feed.updateTopic(tid, cid);
|
||||
|
||||
@@ -21,7 +21,7 @@ var RDB = require('./redis.js'),
|
||||
//todo: break early if one condition is true
|
||||
|
||||
function getCategoryPrivileges(next) {
|
||||
topics.getTopicField(tid, 'cid', function(cid) {
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
categories.privileges(cid, uid, function(privileges) {
|
||||
next(null, privileges);
|
||||
});
|
||||
@@ -121,7 +121,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
topics.getTopicField(tid, 'title', function(title) {
|
||||
topics.getTopicField(tid, 'title', function(err, title) {
|
||||
topicSearch.index(title, tid);
|
||||
});
|
||||
}
|
||||
@@ -133,7 +133,7 @@ var RDB = require('./redis.js'),
|
||||
if (privileges.editable) {
|
||||
|
||||
topics.setTopicField(tid, 'pinned', 1);
|
||||
topics.getTopicField(tid, 'cid', function(cid) {
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
RDB.zadd('categories:' + cid + ':tid', Math.pow(2,53), tid);
|
||||
});
|
||||
|
||||
@@ -258,7 +258,7 @@ var RDB = require('./redis.js'),
|
||||
async.parallel([
|
||||
function(next) {
|
||||
|
||||
topics.getTopicField(tid, 'title', function(title) {
|
||||
topics.getTopicField(tid, 'title', function(err, title) {
|
||||
topics.getTeaser(tid, function(err, teaser) {
|
||||
if (!err) {
|
||||
notifications.create(teaser.username + ' has posted a reply to: "' + title + '"', null, '/topic/' + tid, 'topic:' + tid, function(nid) {
|
||||
|
||||
@@ -89,7 +89,7 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Topics.getCategoryData = function(tid, callback) {
|
||||
Topics.getTopicField(tid, 'cid', function(cid) {
|
||||
Topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
categories.getCategoryData(cid, callback);
|
||||
});
|
||||
}
|
||||
@@ -436,7 +436,7 @@ marked.setOptions({
|
||||
|
||||
Topics.getTitleByPid = function(pid, callback) {
|
||||
posts.getPostField(pid, 'tid', function(tid) {
|
||||
Topics.getTopicField(tid, 'title', function(title) {
|
||||
Topics.getTopicField(tid, 'title', function(err, title) {
|
||||
callback(title);
|
||||
});
|
||||
});
|
||||
@@ -450,7 +450,7 @@ marked.setOptions({
|
||||
|
||||
RDB.sadd(schema.topics(tid).read_by_uid, uid);
|
||||
|
||||
Topics.getTopicField(tid, 'cid', function(cid) {
|
||||
Topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
|
||||
categories.isTopicsRead(cid, uid, function(read) {
|
||||
if(read) {
|
||||
@@ -628,12 +628,7 @@ marked.setOptions({
|
||||
};
|
||||
|
||||
Topics.getTopicField = function(tid, field, callback) {
|
||||
RDB.hget('topic:' + tid, field, function(err, data) {
|
||||
if(err === null)
|
||||
callback(data);
|
||||
else
|
||||
console.log(err);
|
||||
});
|
||||
RDB.hget('topic:' + tid, field, callback);
|
||||
}
|
||||
|
||||
Topics.getTopicFields = function(tid, fields, callback) {
|
||||
@@ -656,7 +651,7 @@ marked.setOptions({
|
||||
}
|
||||
|
||||
Topics.isLocked = function(tid, callback) {
|
||||
Topics.getTopicField(tid, 'locked', function(locked) {
|
||||
Topics.getTopicField(tid, 'locked', function(err, locked) {
|
||||
callback(locked);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ var utils = require('./../public/src/utils.js'),
|
||||
User.sendPostNotificationToFollowers = function(uid, tid, pid) {
|
||||
User.getUserField(uid, 'username', function(username) {
|
||||
RDB.smembers('followers:' + uid, function(err, followers) {
|
||||
topics.getTopicField(tid, 'slug', function(slug) {
|
||||
topics.getTopicField(tid, 'slug', function(err, slug) {
|
||||
var message = username + ' made a new post';
|
||||
|
||||
notifications.create(message, 5, global.nconf.get('url') + 'topic/' + slug + '#' + pid, 'notification_'+ Date.now(), function(nid) {
|
||||
|
||||
@@ -42,16 +42,19 @@ var express = require('express'),
|
||||
templateValues = {
|
||||
cssSrc: global.config['theme:src'] || global.nconf.get('relative_path') + '/vendor/bootstrap/css/bootstrap.min.css',
|
||||
title: global.config['title'] || 'NodeBB',
|
||||
browserTitle: global.config['title'] || 'NodeBB',
|
||||
csrf: options.res.locals.csrf_token,
|
||||
relative_path: global.nconf.get('relative_path'),
|
||||
meta_tags: metaString
|
||||
};
|
||||
|
||||
meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) {
|
||||
if (!err) templateValues.browserTitle = title;
|
||||
// meta.build_title(options.title, (options.req.user ? options.req.user.uid : 0), function(err, title) {
|
||||
// if (!err) templateValues.browserTitle = title;
|
||||
|
||||
// callback(null, templates['header'].parse(templateValues));
|
||||
// });
|
||||
|
||||
callback(null, templates['header'].parse(templateValues));
|
||||
});
|
||||
};
|
||||
|
||||
// Middlewares
|
||||
@@ -236,7 +239,6 @@ var express = require('express'),
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res,
|
||||
title: topicData.topic_name,
|
||||
metaTags: [
|
||||
{ name: "title", content: topicData.topic_name },
|
||||
{ property: 'og:title', content: topicData.topic_name + ' | ' + (global.config.title || 'NodeBB') },
|
||||
@@ -292,7 +294,6 @@ var express = require('express'),
|
||||
app.build_header({
|
||||
req: req,
|
||||
res: res,
|
||||
title: categoryData.category_name,
|
||||
metaTags: [
|
||||
{ name: 'title', content: categoryData.category_name },
|
||||
{ name: 'description', content: categoryData.category_description },
|
||||
@@ -400,7 +401,6 @@ var express = require('express'),
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}(WebServer));
|
||||
|
||||
@@ -712,6 +712,12 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
socket.emit('api:admin.plugins.toggle', status);
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:meta.buildTitle', function(text, callback) {
|
||||
meta.title.build(text, uid, function(err, title) {
|
||||
callback(title);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}(SocketIO));
|
||||
|
||||
Reference in New Issue
Block a user