Skip to content

Node.js based forum software built for the modern web

closes #4335

barisusakli05cc3fe4ef12
diff --git a/public/language/en_GB/modules.json b/public/language/en_GB/modules.json
index a2459cbc8c..a3db35f6e3 100644
--- a/public/language/en_GB/modules.json
+++ b/public/language/en_GB/modules.json
@@ -6,6 +6,7 @@
"chat.user_typing": "%1 is typing ...",
"chat.user_has_messaged_you": "%1 has messaged you.",
"chat.see_all": "See all chats",
+ "chat.mark_all_read": "Mark all chats read",
"chat.no-messages": "Please select a recipient to view chat message history",
"chat.no-users-in-room": "No users in this room",
"chat.recent-chats": "Recent Chats",
diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index 5fd69083da..d64be7bd8d 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -7,8 +7,8 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
var newMessage = false;
module.prepareDOM = function() {
- var chatsToggleEl = components.get('chat/dropdown'),
- chatsListEl = components.get('chat/list');
+ var chatsToggleEl = components.get('chat/dropdown');
+ var chatsListEl = components.get('chat/list');
chatsToggleEl.on('click', function() {
if (chatsToggleEl.parent().hasClass('open')) {
@@ -18,6 +18,14 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra
module.loadChatsDropdown(chatsListEl);
});
+ $('[component="chats/mark-all-read"]').on('click', function() {
+ socket.emit('modules.chats.markAllRead', function(err) {
+ if (err) {
+ return app.alertError(err);
+ }
+ });
+ });
+
socket.on('event:chats.receive', function(data) {
var username = data.message.fromUser.username;
var isSelf = data.self === 1;
diff --git a/src/messaging/unread.js b/src/messaging/unread.js
index 4bceaab3ce..0562551540 100644
--- a/src/messaging/unread.js
+++ b/src/messaging/unread.js
@@ -8,10 +8,16 @@ var sockets = require('../socket.io');
module.exports = function(Messaging) {
Messaging.getUnreadCount = function(uid, callback) {
+ if (!parseInt(uid, 10)) {
+ return callback(null, 0);
+ }
db.sortedSetCard('uid:' + uid + ':chat:rooms:unread', callback);
};
Messaging.pushUnreadCount = function(uid) {
+ if (!parseInt(uid, 10)) {
+ return callback(null, 0);
+ }
Messaging.getUnreadCount(uid, function(err, unreadCount) {
if (err) {
return;
@@ -24,6 +30,10 @@ module.exports = function(Messaging) {
db.sortedSetRemove('uid:' + uid + ':chat:rooms:unread', roomId, callback);
};
+ Messaging.markAllRead = function(uid, callback) {
+ db.delete('uid:' + uid + ':chat:rooms:unread', callback);
+ };
+
Messaging.markUnread = function(uids, roomId, callback) {
async.waterfall([
function (next) {
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index bcf8309a40..16d48b5deb 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -61,7 +61,7 @@ SocketModules.chats.newRoom = function(socket, data, callback) {
socket.lastChatMessageTime = now;
}
- Messaging.canMessageUser(socket.uid, data.touid, function(err, allowed) {
+ Messaging.canMessageUser(socket.uid, data.touid, function(err) {
if (err) {
return callback(err);
}
@@ -244,6 +244,18 @@ SocketModules.chats.markRead = function(socket, roomId, callback) {
});
};
+SocketModules.chats.markAllRead = function(socket, data, callback) {
+ async.waterfall([
+ function (next) {
+ Messaging.markAllRead(socket.uid, next);
+ },
+ function (next) {
+ Messaging.pushUnreadCount(socket.uid);
+ next();
+ }
+ ], callback);
+};
+
SocketModules.chats.renameRoom = function(socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-name]]'));