Skip to content

Node.js based forum software built for the modern web

closes #5519

barisusaklib8c606cbbd7c
diff --git a/public/language/en-GB/modules.json b/public/language/en-GB/modules.json
index 5f258128f8..8f8e4ad1ed 100644
--- a/public/language/en-GB/modules.json
+++ b/public/language/en-GB/modules.json
@@ -20,6 +20,7 @@
"chat.three_months": "3 Months",
"chat.delete_message_confirm": "Are you sure you wish to delete this message?",
"chat.add-users-to-room": "Add users to room",
+ "chat.confirm-chat-with-dnd-user": "This user has set their status to DnD(Do not disturb). Do you still want to chat with them?",
"composer.compose": "Compose",
"composer.show_preview": "Show Preview",
diff --git a/public/src/app.js b/public/src/app.js
index 3e53305aac..1c20346a7a 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -340,6 +340,22 @@ app.cacheBuster = null;
};
app.newChat = function (touid, callback) {
+ function createChat() {
+ socket.emit('modules.chats.newRoom', { touid: touid }, function (err, roomId) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+
+ if (!ajaxify.data.template.chats) {
+ app.openChat(roomId);
+ } else {
+ ajaxify.go('chats/' + roomId);
+ }
+
+ callback(false, roomId);
+ });
+ }
+
callback = callback || function () {};
if (!app.user.uid) {
return app.alertError('[[error:not-logged-in]]');
@@ -348,19 +364,18 @@ app.cacheBuster = null;
if (parseInt(touid, 10) === parseInt(app.user.uid, 10)) {
return app.alertError('[[error:cant-chat-with-yourself]]');
}
-
- socket.emit('modules.chats.newRoom', { touid: touid }, function (err, roomId) {
+ socket.emit('modules.chats.isDnD', touid, function (err, isDnD) {
if (err) {
return app.alertError(err.message);
}
-
- if (!ajaxify.data.template.chats) {
- app.openChat(roomId);
- } else {
- ajaxify.go('chats/' + roomId);
+ if (!isDnD) {
+ return createChat();
}
-
- callback(false, roomId);
+ bootbox.confirm('[[modules:chat.confirm-chat-with-dnd-user]]', function (ok) {
+ if (ok) {
+ createChat();
+ }
+ });
});
};
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 4480a9d0f7..184609129a 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -3,6 +3,7 @@
var async = require('async');
var validator = require('validator');
+var db = require('../database');
var meta = require('../meta');
var notifications = require('../notifications');
var plugins = require('../plugins');
@@ -36,6 +37,17 @@ SocketModules.chats.getRaw = function (socket, data, callback) {
], callback);
};
+SocketModules.chats.isDnD = function (socket, uid, callback) {
+ async.waterfall([
+ function (next) {
+ db.getObjectField('user:' + uid, 'status', next);
+ },
+ function (status, next) {
+ next(null, status === 'dnd');
+ },
+ ], callback);
+};
+
SocketModules.chats.newRoom = function (socket, data, callback) {
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
diff --git a/test/messaging.js b/test/messaging.js
index 4fbaad717f..436fd78a87 100644
--- a/test/messaging.js
+++ b/test/messaging.js
@@ -187,6 +187,17 @@ describe('Messaging Library', function () {
done();
});
});
+
+ it('should return true if user is dnd', function (done) {
+ db.setObjectField('user:' + herpUid, 'status', 'dnd', function (err) {
+ assert.ifError(err);
+ socketModules.chats.isDnD({ uid: fooUid }, herpUid, function (err, isDnD) {
+ assert.ifError(err);
+ assert(isDnD);
+ done();
+ });
+ });
+ });
});
describe('edit/delete', function () {
@@ -303,7 +314,6 @@ describe('Messaging Library', function () {
});
});
-
after(function (done) {
db.emptydb(done);
});