lots of err first fixeS

v1.18.x
Baris Soner Usakli 11 years ago
parent ced37044ca
commit ae76bb3928

@ -102,7 +102,10 @@ define(function() {
socket.emit('topics.loadMoreRecentTopics', {
after: $('#topics-container').children('li').length,
term: active
}, function(data) {
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
if (data.topics && data.topics.length) {
Recent.onTopicsLoaded(data.topics);
}

@ -138,18 +138,10 @@ define(['composer'], function(composer) {
socket.emit('topics.move', {
tid: tid,
cid: targetCid
}, function(data) {
}, function(err) {
moveThreadModal.modal('hide');
if (data.status === 'ok') {
app.alert({
'alert_id': 'thread_move',
type: 'success',
title: 'Topic Successfully Moved',
message: 'This topic has been successfully moved to ' + targetCatLabel,
timeout: 5000
});
} else {
app.alert({
if(err) {
return app.alert({
'alert_id': 'thread_move',
type: 'danger',
title: 'Unable to Move Topic',
@ -157,6 +149,14 @@ define(['composer'], function(composer) {
timeout: 5000
});
}
app.alert({
'alert_id': 'thread_move',
type: 'success',
title: 'Topic Successfully Moved',
message: 'This topic has been successfully moved to ' + targetCatLabel,
timeout: 5000
});
});
}
});
@ -288,15 +288,15 @@ define(['composer'], function(composer) {
}
};
socket.emit('topics.followCheck', tid, function(state) {
socket.emit('topics.followCheck', tid, function(err, state) {
set_follow_state(state, true);
});
if (followEl[0]) {
followEl[0].addEventListener('click', function() {
socket.emit('topics.follow', tid, function(data) {
if (data.status && data.status === 'ok') set_follow_state(data.follow);
else {
app.alert({
socket.emit('topics.follow', tid, function(err, state) {
if(err) {
return app.alert({
type: 'danger',
alert_id: 'topic_follow',
title: 'Please Log In',
@ -304,6 +304,8 @@ define(['composer'], function(composer) {
timeout: 5000
});
}
set_follow_state(state);
});
}, false);
}
@ -1104,9 +1106,13 @@ define(['composer'], function(composer) {
socket.emit('topics.loadMore', {
tid: tid,
after: parseInt($('#post-container .post-row.infiniteloaded').last().attr('data-index'), 10) + 1
}, function (data) {
}, function (err, data) {
if(err) {
return app.alertError(err.message);
}
infiniteLoaderActive = false;
if (data.posts.length) {
if (data && data.posts && data.posts.length) {
indicatorEl.attr('done', '0');
createNewPosts(data, true);
} else {

@ -93,7 +93,11 @@ define(function() {
loadingMoreTopics = true;
socket.emit('topics.loadMoreUnreadTopics', {
after: parseInt($('#topics-container').attr('data-next-start'), 10)
}, function(data) {
}, function(err, data) {
if(err) {
return app.alertError(err.message);
}
if (data.topics && data.topics.length) {
onTopicsLoaded(data.topics);
$('#topics-container').attr('data-next-start', data.nextStart);

@ -15,7 +15,7 @@
</a>
<div class="category row">
<div class="{topic_row_size}">
<div class="col-md-12">
<ul id="topics-container" data-next-start="{nextStart}">
<!-- BEGIN topics -->
<li class="category-item {topics.deleted-class}">

@ -86,9 +86,7 @@ var db = require('./database.js'),
};
function getTopics(next) {
topics.getTopicsByTids(tids, current_user, function(topicsData) {
next(null, topicsData);
}, category_id);
topics.getTopicsByTids(tids, category_id, current_user, next);
}
function getModerators(next) {
@ -126,9 +124,9 @@ var db = require('./database.js'),
Categories.getCategoryTopics = function(cid, start, stop, uid, callback) {
Categories.getTopicIds(cid, start, stop, function(err, tids) {
topics.getTopicsByTids(tids, uid, function(topicsData) {
callback(topicsData);
}, cid);
topics.getTopicsByTids(tids, cid, uid, function(err, topicsData) {
callback(err, topicsData);
});
});
};
@ -137,7 +135,6 @@ var db = require('./database.js'),
};
Categories.getAllCategories = function(current_user, callback) {
db.getListRange('categories:cid', 0, -1, function(err, cids) {
if(err) {

@ -176,16 +176,24 @@ var path = require('path'),
});
});
app.get('/unread', function (req, res) {
app.get('/unread', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0;
topics.getUnreadTopics(uid, 0, 19, function (data) {
topics.getUnreadTopics(uid, 0, 19, function (err, data) {
if(err) {
return next(err);
}
res.json(data);
});
});
app.get('/unread/total', function (req, res) {
app.get('/unread/total', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0;
topics.getTotalUnread(uid, function (data) {
topics.getTotalUnread(uid, function (err, data) {
if(err) {
return next(err);
}
res.json(data);
});
});
@ -273,9 +281,9 @@ var path = require('path'),
return callback(err, null);
}
topics.getTopicsByTids(tids, 0, function (topics) {
topics.getTopicsByTids(tids, 0, 0, function (topics) {
callback(null, topics);
}, 0);
});
});
}

@ -138,9 +138,11 @@ SocketTopics.createTopicFromPosts = function(socket, data, callback) {
return;
}
topics.createTopicFromPosts(socket.uid, data.title, data.pids, function(err, data) {
callback(err, data);
});
if(!data || !data.title || !data.pids || !Array.isArray(data.pids)) {
return callback(new Error('invalid data'));
}
topics.createTopicFromPosts(socket.uid, data.title, data.pids, callback);
};
SocketTopics.movePost = function(socket, data, callback) {
@ -154,79 +156,74 @@ SocketTopics.movePost = function(socket, data, callback) {
return;
}
topics.movePostToTopic(data.pid, data.tid, function(err, data) {
callback(err, data);
});
if(!data || !data.pid || !data.tid) {
return callback(new Error('invalid data'));
}
topics.movePostToTopic(data.pid, data.tid, callback);
};
SocketTopics.move = function(socket, data, callback) {
if(!data || !data.tid || !data.cid) {
return callback(new Error('invalid data'));
}
threadTools.move(data.tid, data.cid, function(err) {
if(err) {
return callback(err);
}
index.server.sockets.in('topic_' + data.tid).emit('event:topic_moved', {
tid: tid
tid: data.tid
});
callback(null);
});
};
SocketTopics.followCheck = function(socket, tid, callback) {
threadTools.isFollowing(tid, socket.uid, function(following) {
callback(following);
});
threadTools.isFollowing(tid, socket.uid, callback);
};
SocketTopics.follow = function(socket, tid, callback) {
if (socket.uid) {
threadTools.toggleFollow(tid, socket.uid, function(follow) {
if (follow.status === 'ok') {
callback(follow);
}
});
} else {
callback({
status: 'error',
error: 'not-logged-in'
});
if(!socket.uid) {
return callback(new Error('not-logged-in'));
}
threadTools.toggleFollow(tid, socket.uid, callback);
};
SocketTopics.loadMore = function(socket, data, callback) {
if(!data || !data.tid) {
return callback(new Error('invalid data'));
}
var start = data.after,
end = start + 9;
topics.getTopicPosts(data.tid, start, end, socket.uid, function(err, posts) {
if(err) {
return callback(err);
}
callback(null, {
posts: posts
});
callback(err, {posts: posts});
});
};
SocketTopics.loadMoreRecentTopics = function(socket, data, callback) {
if(!data || !data.term) {
return callback(new Error('invalid data'));
}
var start = data.after,
end = start + 9;
topics.getLatestTopics(socket.uid, start, end, data.term, function(err, latestTopics) {
if(err) {
return callback(err);
}
callback(null, latestTopics);
});
topics.getLatestTopics(socket.uid, start, end, data.term, callback);
};
SocketTopics.loadMoreUnreadTopics = function(socket, data, callback) {
var start = data.after,
end = start + 9;
topics.getUnreadTopics(socket.uid, start, end, function(unreadTopics) {
callback(null, unreadTopics);
});
topics.getUnreadTopics(socket.uid, start, end, callback);
};
module.exports = SocketTopics;

@ -195,49 +195,40 @@ var winston = require('winston'),
});
}
ThreadTools.isFollowing = function(tid, current_user, callback) {
db.isSetMember('tid:' + tid + ':followers', current_user, function(err, following) {
callback(following);
});
ThreadTools.isFollowing = function(tid, uid, callback) {
db.isSetMember('tid:' + tid + ':followers', uid, callback);
}
ThreadTools.toggleFollow = function(tid, current_user, callback) {
ThreadTools.isFollowing(tid, current_user, function(following) {
if (!following) {
db.setAdd('tid:' + tid + ':followers', current_user, function(err, success) {
if (callback) {
if (!err) {
callback({
status: 'ok',
follow: true
});
} else callback({
status: 'error'
});
}
});
} else {
db.setRemove('tid:' + tid + ':followers', current_user, function(err, success) {
if (callback) {
if (!err) {
callback({
status: 'ok',
follow: false
});
} else callback({
status: 'error'
});
}
});
ThreadTools.toggleFollow = function(tid, uid, callback) {
ThreadTools.isFollowing(tid, uid, function(err, following) {
if(err) {
return callback(err);
}
db[following?'setRemove':'setAdd']('tid:' + tid + ':followers', uid, function(err, success) {
if (callback) {
if(err) {
return callback(err);
}
callback(null, !following);
}
});
});
}
ThreadTools.getFollowers = function(tid, callback) {
db.getSetMembers('tid:' + tid + ':followers', function(err, followers) {
callback(err, followers.map(function(follower) {
return parseInt(follower, 10);
}));
if(err) {
return callback(err);
}
if(followers) {
followers = followers.map(function(follower) {
return parseInt(follower, 10);
});
}
callback(null, followers);
});
}

@ -454,7 +454,7 @@ var async = require('async'),
}
});
}, function(tids) {
Topics.getTopicsByTids(tids, current_user, function(topicData) {
Topics.getTopicsByTids(tids, 0, current_user, function(err, topicData) {
latestTopics.topics = topicData;
callback(err, latestTopics);
});
@ -476,8 +476,9 @@ var async = require('async'),
function(callback) {
db.getSortedSetRevRange('topics:recent', start, stop, function(err, tids) {
if (err)
if (err) {
return callback(err);
}
if (tids && !tids.length) {
done = true;
@ -499,7 +500,7 @@ var async = require('async'),
});
},
function(err) {
callback({
callback(null, {
count: unreadTids.length
});
}
@ -569,19 +570,22 @@ var async = require('async'),
'show_topic_button': 'hidden',
'show_markallread_button': 'show',
'no_topics_message': 'hidden',
'topic_row_size': 'col-md-12',
'topics': []
};
function noUnreadTopics() {
unreadTopics.no_topics_message = 'show';
unreadTopics.show_markallread_button = 'hidden';
callback(unreadTopics);
callback(null, unreadTopics);
}
function sendUnreadTopics(topicIds) {
Topics.getTopicsByTids(topicIds, uid, function(topicData) {
Topics.getTopicsByTids(topicIds, 0, uid, function(err, topicData) {
if(err) {
return callback(err);
}
unreadTopics.topics = topicData;
unreadTopics.nextStart = stop + 1;
if (!topicData || topicData.length === 0) {
@ -591,13 +595,13 @@ var async = require('async'),
unreadTopics.show_markallread_button = 'hidden';
}
callback(unreadTopics);
callback(null, unreadTopics);
});
}
Topics.getUnreadTids(uid, start, stop, function(err, unreadTids) {
if (err) {
return callback([]);
return callback(err);
}
if (unreadTids.length) {
@ -634,13 +638,12 @@ var async = require('async'),
});
};
Topics.getTopicsByTids = function(tids, current_user, callback, category_id) {
Topics.getTopicsByTids = function(tids, cid, current_user, callback) {
var retrieved_topics = [];
if (!Array.isArray(tids) || tids.length === 0) {
callback(retrieved_topics);
return;
return callback(null, retrieved_topics);
}
function getTopicInfo(topicData, callback) {
@ -664,19 +667,19 @@ var async = require('async'),
// temporary. I don't think this call should belong here
function getPrivileges(next) {
categoryTools.privileges(category_id, current_user, function(err, user_privs) {
next(err, user_privs);
});
categoryTools.privileges(cid, current_user, next);
}
function getCategoryInfo(next) {
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon'], function(err, categoryData) {
next(err, categoryData);
});
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon'], next);
}
async.parallel([getUserInfo, hasReadTopic, getTeaserInfo, getPrivileges, getCategoryInfo], function(err, results) {
callback({
if(err) {
return callback(err);
}
callback(null, {
username: results[0].username,
userslug: results[0].userslug,
picture: results[0].picture,
@ -694,13 +697,20 @@ var async = require('async'),
return !deleted || (deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user;
}
function loadTopic(tid, callback) {
function loadTopic(tid, next) {
Topics.getTopicData(tid, function(err, topicData) {
if(err) {
return next(err);
}
if (!topicData) {
return callback(null);
return next();
}
getTopicInfo(topicData, function(topicInfo) {
getTopicInfo(topicData, function(err, topicInfo) {
if(err) {
return next(err);
}
topicData['pin-icon'] = parseInt(topicData.pinned, 10) === 1 ? 'fa-thumb-tack' : 'none';
topicData['lock-icon'] = parseInt(topicData.locked, 10) === 1 ? 'fa-lock' : 'none';
@ -720,18 +730,17 @@ var async = require('async'),
topicData.teaser_pid = topicInfo.teaserInfo.pid;
topicData.teaser_timestamp = topicInfo.teaserInfo.timestamp ? (new Date(parseInt(topicInfo.teaserInfo.timestamp, 10)).toISOString()) : '';
if (isTopicVisible(topicData, topicInfo))
if (isTopicVisible(topicData, topicInfo)) {
retrieved_topics.push(topicData);
}
callback(null);
next(null);
});
});
}
async.eachSeries(tids, loadTopic, function(err) {
if (!err) {
callback(retrieved_topics);
}
callback(err, retrieved_topics);
});
}

Loading…
Cancel
Save