topics should be marked read correctly if you are already in it

v1.18.x
Baris Soner Usakli 11 years ago
parent 47c32738a6
commit 824c5072e8

@ -401,23 +401,29 @@ define(['taskbar'], function(taskbar) {
'title' : titleEl.val(), 'title' : titleEl.val(),
'content' : bodyEl.val(), 'content' : bodyEl.val(),
'category_id' : postData.cid 'category_id' : postData.cid
}, function() { }, function(err) {
composer.discard(post_uuid); if(!err) {
composer.discard(post_uuid);
}
}); });
} else if (parseInt(postData.tid, 10) > 0) { } else if (parseInt(postData.tid, 10) > 0) {
socket.emit('posts.reply', { socket.emit('posts.reply', {
'topic_id' : postData.tid, 'topic_id' : postData.tid,
'content' : bodyEl.val() 'content' : bodyEl.val()
}, function() { }, function(err) {
composer.discard(post_uuid); if(!err) {
composer.discard(post_uuid);
}
}); });
} else if (parseInt(postData.pid, 10) > 0) { } else if (parseInt(postData.pid, 10) > 0) {
socket.emit('posts.edit', { socket.emit('posts.edit', {
pid: postData.pid, pid: postData.pid,
content: bodyEl.val(), content: bodyEl.val(),
title: titleEl.val() title: titleEl.val()
}, function() { }, function(err) {
composer.discard(post_uuid); if(!err) {
composer.discard(post_uuid);
}
}); });
} }
} }

@ -189,6 +189,10 @@ var db = require('./database.js'),
db.setAdd('cid:' + cid + ':read_by_uid', uid); db.setAdd('cid:' + cid + ':read_by_uid', uid);
}; };
Categories.markAsUnreadForAll = function(cid, callback) {
db.delete('cid:' + cid + ':read_by_uid', callback);
};
Categories.hasReadCategories = function(cids, uid, callback) { Categories.hasReadCategories = function(cids, uid, callback) {
var sets = []; var sets = [];

@ -90,9 +90,7 @@ var db = require('./database'),
next(null, postData); next(null, postData);
}); });
} }
], function(err, postData) { ], callback);
callback(err, postData);
});
}; };
Posts.getPostsByTid = function(tid, start, end, callback) { Posts.getPostsByTid = function(tid, start, end, callback) {
@ -222,10 +220,10 @@ var db = require('./database'),
post.editorname = editorData.username; post.editorname = editorData.username;
post.editorslug = editorData.userslug; post.editorslug = editorData.userslug;
callback(); callback(null, post);
}); });
} else { } else {
callback(); callback(null, post);
} }
}); });
}); });

@ -104,15 +104,15 @@ SocketPosts.edit = function(socket, data, callback) {
type: 'warning', type: 'warning',
timeout: 2000 timeout: 2000
}); });
return; return callback(new Error('not-logged-in'));
} else if(!data || !data.pid || !data.title || !data.content) { } else if(!data || !data.pid || !data.title || !data.content) {
return callback(new Error('invalid data')); return callback(new Error('invalid data'));
} else if (!data.title || data.title.length < parseInt(meta.config.minimumTitleLength, 10)) { } else if (!data.title || data.title.length < parseInt(meta.config.minimumTitleLength, 10)) {
topics.emitTitleTooShortAlert(socket); topics.emitTitleTooShortAlert(socket);
return; return callback(new Error('title-too-short'));
} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) { } else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) {
module.parent.exports.emitContentTooShortAlert(socket); module.parent.exports.emitContentTooShortAlert(socket);
return; return callback(new Error('content-too-short'));
} }
postTools.edit(socket.uid, data.pid, data.title, data.content); postTools.edit(socket.uid, data.pid, data.title, data.content);

