mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-09 07:25:46 +01:00
WIP
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
"chat.see_all": "See all Chats",
|
||||
"chat.no-messages": "Please select a recipient to view chat message history",
|
||||
"chat.recent-chats": "Recent Chats",
|
||||
"chat.contacts": "Contacts",
|
||||
"chat.message-history": "Message History",
|
||||
|
||||
"composer.user_said_in": "%1 said in %2:\n",
|
||||
"composer.user_said": "%1 said:\n",
|
||||
|
||||
@@ -486,10 +486,12 @@ accountsController.getChats = function(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
console.log(res.locals.messages);
|
||||
console.log(res.locals);
|
||||
|
||||
res.render('chats', {
|
||||
meta: res.locals.chatData,
|
||||
chats: chats,
|
||||
contacts: res.locals.contacts,
|
||||
messages: res.locals.messages || undefined
|
||||
});
|
||||
});
|
||||
|
||||
@@ -190,10 +190,34 @@ 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) {
|
||||
/* Chat related middlewares */
|
||||
|
||||
middleware.chat = {};
|
||||
middleware.chat.getMetadata = function(req, res, next) {
|
||||
async.waterfall([
|
||||
async.apply(user.getUidByUserslug, req.params.userslug),
|
||||
function(toUid, next) {
|
||||
user.getUserFields(toUid, ['uid', 'username'], next);
|
||||
}
|
||||
], function(err, chatData) {
|
||||
if (!err) {
|
||||
res.locals.chatData = chatData;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
middleware.chat.getContactList = function(req, res, next) {
|
||||
user.getFollowing(req.user.uid, function(err, contacts) {
|
||||
res.locals.contacts = contacts;
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
middleware.chat.getMessages = function(req, res, next) {
|
||||
if (res.locals.chatData) {
|
||||
messaging.getMessages(req.user.uid, res.locals.chatData.uid, false, function(err, messages) {
|
||||
res.locals.messages = messages;
|
||||
next();
|
||||
});
|
||||
@@ -201,7 +225,6 @@ middleware.getChatMessages = function(req, res, next) {
|
||||
res.locals.messages = [];
|
||||
next();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
middleware.buildHeader = function(req, res, next) {
|
||||
|
||||
@@ -121,8 +121,8 @@ function accountRoutes(app, middleware, controllers) {
|
||||
|
||||
app.get('/chats', middleware.buildHeader, 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);
|
||||
app.get('/chats/:userslug', middleware.buildHeader, middleware.authenticate, middleware.chat.getMetadata, middleware.chat.getContactList, middleware.chat.getMessages, controllers.accounts.getChats);
|
||||
app.get('/api/chats/:userslug', middleware.authenticate, middleware.chat.getMetadata, middleware.chat.getContactList, middleware.chat.getMessages, controllers.accounts.getChats);
|
||||
}
|
||||
|
||||
function userRoutes(app, middleware, controllers) {
|
||||
|
||||
Reference in New Issue
Block a user