lint fixes

v1.18.x
Baris Usakli 8 years ago
parent bc6b1a8f56
commit 27a6b8a713

@ -315,7 +315,7 @@ define('forum/chats', [
fetch(config.relative_path + '/api/' + url, { credentials: 'include' }) fetch(config.relative_path + '/api/' + url, { credentials: 'include' })
.then(function (response) { .then(function (response) {
if (response.ok) { if (response.ok) {
response.json().then(function(payload) { response.json().then(function (payload) {
app.parseAndTranslate('partials/chats/message-window', payload, function (html) { app.parseAndTranslate('partials/chats/message-window', payload, function (html) {
components.get('chat/main-wrapper').html(html); components.get('chat/main-wrapper').html(html);
Chats.resizeMainWindow(); Chats.resizeMainWindow();
@ -331,7 +331,7 @@ define('forum/chats', [
}); });
}); });
} else { } else {
console.warn('[search] Received ' + response.status +', query: ' + query); console.warn('[search] Received ' + response.status);
} }
}) })
.catch(function (error) { .catch(function (error) {

@ -7,26 +7,22 @@ var meta = require('../../meta');
var user = require('../../user'); var user = require('../../user');
var helpers = require('../helpers'); var helpers = require('../helpers');
var chatsController = {}; var chatsController = module.exports;
chatsController.get = function (req, res, callback) { chatsController.get = function (req, res, callback) {
if (parseInt(meta.config.disableChat, 10) === 1) { if (parseInt(meta.config.disableChat, 10) === 1) {
return callback(); return callback();
} }
var uid; var uid;
var username;
var recentChats; var recentChats;
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ user.getUidByUserslug(req.params.userslug, next);
uid: async.apply(user.getUidByUserslug, req.params.userslug),
username: async.apply(user.getUsernameByUserslug, req.params.userslug),
}, next);
}, },
function (results, next) { function (_uid, next) {
uid = results.uid; uid = _uid;
username = results.username;
if (!uid) { if (!uid) {
return callback(); return callback();
} }
@ -65,32 +61,30 @@ chatsController.get = function (req, res, callback) {
}), }),
}, next); }, next);
}, },
], function (err, data) { function (data) {
if (err) { var room = data.room;
return callback(err); room.messages = data.messages;
}
var room = data.room;
room.messages = data.messages;
room.isOwner = parseInt(room.owner, 10) === parseInt(req.uid, 10); room.isOwner = parseInt(room.owner, 10) === parseInt(req.uid, 10);
room.users = data.users.filter(function (user) { room.users = data.users.filter(function (user) {
return user && parseInt(user.uid, 10) && parseInt(user.uid, 10) !== req.uid; return user && parseInt(user.uid, 10) && parseInt(user.uid, 10) !== req.uid;
}); });
room.canReply = data.canReply; room.canReply = data.canReply;
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2; room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2;
room.rooms = recentChats.rooms; room.rooms = recentChats.rooms;
room.uid = uid; room.uid = uid;
room.userslug = req.params.userslug; room.userslug = req.params.userslug;
room.nextStart = recentChats.nextStart; room.nextStart = recentChats.nextStart;
room.usernames = messaging.generateUsernames(room.users, req.uid); room.usernames = messaging.generateUsernames(room.users, req.uid);
room.title = room.roomName || room.usernames || '[[pages:chats]]'; room.title = room.roomName || room.usernames || '[[pages:chats]]';
room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0; room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000; room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2; room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
res.render('chats', room); res.render('chats', room);
}); },
], callback);
}; };
chatsController.redirectToChat = function (req, res, next) { chatsController.redirectToChat = function (req, res, next) {
@ -98,14 +92,15 @@ chatsController.redirectToChat = function (req, res, next) {
if (!req.uid) { if (!req.uid) {
return next(); return next();
} }
user.getUserField(req.uid, 'userslug', function (err, userslug) { async.waterfall([
if (err || !userslug) { function (next) {
return next(err); user.getUserField(req.uid, 'userslug', next);
} },
function (userslug, next) {
helpers.redirect(res, '/user/' + userslug + '/chats' + (roomid ? '/' + roomid : '')); if (!userslug) {
}); return next();
}
helpers.redirect(res, '/user/' + userslug + '/chats' + (roomid ? '/' + roomid : ''));
},
], next);
}; };
module.exports = chatsController;

Loading…
Cancel
Save