@ -16,7 +16,7 @@ SocketTopics.post = function(socket, data, callback) {
type: 'danger', type: 'danger',
timeout: 2000 timeout: 2000
}); });
return; return callback(new Error('not-logged-in'));
} }
topics.post(socket.uid, data.title, data.content, data.category_id, function(err, result) { topics.post(socket.uid, data.title, data.content, data.category_id, function(err, result) {
@ -44,7 +44,7 @@ SocketTopics.post = function(socket, data, callback) {
timeout: 7500 timeout: 7500
}); });
} }
return; return callback(err);
} }
if (result) { if (result) {

@ -138,88 +138,85 @@ var async = require('async'),
}; };
Topics.reply = function(tid, uid, content, callback) { Topics.reply = function(tid, uid, content, callback) {
threadTools.privileges(tid, uid, function(err, privileges) { var privileges;
if(err) {
return callback(err);
}
if (content) { async.waterfall([
content = content.trim(); function(next) {
} threadTools.privileges(tid, uid, next);
},
if (!content || content.length < meta.config.minimumPostLength) { function(privilegesData, next) {
return callback(new Error('content-too-short')); privileges = privilegesData;
} else if (!privileges.write) { if (!privileges.write) {
return callback(new Error('no-privileges')); return next(new Error('no-privileges'));
}
user.getUserField(uid, 'lastposttime', function(err, lastposttime) {
if(err) {
return callback(err);
} }
next();
},
function(next) {
user.getUserField(uid, 'lastposttime', next);
},
function(lastposttime, next) {
if(!lastposttime) { if(!lastposttime) {
lastposttime = 0; lastposttime = 0;
} }
if (Date.now() - lastposttime < meta.config.postDelay * 1000) { if (Date.now() - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
return callback(new Error('too-many-posts'), null); return next(new Error('too-many-posts'), null);
} }
posts.create(uid, tid, content, function(err, postData) { next();
if(err) { },
return callback(err); function(next) {
} else if(!postData) { if (content) {
callback(new Error('reply-error'), null); content = content.trim();
} }
posts.getCidByPid(postData.pid, function(err, cid) {
if(err) {
return callback(err, null);
}
db.delete('cid:' + cid + ':read_by_uid', function(err) {
Topics.markAsUnreadForAll(tid, function(err) {
if(err) {
return callback(err, null);
}
Topics.markAsRead(tid, uid, function(err) {
Topics.pushUnreadCount(null);
});
});
});
});
db.getObjectField('tid:lastFeedUpdate', tid, function(err, lastFeedUpdate) {
var now = Date.now();
if(!lastFeedUpdate || parseInt(lastFeedUpdate, 10) < now - 3600000) {
feed.updateTopic(tid);
db.setObjectField('tid:lastFeedUpdate', tid, now);
}
});
feed.updateRecent();
threadTools.notifyFollowers(tid, uid); if (!content || content.length < meta.config.minimumPostLength) {
return next(new Error('content-too-short'));
}
user.sendPostNotificationToFollowers(uid, tid, postData.pid); posts.create(uid, tid, content, next);
},
function(postData, next) {
db.getObjectField('tid:lastFeedUpdate', tid, function(err, lastFeedUpdate) {
var now = Date.now();
if(!lastFeedUpdate || parseInt(lastFeedUpdate, 10) < now - 3600000) {
feed.updateTopic(tid);
db.setObjectField('tid:lastFeedUpdate', tid, now);
}
});
posts.addUserInfoToPost(postData, function(err) { feed.updateRecent();
if(err) { threadTools.notifyFollowers(tid, uid);
return callback(err, null); user.sendPostNotificationToFollowers(uid, tid, postData.pid);
}
postData.favourited = false; Topics.markCategoryUnreadForAll(tid, function(err) {
postData.display_moderator_tools = true; next(err, postData);
postData.display_move_tools = privileges.admin || privileges.moderator; });
postData.relativeTime = utils.toISOString(postData.timestamp); },
function(postData, next) {
Topics.markAsUnreadForAll(tid, function(err) {
if(err) {
return next(err);
}
callback(null, postData); Topics.markAsRead(tid, uid, function(err) {
Topics.pushUnreadCount(null);
next(err, postData);
}); });
}); });
}); },
}); function(postData, next) {
posts.addUserInfoToPost(postData, next);
},
function(postData, next) {
postData.favourited = false;
postData.display_moderator_tools = true;
postData.display_move_tools = privileges.admin || privileges.moderator;
postData.relativeTime = utils.toISOString(postData.timestamp);
next(null, postData);
}
], callback);
} }
Topics.createTopicFromPosts = function(uid, title, pids, callback) { Topics.createTopicFromPosts = function(uid, title, pids, callback) {
@ -970,6 +967,16 @@ var async = require('async'),
}); });
} }
Topics.markCategoryUnreadForAll = function(tid, callback) {
Topics.getTopicField(tid, 'cid', function(err, cid) {
if(err) {
return callback(err);
}
categories.markAsUnreadForAll(cid, callback);
});
}
Topics.hasReadTopics = function(tids, uid, callback) { Topics.hasReadTopics = function(tids, uid, callback) {
var sets = []; var sets = [];

Loading…
Cancel
Save