chat history access

v1.18.x
barisusakli 9 years ago
parent 598c47b77f
commit 202edfa47e

@ -265,7 +265,7 @@ define('forum/chats', [
}; };
Chats.switchChat = function(roomid) { Chats.switchChat = function(roomid) {
ajaxify.go('chats/' + roomid); ajaxify.go('user/' + ajaxify.data.userslug + '/chats/' + roomid);
}; };
Chats.loadChatSince = function(roomId, chatContentEl, since) { Chats.loadChatSince = function(roomId, chatContentEl, since) {

@ -31,7 +31,7 @@ define('chat', [
if (!ajaxify.currentPage.match(/^chats\//)) { if (!ajaxify.currentPage.match(/^chats\//)) {
app.openChat(roomId); app.openChat(roomId);
} else { } else {
ajaxify.go('chats/' + roomId); ajaxify.go('user/' + app.user.userslug + '/chats/' + roomId);
} }
}); });
@ -214,7 +214,7 @@ define('chat', [
components.get('chat/input').val(text); components.get('chat/input').val(text);
}); });
ajaxify.go('chats/' + chatModal.attr('roomId')); ajaxify.go('user/' + app.user.userslug + '/chats/' + chatModal.attr('roomId'));
module.close(chatModal); module.close(chatModal);
} }

@ -4,6 +4,7 @@ var async = require('async');
var messaging = require('../../messaging'); var messaging = require('../../messaging');
var meta = require('../../meta'); var meta = require('../../meta');
var user = require('../../user');
var helpers = require('../helpers'); var helpers = require('../helpers');
@ -13,35 +14,41 @@ 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;
messaging.getRecentChats(req.uid, 0, 19, function(err, recentChats) { var recentChats;
if (err) { async.waterfall([
return callback(err); function(next) {
user.getUidByUserslug(req.params.userslug, next);
},
function(_uid, next) {
uid = _uid;
if (!uid) {
return callback();
} }
messaging.getRecentChats(uid, 0, 19, next);
},
function(_recentChats, next) {
recentChats = _recentChats;
if (!req.params.roomid) { if (!req.params.roomid) {
return res.render('chats', { return res.render('chats', {
rooms: recentChats.rooms, rooms: recentChats.rooms,
userslug: req.params.userslug,
nextStart: recentChats.nextStart, nextStart: recentChats.nextStart,
allowed: true, allowed: true,
title: '[[pages:chats]]', title: '[[pages:chats]]',
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[pages:chats]]'}]) breadcrumbs: helpers.buildBreadcrumbs([{text: '[[pages:chats]]'}])
}); });
} }
async.waterfall([
function (next) {
messaging.isUserInRoom(req.uid, req.params.roomid, next); messaging.isUserInRoom(req.uid, req.params.roomid, next);
}, },
function (inRoom, next) { function(inRoom, next) {
if (!inRoom) { if (!inRoom && parseInt(req.uid, 10) === parseInt(uid, 10)) {
return callback(); return callback();
} }
async.parallel({ async.parallel({
users: async.apply(messaging.getUsersInRoom, req.params.roomid, 0, -1), users: async.apply(messaging.getUsersInRoom, req.params.roomid, 0, -1),
messages: async.apply(messaging.getMessages, { messages: async.apply(messaging.getMessages, {
uid: req.uid, uid: uid,
roomId: req.params.roomid, roomId: req.params.roomid,
since: 'recent', since: 'recent',
isNew: false isNew: false
@ -62,6 +69,7 @@ chatsController.get = function(req, res, callback) {
}); });
room.rooms = recentChats.rooms; room.rooms = recentChats.rooms;
room.userslug = req.params.userslug;
room.nextStart = recentChats.nextStart; room.nextStart = recentChats.nextStart;
room.title = room.roomName; room.title = room.roomName;
room.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:chats]]', url: '/chats'}, {text: room.roomName}]); room.breadcrumbs = helpers.buildBreadcrumbs([{text: '[[pages:chats]]', url: '/chats'}, {text: room.roomName}]);
@ -71,7 +79,8 @@ chatsController.get = function(req, res, callback) {
res.render('chats', room); res.render('chats', room);
}); });
});
}; };
module.exports = chatsController; module.exports = chatsController;

@ -31,5 +31,5 @@ module.exports = function (app, middleware, controllers) {
app.delete('/api/user/:userslug/session/:uuid', [middleware.requireUser], controllers.accounts.session.revoke); app.delete('/api/user/:userslug/session/:uuid', [middleware.requireUser], controllers.accounts.session.revoke);
setupPageRoute(app, '/notifications', middleware, [middleware.authenticate], controllers.accounts.notifications.get); setupPageRoute(app, '/notifications', middleware, [middleware.authenticate], controllers.accounts.notifications.get);
setupPageRoute(app, '/chats/:roomid?', middleware, [middleware.authenticate], controllers.accounts.chats.get); setupPageRoute(app, '/user/:userslug/chats/:roomid?', middleware, accountMiddlewares, controllers.accounts.chats.get);
}; };

Loading…
Cancel
Save