v1.18.x
barisusakli 8 years ago
parent 1ec5539adc
commit 9f2533b5ba

@ -7,7 +7,6 @@ var meta = require('../../meta');
var user = require('../../user');
var helpers = require('../helpers');
var chatsController = {};
chatsController.get = function(req, res, callback) {
@ -93,6 +92,23 @@ chatsController.get = function(req, res, callback) {
});
};
chatsController.redirectToChat = function(req, res, next) {
var roomid = parseInt(req.params.roomid, 10);
if (!req.uid) {
return next();
}
user.getUserField(req.uid, 'userslug', function(err, userslug) {
if (err || !userslug) {
return next(err);
}
if (!roomid) {
return helpers.redirect(res, '/user/' + userslug + '/chats');
}
helpers.redirect(res, '/user/' + userslug + '/chats/' + roomid);
});
};
module.exports = chatsController;

@ -32,4 +32,5 @@ module.exports = function (app, middleware, controllers) {
setupPageRoute(app, '/notifications', middleware, [middleware.authenticate], controllers.accounts.notifications.get);
setupPageRoute(app, '/user/:userslug/chats/:roomid?', middleware, accountMiddlewares, controllers.accounts.chats.get);
setupPageRoute(app, '/chats/:roomid?', middleware, [], controllers.accounts.chats.redirectToChat);
};

Loading…
Cancel
Save