From 9f2533b5ba00c6c0be8995406203197f16585329 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 26 Sep 2016 22:01:47 +0300 Subject: [PATCH] closes #5054 --- src/controllers/accounts/chats.js | 18 +++++++++++++++++- src/routes/accounts.js | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.js index 35eab94a83..7ff867134c 100644 --- a/src/controllers/accounts/chats.js +++ b/src/controllers/accounts/chats.js @@ -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; \ No newline at end of file diff --git a/src/routes/accounts.js b/src/routes/accounts.js index d74316f816..9d17b8f86a 100644 --- a/src/routes/accounts.js +++ b/src/routes/accounts.js @@ -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); };