mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-04-14 00:18:03 +02:00
closes #5519
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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]]'));
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user