remove dupe code

This commit is contained in:
Barış Soner Uşaklı
2018-06-01 13:12:28 -04:00
parent 4e7fdf3e12
commit 7df57ba7a7
3 changed files with 59 additions and 82 deletions

View File

@@ -27,7 +27,6 @@ chatsController.get = function (req, res, callback) {
if (!uid) {
return callback();
}
privileges.global.can('chat', req.uid, next);
},
function (canChat, next) {
@@ -51,48 +50,17 @@ chatsController.get = function (req, res, callback) {
title: '[[pages:chats]]',
});
}
messaging.isUserInRoom(req.uid, req.params.roomid, next);
messaging.loadRoom(req.uid, { uid: uid, roomId: req.params.roomid }, next);
},
function (inRoom, next) {
if (!inRoom) {
function (room) {
if (!room) {
return callback();
}
async.parallel({
users: async.apply(messaging.getUsersInRoom, req.params.roomid, 0, -1),
canReply: async.apply(messaging.canReply, req.params.roomid, req.uid),
room: async.apply(messaging.getRoomData, req.params.roomid),
messages: async.apply(messaging.getMessages, {
callerUid: req.uid,
uid: uid,
roomId: req.params.roomid,
isNew: false,
}),
isAdminOrGlobalMod: function (next) {
user.isAdminOrGlobalMod(req.uid, next);
},
}, next);
},
function (data) {
var room = data.room;
room.messages = data.messages;
room.isOwner = parseInt(room.owner, 10) === parseInt(req.uid, 10);
room.users = data.users.filter(function (user) {
return user && parseInt(user.uid, 10) && parseInt(user.uid, 10) !== req.uid;
});
room.canReply = data.canReply;
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : room.users.length > 2;
room.rooms = recentChats.rooms;
room.nextStart = recentChats.nextStart;
room.title = room.roomName || room.usernames || '[[pages:chats]]';
room.uid = uid;
room.userslug = req.params.userslug;
room.nextStart = recentChats.nextStart;
room.usernames = messaging.generateUsernames(room.users, req.uid);
room.title = room.roomName || room.usernames || '[[pages:chats]]';
room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
room.isAdminOrGlobalMod = data.isAdminOrGlobalMod;
res.render('chats', room);
},
], callback);