Node.js based forum software built for the modern web
closed #160
Julian Lame8f1d645fec6
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.jsindex 4fc0d84915..d038fcf037 100644--- a/public/src/ajaxify.js+++ b/public/src/ajaxify.js@@ -49,7 +49,7 @@ var ajaxify = {};} else if (templates[url]) {tpl_url = url;}-+if (templates.is_available(tpl_url) && !templates.force_refresh(tpl_url)) {if (quiet !== true) {window.history.pushState({@@ -78,6 +78,10 @@ var ajaxify = {};}, url, template);+ socket.emit('api:meta.buildTitle', url, function(title) {+ document.title = title;+ });+return true;}diff --git a/src/categories.js b/src/categories.jsindex 96e3552eea..1ce0b886d3 100644--- a/src/categories.js+++ b/src/categories.js@@ -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)diff --git a/src/meta.js b/src/meta.jsindex 3ea054e314..87c11fe3f0 100644--- a/src/meta.js+++ b/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;++ if (err) title = global.config.title || 'NodeBB';+ else title = (values.notifCount > 0 ? '(' + values.notifCount + ') ' : '') + (values.title ? values.title + ' | ' : '') + global.config.title || 'NodeBB';++ 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];- // Grab the number of unread notifications- user.notifications.getUnreadCount(current_user, function(err, count) {- if (!err && count > 0) title = '(' + count + ') ' + title;+ require('./categories').getCategoryField(cid, 'name', function(err, name) {+ callback(null, name);+ });+ } else if (/^topic\/\d+\/?/.test(urlFragment)) {+ var tid = urlFragment.match(/topic\/(\d+)/)[1];- callback(err, title);- });+ require('./topics').getTopicField(tid, 'title', function(err, title) {+ callback(null, title);+ });+ } else callback(null);+ }}}(exports));\ No newline at end of filediff --git a/src/posts.js b/src/posts.jsindex 9a0dda28e4..932c9e7835 100644--- a/src/posts.js+++ b/src/posts.js@@ -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);diff --git a/src/threadTools.js b/src/threadTools.jsindex d88aa1f7be..5cc4979104 100644--- a/src/threadTools.js+++ b/src/threadTools.js@@ -21,7 +21,7 @@ var RDB = require('./redis.js'),//todo: break early if one condition is truefunction 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) {diff --git a/src/topics.js b/src/topics.jsindex 6730ee00ac..c5301bc653 100644--- a/src/topics.js+++ b/src/topics.js@@ -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);});}diff --git a/src/user.js b/src/user.jsindex 78b01f5f9c..608115595c 100644--- a/src/user.js+++ b/src/user.js@@ -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) {diff --git a/src/webserver.js b/src/webserver.jsindex 379bec362f..243b7885e0 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -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));+ // });++ 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));diff --git a/src/websockets.js b/src/websockets.jsindex 096d483176..6fa6c2568f 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -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));