mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 06:25:50 +01:00
closes #3996
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var validator = require('validator');
|
||||
|
||||
var db = require('../database');
|
||||
var user = require('../user');
|
||||
|
||||
module.exports = function(Messaging) {
|
||||
|
||||
Messaging.getRoomData = function(roomId, callback) {
|
||||
db.getObject('chat:room:' + roomId, function(err, data) {
|
||||
if (err || !data) {
|
||||
return callback(err || new Error('[[error:no-chat-room]]'));
|
||||
}
|
||||
data.roomName = data.roomName || '[[modules:chat.roomname, ' + roomId + ']]';
|
||||
if (data.roomName) {
|
||||
data.roomName = validator.escape(data.roomName);
|
||||
}
|
||||
callback(null, data);
|
||||
});
|
||||
};
|
||||
|
||||
Messaging.newRoom = function(uid, toUids, callback) {
|
||||
var roomId;
|
||||
var now = Date.now();
|
||||
@@ -105,4 +119,22 @@ module.exports = function(Messaging) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
Messaging.renameRoom = function(uid, roomId, newName, callback) {
|
||||
if (!newName) {
|
||||
return callback(new Error('[[error:invalid-name]]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Messaging.isRoomOwner(uid, roomId, next);
|
||||
},
|
||||
function (isOwner, next) {
|
||||
if (!isOwner) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
db.setObjectField('chat:room:' + roomId, 'roomName', newName, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user