v1.18.x
Baris Soner Usakli 11 years ago
parent 529cd60dd2
commit be70b3de57

@ -12,8 +12,17 @@ define(['forum/recent'], function(recent) {
recent.watchForNewPosts();
$('#mark-allread-btn').on('click', function() {
function getUnreadTids() {
var tids = [];
$('#topics-container .category-item[data-tid]').each(function() {
tids.push($(this).attr('data-tid'));
});
return tids;
}
var btn = $(this);
socket.emit('topics.markAllRead', function(err) {
socket.emit('topics.markAllRead', getUnreadTids(), function(err) {
if(err) {
return app.alertError('There was an error marking topics read!');
}

@ -19,7 +19,7 @@
<div class="col-md-12">
<ul id="topics-container" data-nextstart="{nextStart}">
<!-- BEGIN topics -->
<li class="category-item <!-- IF topics.deleted --> deleted<!-- ENDIF topics.deleted -->">
<li class="category-item<!-- IF topics.deleted --> deleted<!-- ENDIF topics.deleted -->" data-tid="{topics.tid}">
<div class="col-md-12 col-xs-12 panel panel-default topic-row">
<a href="{relative_path}/user/{topics.userslug}" class="pull-left">
<img class="img-rounded user-img" src="{topics.picture}" title="{topics.username}" />

@ -1,3 +1,6 @@
'use strict';
var topics = require('../topics'),
categories = require('../categories'),
threadTools = require('../threadTools'),
@ -68,7 +71,7 @@ SocketTopics.post = function(socket, data, callback) {
type: 'success',
timeout: 2000
});
callback(null);
callback();
}
});
};
@ -88,14 +91,19 @@ SocketTopics.markAsRead = function(socket, data) {
};
SocketTopics.markAllRead = function(socket, data, callback) {
topics.markAllRead(socket.uid, function(err) {
if (!Array.isArray(data)) {
return callback(new Error('invalid-data'));
}
topics.markAllRead(socket.uid, data, function(err) {
if(err) {
return callback(err);
}
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, []);
callback(null);
callback();
});
};

@ -797,24 +797,6 @@ var async = require('async'),
});
};
Topics.markAllRead = function(uid, callback) {
Topics.getLatestTids(0, -1, 'month', function(err, tids) {
if (err) {
return callback(err);
}
if(!tids || !tids.length) {
return callback();
}
function markRead(tid, next) {
Topics.markAsRead(tid, uid, next);
}
async.each(tids, markRead, callback);
});
};
Topics.getTitleByPid = function(pid, callback) {
Topics.getTopicFieldByPid('title', pid, callback);
};
@ -862,6 +844,16 @@ var async = require('async'),
});
};
Topics.markAllRead = function(uid, tids, callback) {
if(!tids || !tids.length) {
return callback();
}
async.each(tids, function (tid, next) {
Topics.markAsRead(tid, uid, next);
}, callback);
};
Topics.markAsRead = function(tid, uid, callback) {
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {

Loading…
Cancel
Save