From cbb630fd6b9e36755b9f904165eb2ef56fc04494 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 16 Jan 2014 19:57:28 -0500 Subject: [PATCH] fixed categories.js socket callbacks --- public/src/forum/category.js | 8 ++++---- public/src/forum/topic.js | 2 +- src/socket.io/categories.js | 12 +++--------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index baee8ade4f..e4d36d78f4 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -132,16 +132,16 @@ define(['composer'], function(composer) { socket.emit('categories.loadMore', { cid: cid, after: $('#topics-container').children('.category-item').length - }, function (data) { - if (data.topics.length) { + }, function (err, data) { + if (!err && data.topics.length) { Category.onTopicsLoaded(data.topics); } loadingMoreTopics = false; }); } - function renderRecentReplies(posts) { - if (!posts || posts.length === 0) { + function renderRecentReplies(err, posts) { + if (err || !posts || posts.length === 0) { return; } diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 379eb38b96..a198127c3b 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -102,7 +102,7 @@ define(['composer'], function(composer) { var loadingEl = document.getElementById('categories-loading'); if (loadingEl) { - socket.emit('categories.get', function(data) { + socket.emit('categories.get', function(err, data) { // Render categories var categoriesFrag = document.createDocumentFragment(), categoryEl = document.createElement('li'), diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index b670f1ff8d..43c5a002b8 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -3,17 +3,11 @@ var categories = require('../categories'), SocketCategories = {}; SocketCategories.getRecentReplies = function(socket, tid, callback) { - categories.getRecentReplies(tid, socket.uid, 4, function(err, replies) { - callback(replies); - }); + categories.getRecentReplies(tid, socket.uid, 4, callback); }; SocketCategories.get = function(socket, data, callback) { - categories.getAllCategories(0, function(err, categories) { - if(callback) { - callback(categories); - } - }); + categories.getAllCategories(0, callback); }; SocketCategories.loadMore = function(socket, data, callback) { @@ -21,7 +15,7 @@ SocketCategories.loadMore = function(socket, data, callback) { end = start + 9; categories.getCategoryTopics(data.cid, start, end, socket.uid, function(topics) { - callback({ + callback(null, { topics: topics }); });