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