issue #1788 - start

v1.18.x
Julian Lam 11 years ago
parent 5097526ae0
commit 0dad7adb8d

@ -32,7 +32,6 @@
"header.tags": "Tags", "header.tags": "Tags",
"header.popular": "Popular", "header.popular": "Popular",
"header.users": "Users", "header.users": "Users",
"header.chats": "Chats",
"header.notifications": "Notifications", "header.notifications": "Notifications",
"header.search": "Search", "header.search": "Search",
"header.profile": "Profile", "header.profile": "Profile",

@ -6,6 +6,8 @@
"chat.user_typing": "%1 is typing ...", "chat.user_typing": "%1 is typing ...",
"chat.user_has_messaged_you": "%1 has messaged you.", "chat.user_has_messaged_you": "%1 has messaged you.",
"chat.see_all": "See all Chats", "chat.see_all": "See all Chats",
"chat.no-messages": "Please select a recipient to view chat message history",
"chat.recent-chats": "Recent Chats",
"composer.user_said_in": "%1 said in %2:\n", "composer.user_said_in": "%1 said in %2:\n",
"composer.user_said": "%1 said:\n", "composer.user_said": "%1 said:\n",

@ -486,8 +486,11 @@ accountsController.getChats = function(req, res, next) {
return next(err); return next(err);
} }
console.log(res.locals.messages);
res.render('chats', { res.render('chats', {
chats: chats chats: chats,
messages: res.locals.messages || undefined
}); });
}); });
}; };

@ -77,9 +77,10 @@ var db = require('./database'),
} }
async.map(messages, function(message, next) { async.map(messages, function(message, next) {
var self = parseInt(message.fromuid, 10) === parseInt(fromuid) var self = parseInt(message.fromuid, 10) === parseInt(fromuid, 10);
message.fromUser = self ? userData[0] : userData[1]; message.fromUser = self ? userData[0] : userData[1];
message.toUser = self ? userData[1] : userData[0]; message.toUser = self ? userData[1] : userData[0];
message.timestampISO = new Date(parseInt(message.timestamp, 10)).toISOString();
Messaging.parse(message.content, message.fromuid, fromuid, userData[1], userData[0], isNew, function(result) { Messaging.parse(message.content, message.fromuid, fromuid, userData[1], userData[0], isNew, function(result) {
message.content = result; message.content = result;

@ -15,6 +15,7 @@ var app,
db = require('./../database'), db = require('./../database'),
categories = require('./../categories'), categories = require('./../categories'),
topics = require('./../topics'), topics = require('./../topics'),
messaging = require('../messaging'),
controllers = { controllers = {
api: require('./../controllers/api') api: require('./../controllers/api')
@ -189,6 +190,20 @@ middleware.checkAccountPermissions = function(req, res, next) {
}); });
}; };
middleware.getChatMessages = function(req, res, next) {
user.getUidByUserslug(req.params.userslug, function(err, toUid) {
if (!err && toUid) {
messaging.getMessages(req.user.uid, toUid, false, function(err, messages) {
res.locals.messages = messages;
next();
});
} else {
res.locals.messages = [];
next();
}
});
};
middleware.buildHeader = function(req, res, next) { middleware.buildHeader = function(req, res, next) {
res.locals.renderHeader = true; res.locals.renderHeader = true;
async.parallel({ async.parallel({

@ -121,6 +121,8 @@ function accountRoutes(app, middleware, controllers) {
app.get('/chats', middleware.buildHeader, middleware.authenticate, controllers.accounts.getChats); app.get('/chats', middleware.buildHeader, middleware.authenticate, controllers.accounts.getChats);
app.get('/api/chats', middleware.authenticate, controllers.accounts.getChats); app.get('/api/chats', middleware.authenticate, controllers.accounts.getChats);
app.get('/chats/:userslug', middleware.buildHeader, middleware.authenticate, middleware.getChatMessages, controllers.accounts.getChats);
app.get('/api/chats/:userslug', middleware.authenticate, middleware.getChatMessages, controllers.accounts.getChats);
} }
function userRoutes(app, middleware, controllers) { function userRoutes(app, middleware, controllers) {

Loading…
Cancel
Save