mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
closes #1090
This commit is contained in:
@@ -12,8 +12,17 @@ define(['forum/recent'], function(recent) {
|
|||||||
recent.watchForNewPosts();
|
recent.watchForNewPosts();
|
||||||
|
|
||||||
$('#mark-allread-btn').on('click', function() {
|
$('#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);
|
var btn = $(this);
|
||||||
socket.emit('topics.markAllRead', function(err) {
|
|
||||||
|
socket.emit('topics.markAllRead', getUnreadTids(), function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return app.alertError('There was an error marking topics read!');
|
return app.alertError('There was an error marking topics read!');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<ul id="topics-container" data-nextstart="{nextStart}">
|
<ul id="topics-container" data-nextstart="{nextStart}">
|
||||||
<!-- BEGIN topics -->
|
<!-- 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">
|
<div class="col-md-12 col-xs-12 panel panel-default topic-row">
|
||||||
<a href="{relative_path}/user/{topics.userslug}" class="pull-left">
|
<a href="{relative_path}/user/{topics.userslug}" class="pull-left">
|
||||||
<img class="img-rounded user-img" src="{topics.picture}" title="{topics.username}" />
|
<img class="img-rounded user-img" src="{topics.picture}" title="{topics.username}" />
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
var topics = require('../topics'),
|
var topics = require('../topics'),
|
||||||
categories = require('../categories'),
|
categories = require('../categories'),
|
||||||
threadTools = require('../threadTools'),
|
threadTools = require('../threadTools'),
|
||||||
@@ -68,7 +71,7 @@ SocketTopics.post = function(socket, data, callback) {
|
|||||||
type: 'success',
|
type: 'success',
|
||||||
timeout: 2000
|
timeout: 2000
|
||||||
});
|
});
|
||||||
callback(null);
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -88,14 +91,19 @@ SocketTopics.markAsRead = function(socket, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.markAllRead = function(socket, data, callback) {
|
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) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
index.server.sockets.in('uid_' + socket.uid).emit('event:unread.updateCount', null, []);
|
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.getTitleByPid = function(pid, callback) {
|
||||||
Topics.getTopicFieldByPid('title', 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) {
|
Topics.markAsRead = function(tid, uid, callback) {
|
||||||
|
|
||||||
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {
|
db.setAdd('tid:' + tid + ':read_by_uid', uid, function(err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user